2020-07-30 12:22:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DanielSiepmann\Tracking\Tests\Functional\Command;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2023-05-11 08:48:15 +02:00
|
|
|
use Codappix\Typo3PhpDatasets\TestingFramework;
|
2020-07-30 12:22:32 +02:00
|
|
|
use DanielSiepmann\Tracking\Command\UpdateDataCommand;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
2023-05-11 08:48:15 +02:00
|
|
|
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
/**
|
2022-12-07 13:37:19 +01:00
|
|
|
* @covers \DanielSiepmann\Tracking\Command\UpdateDataCommand
|
2020-07-30 12:22:32 +02:00
|
|
|
*/
|
2023-05-11 08:48:15 +02:00
|
|
|
class UpdateDataCommandTest extends FunctionalTestCase
|
2020-07-30 12:22:32 +02:00
|
|
|
{
|
2023-05-11 08:48:15 +02:00
|
|
|
use TestingFramework;
|
|
|
|
|
2022-12-07 13:37:19 +01:00
|
|
|
protected array $testExtensionsToLoad = [
|
2020-07-30 12:22:32 +02:00
|
|
|
'typo3conf/ext/tracking',
|
|
|
|
];
|
|
|
|
|
2022-12-07 13:37:19 +01:00
|
|
|
protected array $pathsToLinkInTestInstance = [
|
2020-07-30 12:22:32 +02:00
|
|
|
'typo3conf/ext/tracking/Tests/Functional/Fixtures/sites' => 'typo3conf/sites',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function updatesAllEntriesWithMissingOperatingSystem(): void
|
|
|
|
{
|
2023-05-11 08:48:15 +02:00
|
|
|
$this->importPHPDataSet(__DIR__ . '/../Fixtures/UpdateDataCommandTest/PageviewsWithMissingOperatingSystem.php');
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$subject = GeneralUtility::makeInstance(UpdateDataCommand::class);
|
|
|
|
$tester = new CommandTester($subject);
|
|
|
|
$tester->execute([], ['capture_stderr_separately' => true]);
|
|
|
|
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame(0, $tester->getStatusCode());
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$records = $this->getAllRecords('tx_tracking_pageview');
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertCount(2, $records);
|
|
|
|
self::assertSame('Linux', $records[0]['operating_system']);
|
|
|
|
self::assertSame('Android', $records[1]['operating_system']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function doesNotChangeExistingOperatingSystem(): void
|
|
|
|
{
|
2023-05-11 08:48:15 +02:00
|
|
|
$this->importPHPDataSet(__DIR__ . '/../Fixtures/UpdateDataCommandTest/PageviewsWithOperatingSystem.php');
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$subject = GeneralUtility::makeInstance(UpdateDataCommand::class);
|
|
|
|
$tester = new CommandTester($subject);
|
|
|
|
$tester->execute([], ['capture_stderr_separately' => true]);
|
|
|
|
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame(0, $tester->getStatusCode());
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$records = $this->getAllRecords('tx_tracking_pageview');
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertCount(2, $records);
|
|
|
|
self::assertSame('Linux', $records[0]['operating_system']);
|
|
|
|
self::assertSame('Android', $records[1]['operating_system']);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function doesNothingIfNoRecordExists(): void
|
|
|
|
{
|
2023-05-11 08:48:15 +02:00
|
|
|
$this->importPHPDataSet(__DIR__ . '/../Fixtures/Pages.php');
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$subject = GeneralUtility::makeInstance(UpdateDataCommand::class);
|
|
|
|
$tester = new CommandTester($subject);
|
|
|
|
$tester->execute([], ['capture_stderr_separately' => true]);
|
|
|
|
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertSame(0, $tester->getStatusCode());
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$records = $this->getAllRecords('tx_tracking_pageview');
|
2022-12-07 13:37:19 +01:00
|
|
|
self::assertCount(0, $records);
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
}
|