mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Allow device long URLs to be removed from short URLs by providing null value
This commit is contained in:
@@ -8,6 +8,7 @@ use Cake\Chronos\Chronos;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Config\EnvVars;
|
||||
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
||||
use Shlinkio\Shlink\Core\Model\DeviceType;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
|
||||
use stdClass;
|
||||
@@ -69,6 +70,40 @@ class ShortUrlCreationTest extends TestCase
|
||||
yield [[
|
||||
ShortUrlInputFilter::LONG_URL => [],
|
||||
]];
|
||||
yield [[
|
||||
ShortUrlInputFilter::LONG_URL => null,
|
||||
]];
|
||||
yield [[
|
||||
ShortUrlInputFilter::LONG_URL => 'foo',
|
||||
ShortUrlInputFilter::DEVICE_LONG_URLS => [
|
||||
'invalid' => 'https://shlink.io',
|
||||
],
|
||||
]];
|
||||
yield [[
|
||||
ShortUrlInputFilter::LONG_URL => 'foo',
|
||||
ShortUrlInputFilter::DEVICE_LONG_URLS => [
|
||||
DeviceType::DESKTOP->value => '',
|
||||
],
|
||||
]];
|
||||
yield [[
|
||||
ShortUrlInputFilter::LONG_URL => 'foo',
|
||||
ShortUrlInputFilter::DEVICE_LONG_URLS => [
|
||||
DeviceType::DESKTOP->value => null,
|
||||
],
|
||||
]];
|
||||
yield [[
|
||||
ShortUrlInputFilter::LONG_URL => 'foo',
|
||||
ShortUrlInputFilter::DEVICE_LONG_URLS => [
|
||||
DeviceType::IOS->value => ' ',
|
||||
],
|
||||
]];
|
||||
yield [[
|
||||
ShortUrlInputFilter::LONG_URL => 'foo',
|
||||
ShortUrlInputFilter::DEVICE_LONG_URLS => [
|
||||
DeviceType::IOS->value => 'bar',
|
||||
DeviceType::ANDROID->value => [],
|
||||
],
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
54
module/Core/test/ShortUrl/Model/ShortUrlEditionTest.php
Normal file
54
module/Core/test/ShortUrl/Model/ShortUrlEditionTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\ShortUrl\Model;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Model\DeviceType;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\DeviceLongUrlPair;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlEdition;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
|
||||
|
||||
class ShortUrlEditionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideDeviceLongUrls
|
||||
*/
|
||||
public function expectedDeviceLongUrlsAreResolved(
|
||||
?array $deviceLongUrls,
|
||||
array $expectedDeviceLongUrls,
|
||||
array $expectedDevicesToRemove,
|
||||
): void {
|
||||
$edition = ShortUrlEdition::fromRawData([ShortUrlInputFilter::DEVICE_LONG_URLS => $deviceLongUrls]);
|
||||
|
||||
self::assertEquals($expectedDeviceLongUrls, $edition->deviceLongUrls);
|
||||
self::assertEquals($expectedDevicesToRemove, $edition->devicesToRemove);
|
||||
}
|
||||
|
||||
public function provideDeviceLongUrls(): iterable
|
||||
{
|
||||
yield 'null' => [null, [], []];
|
||||
yield 'empty' => [[], [], []];
|
||||
yield 'only new urls' => [[
|
||||
DeviceType::DESKTOP->value => 'foo',
|
||||
DeviceType::IOS->value => 'bar',
|
||||
], [
|
||||
DeviceType::DESKTOP->value => DeviceLongUrlPair::fromRawTypeAndLongUrl(DeviceType::DESKTOP->value, 'foo'),
|
||||
DeviceType::IOS->value => DeviceLongUrlPair::fromRawTypeAndLongUrl(DeviceType::IOS->value, 'bar'),
|
||||
], []];
|
||||
yield 'only urls to remove' => [[
|
||||
DeviceType::ANDROID->value => null,
|
||||
DeviceType::IOS->value => null,
|
||||
], [], [DeviceType::ANDROID, DeviceType::IOS]];
|
||||
yield 'both' => [[
|
||||
DeviceType::DESKTOP->value => 'bar',
|
||||
DeviceType::IOS->value => 'foo',
|
||||
DeviceType::ANDROID->value => null,
|
||||
], [
|
||||
DeviceType::DESKTOP->value => DeviceLongUrlPair::fromRawTypeAndLongUrl(DeviceType::DESKTOP->value, 'bar'),
|
||||
DeviceType::IOS->value => DeviceLongUrlPair::fromRawTypeAndLongUrl(DeviceType::IOS->value, 'foo'),
|
||||
], [DeviceType::ANDROID]];
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace ShlinkioTest\Shlink\Core\ShortUrl\Model\Validation;
|
||||
|
||||
use Laminas\Validator\NotEmpty;
|
||||
use Laminas\Validator\ValidatorChain;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Model\DeviceType;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\DeviceLongUrlsValidator;
|
||||
@@ -17,10 +16,7 @@ class DeviceLongUrlsValidatorTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$longUrlValidators = new ValidatorChain();
|
||||
$longUrlValidators->attach(new NotEmpty());
|
||||
|
||||
$this->validator = new DeviceLongUrlsValidator($longUrlValidators);
|
||||
$this->validator = new DeviceLongUrlsValidator(new NotEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user