2020-07-30 12:22:32 +02:00
|
|
|
<?php
|
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
declare(strict_types=1);
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
namespace DanielSiepmann\Tracking\Tests\Functional\Dashboard\Provider;
|
|
|
|
|
|
|
|
use DanielSiepmann\Tracking\Dashboard\Provider\Demand;
|
|
|
|
use DanielSiepmann\Tracking\Dashboard\Provider\Demand\Tag;
|
2020-07-30 12:22:32 +02:00
|
|
|
use DanielSiepmann\Tracking\Dashboard\Provider\PageviewsPerPage;
|
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
|
|
|
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
|
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase as TestCase;
|
|
|
|
|
|
|
|
/**
|
2021-08-16 09:56:19 +02:00
|
|
|
* @covers \DanielSiepmann\Tracking\Dashboard\Provider\PageviewsPerPage
|
2020-07-30 12:22:32 +02:00
|
|
|
*/
|
|
|
|
class PageviewsPerPageTest extends TestCase
|
|
|
|
{
|
|
|
|
protected $testExtensionsToLoad = [
|
|
|
|
'typo3conf/ext/tracking',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function listsSixResultsForLast31DaysByDefault(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
2021-08-16 09:56:19 +02:00
|
|
|
'uid' => $i,
|
2020-07-30 12:22:32 +02:00
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
2021-08-16 09:56:19 +02:00
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
|
|
|
new Demand()
|
2020-07-30 12:22:32 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
'Page 10',
|
|
|
|
'Page 9',
|
|
|
|
'Page 8',
|
|
|
|
'Page 7',
|
|
|
|
'Page 6',
|
|
|
|
'Page 5',
|
|
|
|
], $result['labels']);
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertCount(6, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function respectedOrdering(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 1,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 2,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 3,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 2,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
2021-08-16 09:56:19 +02:00
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
|
|
|
new Demand()
|
2020-07-30 12:22:32 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
'Page 2',
|
|
|
|
'Page 3',
|
|
|
|
'Page 1',
|
|
|
|
], $result['labels']);
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertCount(3, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function respectedNumberOfDays(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 1,
|
|
|
|
'crdate' => strtotime('-3 days'),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 2,
|
|
|
|
'crdate' => strtotime('-2 days'),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 3,
|
|
|
|
'crdate' => strtotime('-1 days'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
2021-08-16 09:56:19 +02:00
|
|
|
new Demand(2)
|
2020-07-30 12:22:32 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
'Page 3',
|
|
|
|
'Page 2',
|
|
|
|
], $result['labels']);
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertCount(2, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function respectedMaxResults(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
2021-08-16 09:56:19 +02:00
|
|
|
new Demand(31, 4)
|
2020-07-30 12:22:32 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
'Page 10',
|
|
|
|
'Page 9',
|
|
|
|
'Page 8',
|
|
|
|
'Page 7',
|
|
|
|
], $result['labels']);
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertCount(4, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function respectedExcludedPages(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
2021-08-16 09:56:19 +02:00
|
|
|
new Demand(31, 6, [1, 2, 3, 4, 5, 6])
|
2020-07-30 12:22:32 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
'Page 10',
|
|
|
|
'Page 9',
|
|
|
|
'Page 8',
|
|
|
|
'Page 7',
|
|
|
|
], $result['labels']);
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertCount(4, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function localizedRecordTitlesIfLimitedToSingleLanguage(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 1,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 1,
|
|
|
|
'sys_language_uid' => 1,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 2,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 2,
|
|
|
|
'sys_language_uid' => 1,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 3,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
2021-08-16 09:56:19 +02:00
|
|
|
new Demand(31, 6, [], [1])
|
2020-07-30 12:22:32 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
'Page 2',
|
2021-08-16 10:33:25 +02:00
|
|
|
'Page 1',
|
2020-07-30 12:22:32 +02:00
|
|
|
], $result['labels']);
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertCount(2, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function defaultLanguageTitleIsUsedIfMultipleLanguagesAreAllowed(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 1,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 1,
|
|
|
|
'sys_language_uid' => 1,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 2,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 2,
|
|
|
|
'sys_language_uid' => 1,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => 3,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
2021-08-16 09:56:19 +02:00
|
|
|
new Demand(31, 6, [], [1, 0])
|
2020-07-30 12:22:32 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
'Page 2',
|
|
|
|
'Page 1',
|
|
|
|
'Page 3',
|
|
|
|
], $result['labels']);
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertCount(3, $result['datasets'][0]['data']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function respectedConfiguredTagRuleToNotIncludeBots(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'uid' => $i,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_tag', [
|
|
|
|
'pid' => $i,
|
|
|
|
'uid' => $i,
|
|
|
|
'record_uid' => $i,
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
for ($i = 11; $i <= 20; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'uid' => $i,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_tag', [
|
|
|
|
'pid' => $i,
|
|
|
|
'uid' => $i,
|
|
|
|
'record_uid' => $i,
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'yes',
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
|
|
|
new Demand(31, 6, [], [], [
|
|
|
|
Tag::createFromArray([
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
]),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
|
|
|
self::assertSame([
|
|
|
|
'Page 10',
|
|
|
|
'Page 9',
|
|
|
|
'Page 8',
|
|
|
|
'Page 7',
|
|
|
|
'Page 6',
|
|
|
|
'Page 5',
|
|
|
|
], $result['labels']);
|
|
|
|
self::assertCount(6, $result['datasets'][0]['data']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function respectedConfiguredTagRuleToIncludeBots(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'uid' => $i,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_tag', [
|
|
|
|
'pid' => $i,
|
|
|
|
'uid' => $i,
|
|
|
|
'record_uid' => $i,
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
for ($i = 11; $i <= 20; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'uid' => $i,
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
$connection->insert('tx_tracking_tag', [
|
|
|
|
'pid' => $i,
|
|
|
|
'uid' => $i,
|
|
|
|
'record_uid' => $i,
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'yes',
|
|
|
|
'crdate' => time(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerPage(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
GeneralUtility::makeInstance(PageRepository::class),
|
|
|
|
new Demand(31, 6, [], [], [
|
|
|
|
Tag::createFromArray([
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'yes',
|
|
|
|
]),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
|
|
|
self::assertSame([
|
|
|
|
'Page 20',
|
|
|
|
'Page 19',
|
|
|
|
'Page 18',
|
|
|
|
'Page 17',
|
|
|
|
'Page 16',
|
|
|
|
'Page 15',
|
|
|
|
], $result['labels']);
|
|
|
|
self::assertCount(6, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
}
|