mirror of
https://github.com/DanielSiepmann/tracking.git
synced 2024-11-16 19:26:09 +01:00
Daniel Siepmann
5f0490f493
Allow each tracking record to contain arbitrary tags. Those tags are generated via an API and can be extended by foreign extensions or for individual projects. Existing operating_system was moved to this new feature. The update command allows to migrate existing records to this new feature. Those flags can be used when configuring widgets. A new flag was added bot:yes and bot:no. Bots are now tracked but flagged. That new feature allows to build fine grained reports and makes the extension way more flexible. Possible new implications: - Show visits from none bots - Show visits from bots - Show visits from specific bot - Add color to page views per page (bar chart) to color bot or none bot WIP: - Update Yaml file to work like before, no bots in widgets - Add documentation (widgets) - Add documentation (migration *.yaml)
277 lines
10 KiB
PHP
277 lines
10 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
namespace DanielSiepmann\Tracking\Tests\Unit\Domain\Recordview;
|
|
|
|
use DanielSiepmann\Tracking\Domain\Model\RecordRule;
|
|
use DanielSiepmann\Tracking\Domain\Model\Recordview;
|
|
use DanielSiepmann\Tracking\Domain\Recordview\Factory;
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use TYPO3\CMS\Core\Routing\PageArguments;
|
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
|
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
|
|
|
/**
|
|
* @covers \DanielSiepmann\Tracking\Domain\Recordview\Factory
|
|
*/
|
|
class FactoryTest extends FunctionalTestCase
|
|
{
|
|
use ProphecyTrait;
|
|
|
|
protected $testExtensionsToLoad = [
|
|
'typo3conf/ext/tracking',
|
|
];
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function returnsRecordviewFromRequest(): 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('');
|
|
$request->getHeader('User-Agent')->willReturn([]);
|
|
$request->getQueryParams()->willReturn([
|
|
'category' => 10,
|
|
]);
|
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
|
self::assertInstanceOf(Recordview::class, $result);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function returnedRecordviewContainsUserAgent(): 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('');
|
|
$request->getHeader('User-Agent')->willReturn(['Some User Agent']);
|
|
$request->getQueryParams()->willReturn([
|
|
'category' => 10,
|
|
]);
|
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
|
self::assertSame('Some User Agent', $result->getUserAgent());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function returnedRecordviewContainsUri(): 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' => 10,
|
|
]);
|
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
|
self::assertSame('https://example.com', $result->getUrl());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function returnedRecordviewContainsDateTime(): 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' => 10,
|
|
]);
|
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
|
self::assertInstanceOf(\DateTimeImmutable::class, $result->getCrdate());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function returnedRecordviewContainsLanguage(): 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' => 10,
|
|
]);
|
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
|
self::assertSame($language->reveal(), $result->getLanguage());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function returnedRecordviewContainsPageId(): 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' => 10,
|
|
]);
|
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
|
self::assertSame(10, $result->getPageUid());
|
|
}
|
|
|
|
/**
|
|
* @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,
|
|
]);
|
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
|
self::assertSame(20, $result->getRecordUid());
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function returnedRecordviewContainsTableName(): 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,
|
|
]);
|
|
|
|
$subject = $this->get(Factory::class);
|
|
|
|
$result = $subject->fromRequest($request->reveal(), $rule->reveal());
|
|
self::assertSame('sys_category', $result->getTableName());
|
|
}
|
|
}
|