mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Estended ShortUrlRedirectionBuilderTest covering short URLS withput query forwarding
This commit is contained in:
parent
8212d3c540
commit
74a08b86ce
1 changed files with 62 additions and 14 deletions
|
@ -6,27 +6,34 @@ namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper;
|
|||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
||||
use Shlinkio\Shlink\Core\Options\TrackingOptions;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlRedirectionBuilder;
|
||||
|
||||
class ShortUrlRedirectionBuilderTest extends TestCase
|
||||
{
|
||||
private ShortUrlRedirectionBuilder $redirectionBuilder;
|
||||
private TrackingOptions $trackingOptions;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->trackingOptions = new TrackingOptions(['disable_track_param' => 'foobar']);
|
||||
$this->redirectionBuilder = new ShortUrlRedirectionBuilder($this->trackingOptions);
|
||||
$trackingOptions = new TrackingOptions(['disable_track_param' => 'foobar']);
|
||||
$this->redirectionBuilder = new ShortUrlRedirectionBuilder($trackingOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function buildShortUrlRedirectBuildsExpectedUrl(string $expectedUrl, array $query, ?string $extraPath): void
|
||||
{
|
||||
$shortUrl = ShortUrl::withLongUrl('https://domain.com/foo/bar?some=thing');
|
||||
public function buildShortUrlRedirectBuildsExpectedUrl(
|
||||
string $expectedUrl,
|
||||
array $query,
|
||||
?string $extraPath,
|
||||
?bool $forwardQuery,
|
||||
): void {
|
||||
$shortUrl = ShortUrl::fromMeta(ShortUrlMeta::fromRawData([
|
||||
'longUrl' => 'https://domain.com/foo/bar?some=thing',
|
||||
'forwardQuery' => $forwardQuery,
|
||||
]));
|
||||
$result = $this->redirectionBuilder->buildShortUrlRedirect($shortUrl, $query, $extraPath);
|
||||
|
||||
self::assertEquals($expectedUrl, $result);
|
||||
|
@ -34,18 +41,59 @@ class ShortUrlRedirectionBuilderTest extends TestCase
|
|||
|
||||
public function provideData(): iterable
|
||||
{
|
||||
yield ['https://domain.com/foo/bar?some=thing', [], null];
|
||||
yield ['https://domain.com/foo/bar?some=thing&else', ['else' => null], null];
|
||||
yield ['https://domain.com/foo/bar?some=thing&foo=bar', ['foo' => 'bar'], null];
|
||||
yield ['https://domain.com/foo/bar?some=thing&123=foo', ['123' => 'foo'], null];
|
||||
yield ['https://domain.com/foo/bar?some=thing&456=foo', [456 => 'foo'], null];
|
||||
yield ['https://domain.com/foo/bar?some=overwritten&foo=bar', ['foo' => 'bar', 'some' => 'overwritten'], null];
|
||||
yield ['https://domain.com/foo/bar?some=overwritten', ['foobar' => 'notrack', 'some' => 'overwritten'], null];
|
||||
yield ['https://domain.com/foo/bar/something/else-baz?some=thing', [], '/something/else-baz'];
|
||||
yield ['https://domain.com/foo/bar?some=thing', [], null, true];
|
||||
yield ['https://domain.com/foo/bar?some=thing', [], null, null];
|
||||
yield ['https://domain.com/foo/bar?some=thing', [], null, false];
|
||||
yield ['https://domain.com/foo/bar?some=thing&else', ['else' => null], null, true];
|
||||
yield ['https://domain.com/foo/bar?some=thing&foo=bar', ['foo' => 'bar'], null, true];
|
||||
yield ['https://domain.com/foo/bar?some=thing&foo=bar', ['foo' => 'bar'], null, null];
|
||||
yield ['https://domain.com/foo/bar?some=thing', ['foo' => 'bar'], null, false];
|
||||
yield ['https://domain.com/foo/bar?some=thing&123=foo', ['123' => 'foo'], null, true];
|
||||
yield ['https://domain.com/foo/bar?some=thing&456=foo', [456 => 'foo'], null, true];
|
||||
yield ['https://domain.com/foo/bar?some=thing&456=foo', [456 => 'foo'], null, null];
|
||||
yield ['https://domain.com/foo/bar?some=thing', [456 => 'foo'], null, false];
|
||||
yield [
|
||||
'https://domain.com/foo/bar?some=overwritten&foo=bar',
|
||||
['foo' => 'bar', 'some' => 'overwritten'],
|
||||
null,
|
||||
true,
|
||||
];
|
||||
yield [
|
||||
'https://domain.com/foo/bar?some=overwritten',
|
||||
['foobar' => 'notrack', 'some' => 'overwritten'],
|
||||
null,
|
||||
true,
|
||||
];
|
||||
yield [
|
||||
'https://domain.com/foo/bar?some=overwritten',
|
||||
['foobar' => 'notrack', 'some' => 'overwritten'],
|
||||
null,
|
||||
null,
|
||||
];
|
||||
yield [
|
||||
'https://domain.com/foo/bar?some=thing',
|
||||
['foobar' => 'notrack', 'some' => 'overwritten'],
|
||||
null,
|
||||
false,
|
||||
];
|
||||
yield ['https://domain.com/foo/bar/something/else-baz?some=thing', [], '/something/else-baz', true];
|
||||
yield [
|
||||
'https://domain.com/foo/bar/something/else-baz?some=thing&hello=world',
|
||||
['hello' => 'world'],
|
||||
'/something/else-baz',
|
||||
true,
|
||||
];
|
||||
yield [
|
||||
'https://domain.com/foo/bar/something/else-baz?some=thing&hello=world',
|
||||
['hello' => 'world'],
|
||||
'/something/else-baz',
|
||||
null,
|
||||
];
|
||||
yield [
|
||||
'https://domain.com/foo/bar/something/else-baz?some=thing',
|
||||
['hello' => 'world'],
|
||||
'/something/else-baz',
|
||||
false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue