2020-07-29 10:07:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DanielSiepmann\Tracking\Tests\Unit\Domain\Recordview;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use DanielSiepmann\Tracking\Domain\Model\RecordRule;
|
|
|
|
use DanielSiepmann\Tracking\Domain\Model\Recordview;
|
|
|
|
use DanielSiepmann\Tracking\Domain\Recordview\Factory;
|
2022-12-07 13:37:19 +01:00
|
|
|
use DateTimeImmutable;
|
2020-07-29 10:07:14 +02:00
|
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use TYPO3\CMS\Core\Routing\PageArguments;
|
|
|
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
2022-09-16 14:59:54 +02:00
|
|
|
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
2020-07-29 10:07:14 +02:00
|
|
|
|
|
|
|
/**
|
2022-12-07 13:37:19 +01:00
|
|
|
* @covers \DanielSiepmann\Tracking\Domain\Recordview\Factory
|
2020-07-29 10:07:14 +02:00
|
|
|
*/
|
2022-09-16 14:59:54 +02:00
|
|
|
class FactoryTest extends FunctionalTestCase
|
2020-07-29 10:07:14 +02:00
|
|
|
{
|
|
|
|
use ProphecyTrait;
|
|
|
|
|
2022-12-07 13:37:19 +01:00
|
|
|
protected array $testExtensionsToLoad = [
|
2022-09-16 14:59:54 +02:00
|
|
|
'typo3conf/ext/tracking',
|
|
|
|
];
|
|
|
|
|
2020-07-29 10:07:14 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsRecordviewFromRequest(): void
|
|
|
|
{
|
|
|
|
$rule = $this->prophesize(RecordRule::class);
|
2021-11-25 14:40:00 +01:00
|
|
|
$rule->getUidExpression()->willReturn('request.getQueryParams()["category"]');
|
2020-07-29 10:07:14 +02:00
|
|
|
$rule->getTableName()->willReturn('sys_category');
|
|
|
|
|
|
|
|
$routing = $this->prophesize(PageArguments::class);
|
|
|
|
$routing->getPageId()->willReturn(10);
|
|
|
|
|
|
|
|
$language = $this->prophesize(SiteLanguage::class);
|
|
|
|
|
|
|
|
$request = $this->prophesize(ServerRequestInterface::class);
|
|
|
|
$request->getAttribute('routing')->willReturn($routing->reveal());
|
|
|
|
$request->getAttribute('language')->willReturn($language->reveal());
|
|
|
|
$request->getUri()->willReturn('');
|
|
|
|
$request->getHeader('User-Agent')->willReturn([]);
|
|
|
|
$request->getQueryParams()->willReturn([
|
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertInstanceOf(Recordview::class, $result);
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnedRecordviewContainsUserAgent(): void
|
|
|
|
{
|
|
|
|
$rule = $this->prophesize(RecordRule::class);
|
2021-11-25 14:40:00 +01:00
|
|
|
$rule->getUidExpression()->willReturn('request.getQueryParams()["category"]');
|
2020-07-29 10:07:14 +02:00
|
|
|
$rule->getTableName()->willReturn('sys_category');
|
|
|
|
|
|
|
|
$routing = $this->prophesize(PageArguments::class);
|
|
|
|
$routing->getPageId()->willReturn(10);
|
|
|
|
|
|
|
|
$language = $this->prophesize(SiteLanguage::class);
|
|
|
|
|
|
|
|
$request = $this->prophesize(ServerRequestInterface::class);
|
|
|
|
$request->getAttribute('routing')->willReturn($routing->reveal());
|
|
|
|
$request->getAttribute('language')->willReturn($language->reveal());
|
|
|
|
$request->getUri()->willReturn('');
|
|
|
|
$request->getHeader('User-Agent')->willReturn(['Some User Agent']);
|
|
|
|
$request->getQueryParams()->willReturn([
|
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame('Some User Agent', $result->getUserAgent());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnedRecordviewContainsUri(): void
|
|
|
|
{
|
|
|
|
$rule = $this->prophesize(RecordRule::class);
|
2021-11-25 14:40:00 +01:00
|
|
|
$rule->getUidExpression()->willReturn('request.getQueryParams()["category"]');
|
2020-07-29 10:07:14 +02:00
|
|
|
$rule->getTableName()->willReturn('sys_category');
|
|
|
|
|
|
|
|
$routing = $this->prophesize(PageArguments::class);
|
|
|
|
$routing->getPageId()->willReturn(10);
|
|
|
|
|
|
|
|
$language = $this->prophesize(SiteLanguage::class);
|
|
|
|
|
|
|
|
$request = $this->prophesize(ServerRequestInterface::class);
|
|
|
|
$request->getAttribute('routing')->willReturn($routing->reveal());
|
|
|
|
$request->getAttribute('language')->willReturn($language->reveal());
|
|
|
|
$request->getUri()->willReturn('https://example.com');
|
|
|
|
$request->getHeader('User-Agent')->willReturn(['']);
|
|
|
|
$request->getQueryParams()->willReturn([
|
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame('https://example.com', $result->getUrl());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnedRecordviewContainsDateTime(): void
|
|
|
|
{
|
|
|
|
$rule = $this->prophesize(RecordRule::class);
|
2021-11-25 14:40:00 +01:00
|
|
|
$rule->getUidExpression()->willReturn('request.getQueryParams()["category"]');
|
2020-07-29 10:07:14 +02:00
|
|
|
$rule->getTableName()->willReturn('sys_category');
|
|
|
|
|
|
|
|
$routing = $this->prophesize(PageArguments::class);
|
|
|
|
$routing->getPageId()->willReturn(10);
|
|
|
|
|
|
|
|
$language = $this->prophesize(SiteLanguage::class);
|
|
|
|
|
|
|
|
$request = $this->prophesize(ServerRequestInterface::class);
|
|
|
|
$request->getAttribute('routing')->willReturn($routing->reveal());
|
|
|
|
$request->getAttribute('language')->willReturn($language->reveal());
|
|
|
|
$request->getUri()->willReturn('https://example.com');
|
|
|
|
$request->getHeader('User-Agent')->willReturn(['']);
|
|
|
|
$request->getQueryParams()->willReturn([
|
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertInstanceOf(DateTimeImmutable::class, $result->getCrdate());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnedRecordviewContainsLanguage(): void
|
|
|
|
{
|
|
|
|
$rule = $this->prophesize(RecordRule::class);
|
2021-11-25 14:40:00 +01:00
|
|
|
$rule->getUidExpression()->willReturn('request.getQueryParams()["category"]');
|
2020-07-29 10:07:14 +02:00
|
|
|
$rule->getTableName()->willReturn('sys_category');
|
|
|
|
|
|
|
|
$routing = $this->prophesize(PageArguments::class);
|
|
|
|
$routing->getPageId()->willReturn(10);
|
|
|
|
|
|
|
|
$language = $this->prophesize(SiteLanguage::class);
|
|
|
|
|
|
|
|
$request = $this->prophesize(ServerRequestInterface::class);
|
|
|
|
$request->getAttribute('routing')->willReturn($routing->reveal());
|
|
|
|
$request->getAttribute('language')->willReturn($language->reveal());
|
|
|
|
$request->getUri()->willReturn('https://example.com');
|
|
|
|
$request->getHeader('User-Agent')->willReturn(['']);
|
|
|
|
$request->getQueryParams()->willReturn([
|
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame($language->reveal(), $result->getLanguage());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnedRecordviewContainsPageId(): void
|
|
|
|
{
|
|
|
|
$rule = $this->prophesize(RecordRule::class);
|
2021-11-25 14:40:00 +01:00
|
|
|
$rule->getUidExpression()->willReturn('request.getQueryParams()["category"]');
|
2020-07-29 10:07:14 +02:00
|
|
|
$rule->getTableName()->willReturn('sys_category');
|
|
|
|
|
|
|
|
$routing = $this->prophesize(PageArguments::class);
|
|
|
|
$routing->getPageId()->willReturn(10);
|
|
|
|
|
|
|
|
$language = $this->prophesize(SiteLanguage::class);
|
|
|
|
|
|
|
|
$request = $this->prophesize(ServerRequestInterface::class);
|
|
|
|
$request->getAttribute('routing')->willReturn($routing->reveal());
|
|
|
|
$request->getAttribute('language')->willReturn($language->reveal());
|
|
|
|
$request->getUri()->willReturn('https://example.com');
|
|
|
|
$request->getHeader('User-Agent')->willReturn(['']);
|
|
|
|
$request->getQueryParams()->willReturn([
|
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame(10, $result->getPageUid());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnedRecordviewContainsRecordUid(): void
|
|
|
|
{
|
|
|
|
$rule = $this->prophesize(RecordRule::class);
|
|
|
|
$rule->getUidExpression()->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->getTableName()->willReturn('sys_category');
|
|
|
|
|
|
|
|
$routing = $this->prophesize(PageArguments::class);
|
|
|
|
$routing->getPageId()->willReturn(10);
|
|
|
|
|
|
|
|
$language = $this->prophesize(SiteLanguage::class);
|
|
|
|
|
|
|
|
$request = $this->prophesize(ServerRequestInterface::class);
|
|
|
|
$request->getAttribute('routing')->willReturn($routing->reveal());
|
|
|
|
$request->getAttribute('language')->willReturn($language->reveal());
|
|
|
|
$request->getUri()->willReturn('https://example.com');
|
|
|
|
$request->getHeader('User-Agent')->willReturn(['']);
|
|
|
|
$request->getQueryParams()->willReturn([
|
|
|
|
'category' => 20,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame(20, $result->getRecordUid());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnedRecordviewContainsTableName(): void
|
|
|
|
{
|
|
|
|
$rule = $this->prophesize(RecordRule::class);
|
2021-11-25 14:40:00 +01:00
|
|
|
$rule->getUidExpression()->willReturn('request.getQueryParams()["category"]');
|
2020-07-29 10:07:14 +02:00
|
|
|
$rule->getTableName()->willReturn('sys_category');
|
|
|
|
|
|
|
|
$routing = $this->prophesize(PageArguments::class);
|
|
|
|
$routing->getPageId()->willReturn(10);
|
|
|
|
|
|
|
|
$language = $this->prophesize(SiteLanguage::class);
|
|
|
|
|
|
|
|
$request = $this->prophesize(ServerRequestInterface::class);
|
|
|
|
$request->getAttribute('routing')->willReturn($routing->reveal());
|
|
|
|
$request->getAttribute('language')->willReturn($language->reveal());
|
|
|
|
$request->getUri()->willReturn('https://example.com');
|
|
|
|
$request->getHeader('User-Agent')->willReturn(['']);
|
|
|
|
$request->getQueryParams()->willReturn([
|
|
|
|
'category' => 20,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame('sys_category', $result->getTableName());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
}
|