mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-09 08:43:13 +08:00
Created named constructors for Visit entity and added tracking of the visited URL
This commit is contained in:
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Entity;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
@@ -13,35 +12,30 @@ use Shlinkio\Shlink\Core\Model\Visitor;
|
||||
|
||||
class VisitTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideDates
|
||||
*/
|
||||
public function isProperlyJsonSerialized(?Chronos $date): void
|
||||
/** @test */
|
||||
public function isProperlyJsonSerialized(): void
|
||||
{
|
||||
$visit = new Visit(ShortUrl::createEmpty(), new Visitor('Chrome', 'some site', '1.2.3.4'), true, $date);
|
||||
$visit = Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('Chrome', 'some site', '1.2.3.4', ''));
|
||||
|
||||
self::assertEquals([
|
||||
'referer' => 'some site',
|
||||
'date' => ($date ?? $visit->getDate())->toAtomString(),
|
||||
'date' => $visit->getDate()->toAtomString(),
|
||||
'userAgent' => 'Chrome',
|
||||
'visitLocation' => null,
|
||||
], $visit->jsonSerialize());
|
||||
}
|
||||
|
||||
public function provideDates(): iterable
|
||||
{
|
||||
yield 'null date' => [null];
|
||||
yield 'not null date' => [Chronos::now()->subDays(10)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideAddresses
|
||||
*/
|
||||
public function addressIsAnonymizedWhenRequested(bool $anonymize, ?string $address, ?string $expectedAddress): void
|
||||
{
|
||||
$visit = new Visit(ShortUrl::createEmpty(), new Visitor('Chrome', 'some site', $address), $anonymize);
|
||||
$visit = Visit::forValidShortUrl(
|
||||
ShortUrl::createEmpty(),
|
||||
new Visitor('Chrome', 'some site', $address, ''),
|
||||
$anonymize,
|
||||
);
|
||||
|
||||
self::assertEquals($expectedAddress, $visit->getRemoteAddr());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user