mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Add unit test to cover device URLs edition, and fix bug thanks to it
This commit is contained in:
parent
5aa8de11f4
commit
b0b9902f40
3 changed files with 48 additions and 3 deletions
|
@ -174,12 +174,13 @@ class ShortUrl extends AbstractEntity
|
|||
$this->deviceLongUrls->remove($deviceType->value);
|
||||
}
|
||||
foreach ($shortUrlEdit->deviceLongUrls as $deviceLongUrlPair) {
|
||||
$deviceLongUrl = $this->deviceLongUrls->get($deviceLongUrlPair->deviceType->value);
|
||||
$key = $deviceLongUrlPair->deviceType->value;
|
||||
$deviceLongUrl = $this->deviceLongUrls->get($key);
|
||||
|
||||
if ($deviceLongUrl !== null) {
|
||||
$deviceLongUrl->updateLongUrl($deviceLongUrlPair->longUrl);
|
||||
} else {
|
||||
$this->deviceLongUrls->add(DeviceLongUrl::fromShortUrlAndPair($this, $deviceLongUrlPair));
|
||||
$this->deviceLongUrls->set($key, DeviceLongUrl::fromShortUrlAndPair($this, $deviceLongUrlPair));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@ namespace ShlinkioTest\Shlink\Core\ShortUrl\Entity;
|
|||
use Cake\Chronos\Chronos;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Exception\ShortCodeCannotBeRegeneratedException;
|
||||
use Shlinkio\Shlink\Core\Model\DeviceType;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlEdition;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
|
||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
||||
use Shlinkio\Shlink\Importer\Sources\ImportSource;
|
||||
|
@ -89,4 +91,46 @@ class ShortUrlTest extends TestCase
|
|||
yield [null, DEFAULT_SHORT_CODES_LENGTH];
|
||||
yield from map(range(4, 10), fn (int $value) => [$value, $value]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function deviceLongUrlsAreUpdated(): void
|
||||
{
|
||||
$shortUrl = ShortUrl::withLongUrl('foo');
|
||||
|
||||
$shortUrl->update(ShortUrlEdition::fromRawData([
|
||||
ShortUrlInputFilter::DEVICE_LONG_URLS => [
|
||||
DeviceType::ANDROID->value => 'android',
|
||||
DeviceType::IOS->value => 'ios',
|
||||
],
|
||||
]));
|
||||
self::assertEquals([
|
||||
DeviceType::ANDROID->value => 'android',
|
||||
DeviceType::IOS->value => 'ios',
|
||||
DeviceType::DESKTOP->value => null,
|
||||
], $shortUrl->deviceLongUrls());
|
||||
|
||||
$shortUrl->update(ShortUrlEdition::fromRawData([
|
||||
ShortUrlInputFilter::DEVICE_LONG_URLS => [
|
||||
DeviceType::ANDROID->value => null,
|
||||
DeviceType::DESKTOP->value => 'desktop',
|
||||
],
|
||||
]));
|
||||
self::assertEquals([
|
||||
DeviceType::ANDROID->value => null,
|
||||
DeviceType::IOS->value => 'ios',
|
||||
DeviceType::DESKTOP->value => 'desktop',
|
||||
], $shortUrl->deviceLongUrls());
|
||||
|
||||
$shortUrl->update(ShortUrlEdition::fromRawData([
|
||||
ShortUrlInputFilter::DEVICE_LONG_URLS => [
|
||||
DeviceType::ANDROID->value => null,
|
||||
DeviceType::IOS->value => null,
|
||||
],
|
||||
]));
|
||||
self::assertEquals([
|
||||
DeviceType::ANDROID->value => null,
|
||||
DeviceType::IOS->value => null,
|
||||
DeviceType::DESKTOP->value => 'desktop',
|
||||
], $shortUrl->deviceLongUrls());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ class CreateShortUrlTest extends ApiTestCase
|
|||
'tags' => ['boo', 'far'],
|
||||
'validSince' => Chronos::now()->toAtomString(),
|
||||
'maxVisits' => 7,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue