2020-07-29 10:07:14 +02:00
|
|
|
<?php
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-07-29 10:07:14 +02:00
|
|
|
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;
|
2024-10-15 14:07:38 +02:00
|
|
|
use DanielSiepmann\Tracking\Tests\Functional\AbstractFunctionalTestCase;
|
2022-12-07 13:37:19 +01:00
|
|
|
use DateTimeImmutable;
|
2024-10-15 14:07:38 +02:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2020-07-29 10:07:14 +02:00
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use TYPO3\CMS\Core\Routing\PageArguments;
|
|
|
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[CoversClass(Factory::class)]
|
|
|
|
final class FactoryTest extends AbstractFunctionalTestCase
|
2020-07-29 10:07:14 +02:00
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-29 10:07:14 +02:00
|
|
|
public function returnsRecordviewFromRequest(): void
|
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
$rule = $this->createStub(RecordRule::class);
|
|
|
|
$rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->method('getTableName')->willReturn('sys_category');
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$routing = $this->createStub(PageArguments::class);
|
|
|
|
$routing->method('getPageId')->willReturn(10);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$language = $this->createStub(SiteLanguage::class);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$request = $this->createStub(ServerRequestInterface::class);
|
|
|
|
$request->method('getAttribute')->willReturnMap([
|
|
|
|
['routing', null, $routing],
|
|
|
|
['language', null, $language],
|
|
|
|
]);
|
|
|
|
$request->method('getUri')->willReturn('');
|
|
|
|
$request->method('getHeader')->willReturn([]);
|
|
|
|
$request->method('getQueryParams')->willReturn([
|
2020-07-29 10:07:14 +02:00
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$result = $subject->fromRequest($request, $rule);
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertInstanceOf(Recordview::class, $result);
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-29 10:07:14 +02:00
|
|
|
public function returnedRecordviewContainsUserAgent(): void
|
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
$rule = $this->createStub(RecordRule::class);
|
|
|
|
$rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->method('getTableName')->willReturn('sys_category');
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$routing = $this->createStub(PageArguments::class);
|
|
|
|
$routing->method('getPageId')->willReturn(10);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$language = $this->createStub(SiteLanguage::class);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$request = $this->createStub(ServerRequestInterface::class);
|
|
|
|
$request->method('getAttribute')->willReturnMap([
|
|
|
|
['routing', null, $routing],
|
|
|
|
['language', null, $language],
|
|
|
|
]);
|
|
|
|
$request->method('getUri')->willReturn('');
|
|
|
|
$request->method('getHeader')->willReturn(['Some User Agent']);
|
|
|
|
$request->method('getQueryParams')->willReturn([
|
2020-07-29 10:07:14 +02:00
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$result = $subject->fromRequest($request, $rule);
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame('Some User Agent', $result->getUserAgent());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-29 10:07:14 +02:00
|
|
|
public function returnedRecordviewContainsUri(): void
|
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
$rule = $this->createStub(RecordRule::class);
|
|
|
|
$rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->method('getTableName')->willReturn('sys_category');
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$routing = $this->createStub(PageArguments::class);
|
|
|
|
$routing->method('getPageId')->willReturn(10);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$language = $this->createStub(SiteLanguage::class);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$request = $this->createStub(ServerRequestInterface::class);
|
|
|
|
$request->method('getAttribute')->willReturnMap([
|
|
|
|
['routing', null, $routing],
|
|
|
|
['language', null, $language],
|
|
|
|
]);
|
|
|
|
$request->method('getUri')->willReturn('https://example.com');
|
|
|
|
$request->method('getHeader')->willReturn(['']);
|
|
|
|
$request->method('getQueryParams')->willReturn([
|
2020-07-29 10:07:14 +02:00
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$result = $subject->fromRequest($request, $rule);
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame('https://example.com', $result->getUrl());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-29 10:07:14 +02:00
|
|
|
public function returnedRecordviewContainsDateTime(): void
|
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
$rule = $this->createStub(RecordRule::class);
|
|
|
|
$rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->method('getTableName')->willReturn('sys_category');
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$routing = $this->createStub(PageArguments::class);
|
|
|
|
$routing->method('getPageId')->willReturn(10);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$language = $this->createStub(SiteLanguage::class);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$request = $this->createStub(ServerRequestInterface::class);
|
|
|
|
$request->method('getAttribute')->willReturnMap([
|
|
|
|
['routing', null, $routing],
|
|
|
|
['language', null, $language],
|
|
|
|
]);
|
|
|
|
$request->method('getUri')->willReturn('https://example.com');
|
|
|
|
$request->method('getHeader')->willReturn(['']);
|
|
|
|
$request->method('getQueryParams')->willReturn([
|
2020-07-29 10:07:14 +02:00
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$result = $subject->fromRequest($request, $rule);
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertInstanceOf(DateTimeImmutable::class, $result->getCrdate());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-29 10:07:14 +02:00
|
|
|
public function returnedRecordviewContainsLanguage(): void
|
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
$rule = $this->createStub(RecordRule::class);
|
|
|
|
$rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->method('getTableName')->willReturn('sys_category');
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$routing = $this->createStub(PageArguments::class);
|
|
|
|
$routing->method('getPageId')->willReturn(10);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$language = $this->createStub(SiteLanguage::class);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$request = $this->createStub(ServerRequestInterface::class);
|
|
|
|
$request->method('getAttribute')->willReturnMap([
|
|
|
|
['routing', null, $routing],
|
|
|
|
['language', null, $language],
|
|
|
|
]);
|
|
|
|
$request->method('getUri')->willReturn('https://example.com');
|
|
|
|
$request->method('getHeader')->willReturn(['']);
|
|
|
|
$request->method('getQueryParams')->willReturn([
|
2020-07-29 10:07:14 +02:00
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$result = $subject->fromRequest($request, $rule);
|
|
|
|
self::assertSame($language, $result->getLanguage());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-29 10:07:14 +02:00
|
|
|
public function returnedRecordviewContainsPageId(): void
|
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
$rule = $this->createStub(RecordRule::class);
|
|
|
|
$rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->method('getTableName')->willReturn('sys_category');
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$routing = $this->createStub(PageArguments::class);
|
|
|
|
$routing->method('getPageId')->willReturn(10);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$language = $this->createStub(SiteLanguage::class);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$request = $this->createStub(ServerRequestInterface::class);
|
|
|
|
$request->method('getAttribute')->willReturnMap([
|
|
|
|
['routing', null, $routing],
|
|
|
|
['language', null, $language],
|
|
|
|
]);
|
|
|
|
$request->method('getUri')->willReturn('https://example.com');
|
|
|
|
$request->method('getHeader')->willReturn(['']);
|
|
|
|
$request->method('getQueryParams')->willReturn([
|
2020-07-29 10:07:14 +02:00
|
|
|
'category' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$result = $subject->fromRequest($request, $rule);
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame(10, $result->getPageUid());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-29 10:07:14 +02:00
|
|
|
public function returnedRecordviewContainsRecordUid(): void
|
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
$rule = $this->createStub(RecordRule::class);
|
|
|
|
$rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->method('getTableName')->willReturn('sys_category');
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$routing = $this->createStub(PageArguments::class);
|
|
|
|
$routing->method('getPageId')->willReturn(10);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$language = $this->createStub(SiteLanguage::class);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$request = $this->createStub(ServerRequestInterface::class);
|
|
|
|
$request->method('getAttribute')->willReturnMap([
|
|
|
|
['routing', null, $routing],
|
|
|
|
['language', null, $language],
|
|
|
|
]);
|
|
|
|
$request->method('getUri')->willReturn('https://example.com');
|
|
|
|
$request->method('getHeader')->willReturn(['']);
|
|
|
|
$request->method('getQueryParams')->willReturn([
|
2020-07-29 10:07:14 +02:00
|
|
|
'category' => 20,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$result = $subject->fromRequest($request, $rule);
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame(20, $result->getRecordUid());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-29 10:07:14 +02:00
|
|
|
public function returnedRecordviewContainsTableName(): void
|
|
|
|
{
|
2024-10-15 14:07:38 +02:00
|
|
|
$rule = $this->createStub(RecordRule::class);
|
|
|
|
$rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]');
|
|
|
|
$rule->method('getTableName')->willReturn('sys_category');
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$routing = $this->createStub(PageArguments::class);
|
|
|
|
$routing->method('getPageId')->willReturn(10);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$language = $this->createStub(SiteLanguage::class);
|
2020-07-29 10:07:14 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$request = $this->createStub(ServerRequestInterface::class);
|
|
|
|
$request->method('getAttribute')->willReturnMap([
|
|
|
|
['routing', null, $routing],
|
|
|
|
['language', null, $language],
|
|
|
|
]);
|
|
|
|
$request->method('getUri')->willReturn('https://example.com');
|
|
|
|
$request->method('getHeader')->willReturn(['']);
|
|
|
|
$request->method('getQueryParams')->willReturn([
|
2020-07-29 10:07:14 +02:00
|
|
|
'category' => 20,
|
|
|
|
]);
|
|
|
|
|
2022-09-16 14:59:54 +02:00
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
$result = $subject->fromRequest($request, $rule);
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame('sys_category', $result->getTableName());
|
2020-07-29 10:07:14 +02:00
|
|
|
}
|
|
|
|
}
|