mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-23 23:13:26 -06:00
Fixed error when trying to match creteria on a Short URL with dates
This commit is contained in:
parent
cb6756d801
commit
1fa9896524
@ -204,10 +204,10 @@ class ShortUrl extends AbstractEntity
|
||||
if ($meta->hasDomain() && $meta->getDomain() !== $this->resolveDomain()) {
|
||||
return false;
|
||||
}
|
||||
if ($meta->hasValidSince() && ! $meta->getValidSince()->eq($this->validSince)) {
|
||||
if ($meta->hasValidSince() && ($this->validSince === null || ! $meta->getValidSince()->eq($this->validSince))) {
|
||||
return false;
|
||||
}
|
||||
if ($meta->hasValidUntil() && ! $meta->getValidUntil()->eq($this->validUntil)) {
|
||||
if ($meta->hasValidUntil() && ($this->validUntil === null || ! $meta->getValidUntil()->eq($this->validUntil))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Entity;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Exception\ShortCodeCannotBeRegeneratedException;
|
||||
@ -74,4 +75,38 @@ class ShortUrlTest extends TestCase
|
||||
yield [null, DEFAULT_SHORT_CODES_LENGTH];
|
||||
yield from map(range(4, 10), fn (int $value) => [$value, $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideCriteriaToMatch
|
||||
*/
|
||||
public function criteriaIsMatchedWhenDatesMatch(ShortUrl $shortUrl, ShortUrlMeta $meta, bool $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, $shortUrl->matchesCriteria($meta, []));
|
||||
}
|
||||
|
||||
public function provideCriteriaToMatch(): iterable
|
||||
{
|
||||
$start = Chronos::parse('2020-03-05 20:18:30');
|
||||
$end = Chronos::parse('2021-03-05 20:18:30');
|
||||
|
||||
yield [new ShortUrl('foo'), ShortUrlMeta::fromRawData(['validSince' => $start]), false];
|
||||
yield [new ShortUrl('foo'), ShortUrlMeta::fromRawData(['validUntil' => $end]), false];
|
||||
yield [new ShortUrl('foo'), ShortUrlMeta::fromRawData(['validSince' => $start, 'validUntil' => $end]), false];
|
||||
yield [
|
||||
new ShortUrl('foo', ShortUrlMeta::fromRawData(['validSince' => $start])),
|
||||
ShortUrlMeta::fromRawData(['validSince' => $start]),
|
||||
true,
|
||||
];
|
||||
yield [
|
||||
new ShortUrl('foo', ShortUrlMeta::fromRawData(['validUntil' => $end])),
|
||||
ShortUrlMeta::fromRawData(['validUntil' => $end]),
|
||||
true,
|
||||
];
|
||||
yield [
|
||||
new ShortUrl('foo', ShortUrlMeta::fromRawData(['validUntil' => $end, 'validSince' => $start])),
|
||||
ShortUrlMeta::fromRawData(['validUntil' => $end, 'validSince' => $start]),
|
||||
true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user