mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-11 07:55:47 -06:00
Merge pull request #765 from acelaya-forks/feature/fix-dates-match
Feature/fix dates match
This commit is contained in:
commit
21ef1dfee8
23
CHANGELOG.md
23
CHANGELOG.md
@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
||||
|
||||
## 2.2.1 - 2020-05-11
|
||||
|
||||
#### Added
|
||||
|
||||
* *Nothing*
|
||||
|
||||
#### Changed
|
||||
|
||||
* *Nothing*
|
||||
|
||||
#### Deprecated
|
||||
|
||||
* *Nothing*
|
||||
|
||||
#### Removed
|
||||
|
||||
* *Nothing*
|
||||
|
||||
#### Fixed
|
||||
|
||||
* [#764](https://github.com/shlinkio/shlink/issues/764) Fixed error when trying to match an existing short URL which does not have `validSince` and/or `validUntil`, but you are providing either one of them for the new one.
|
||||
|
||||
|
||||
## 2.2.0 - 2020-05-09
|
||||
|
||||
#### Added
|
||||
|
@ -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