2020-07-30 12:22:32 +02:00
|
|
|
<?php
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-07-30 12:22:32 +02:00
|
|
|
namespace DanielSiepmann\Tracking\Tests\Functional\Dashboard\Provider;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\Dashboard\Provider\PageviewsPerDay;
|
2024-10-15 14:07:38 +02:00
|
|
|
use DanielSiepmann\Tracking\Tests\Functional\AbstractFunctionalTestCase;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2020-07-30 12:22:32 +02:00
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
2022-12-07 13:37:19 +01:00
|
|
|
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
|
2020-07-30 12:22:32 +02:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[CoversClass(PageviewsPerDay::class)]
|
|
|
|
final class PageviewsPerDayTest extends AbstractFunctionalTestCase
|
2020-07-30 12:22:32 +02:00
|
|
|
{
|
2022-12-07 13:37:19 +01:00
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2024-10-15 14:07:38 +02:00
|
|
|
$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
|
2022-12-07 13:37:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
unset($GLOBALS['LANG']);
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-30 12:22:32 +02:00
|
|
|
public function listsResultsForLast31DaysByDefault(): void
|
|
|
|
{
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'crdate' => strtotime('-' . $i . ' days'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerDay(
|
2022-12-07 13:37:19 +01:00
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
2020-07-30 12:22:32 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertCount(32, $result['labels']);
|
|
|
|
self::assertCount(32, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-30 12:22:32 +02:00
|
|
|
public function respectedNumberOfDays(): void
|
|
|
|
{
|
2023-05-11 08:48:15 +02:00
|
|
|
$this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php');
|
2020-07-30 12:22:32 +02:00
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'crdate' => strtotime('-' . $i . ' days'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerDay(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
3
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertCount(4, $result['labels']);
|
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
1,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
], $result['datasets'][0]['data']);
|
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-30 12:22:32 +02:00
|
|
|
public function respectedExcludedPages(): void
|
|
|
|
{
|
2023-05-11 08:48:15 +02:00
|
|
|
$this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php');
|
2020-07-30 12:22:32 +02:00
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'crdate' => strtotime('-' . $i . ' days'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerDay(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
3,
|
|
|
|
[2]
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertCount(4, $result['labels']);
|
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
1,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
], $result['datasets'][0]['data']);
|
|
|
|
}
|
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-07-30 12:22:32 +02:00
|
|
|
public function respectedDateFormat(): void
|
|
|
|
{
|
2023-05-11 08:48:15 +02:00
|
|
|
$this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php');
|
2020-07-30 12:22:32 +02:00
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
|
|
|
|
$subject = new PageviewsPerDay(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
1,
|
|
|
|
[],
|
2020-08-03 12:33:02 +02:00
|
|
|
[],
|
2020-07-30 12:22:32 +02:00
|
|
|
'd.m.Y'
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame([
|
2020-07-30 12:22:32 +02:00
|
|
|
date('d.m.Y', strtotime('-1 day')),
|
|
|
|
date('d.m.Y'),
|
|
|
|
], $result['labels']);
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertCount(2, $result['datasets'][0]['data']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
2020-08-03 12:33:02 +02:00
|
|
|
|
2024-10-15 14:07:38 +02:00
|
|
|
#[Test]
|
2020-08-03 12:33:02 +02:00
|
|
|
public function respectsLimitToLanguages(): void
|
|
|
|
{
|
|
|
|
$connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview');
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
|
|
$connection->insert('tx_tracking_pageview', [
|
|
|
|
'pid' => $i,
|
|
|
|
'crdate' => strtotime('-' . $i . ' days'),
|
|
|
|
'sys_language_uid' => $i % 2,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$subject = new PageviewsPerDay(
|
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'),
|
|
|
|
11,
|
|
|
|
[],
|
|
|
|
[1]
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $subject->getChartData();
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame([
|
2020-08-03 12:33:02 +02:00
|
|
|
0 => 0,
|
|
|
|
1 => 0,
|
|
|
|
2 => 1,
|
|
|
|
3 => 0,
|
|
|
|
4 => 1,
|
|
|
|
5 => 0,
|
|
|
|
6 => 1,
|
|
|
|
7 => 0,
|
|
|
|
8 => 1,
|
|
|
|
9 => 0,
|
|
|
|
10 => 1,
|
|
|
|
11 => 0,
|
|
|
|
], $result['datasets'][0]['data']);
|
|
|
|
}
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|