From d5794a3dcb50d0a3d6fcd1e6caab0b92c54ae5e6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 9 Feb 2021 22:52:44 +0100 Subject: [PATCH] Created OrphanVisitDataTransformerTest --- .../OrphanVisitDataTransformerTest.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 module/Core/test/Visit/Transformer/OrphanVisitDataTransformerTest.php diff --git a/module/Core/test/Visit/Transformer/OrphanVisitDataTransformerTest.php b/module/Core/test/Visit/Transformer/OrphanVisitDataTransformerTest.php new file mode 100644 index 00000000..cf36c052 --- /dev/null +++ b/module/Core/test/Visit/Transformer/OrphanVisitDataTransformerTest.php @@ -0,0 +1,82 @@ +transformer = new OrphanVisitDataTransformer(); + } + + /** + * @test + * @dataProvider provideVisits + */ + public function visitsAreParsedAsExpected(Visit $visit, array $expectedResult): void + { + $result = $this->transformer->transform($visit); + + self::assertEquals($expectedResult, $result); + } + + public function provideVisits(): iterable + { + yield 'base path visit' => [ + $visit = Visit::forBasePath(Visitor::emptyInstance()), + [ + 'referer' => '', + 'date' => $visit->getDate()->toAtomString(), + 'userAgent' => '', + 'visitLocation' => null, + 'visitedUrl' => '', + 'type' => Visit::TYPE_BASE_URL, + ], + ]; + yield 'invalid short url visit' => [ + $visit = Visit::forInvalidShortUrl(Visitor::fromRequest( + ServerRequestFactory::fromGlobals()->withHeader('User-Agent', 'foo') + ->withHeader('Referer', 'bar') + ->withUri(new Uri('https://example.com/foo')), + )), + [ + 'referer' => 'bar', + 'date' => $visit->getDate()->toAtomString(), + 'userAgent' => 'foo', + 'visitLocation' => null, + 'visitedUrl' => 'https://example.com/foo', + 'type' => Visit::TYPE_INVALID_SHORT_URL, + ], + ]; + yield 'regular 404 visit' => [ + $visit = Visit::forRegularNotFound( + Visitor::fromRequest( + ServerRequestFactory::fromGlobals()->withHeader('User-Agent', 'user-agent') + ->withHeader('Referer', 'referer') + ->withUri(new Uri('https://doma.in/foo/bar')), + ), + )->locate($location = new VisitLocation(Location::emptyInstance())), + [ + 'referer' => 'referer', + 'date' => $visit->getDate()->toAtomString(), + 'userAgent' => 'user-agent', + 'visitLocation' => $location, + 'visitedUrl' => 'https://doma.in/foo/bar', + 'type' => Visit::TYPE_REGULAR_404, + ], + ]; + } +}