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\Command;
|
|
|
|
|
2020-07-30 12:22:32 +02:00
|
|
|
use DanielSiepmann\Tracking\Command\UpdateDataCommand;
|
2021-08-16 09:56:19 +02:00
|
|
|
use DanielSiepmann\Tracking\Extension;
|
2020-07-30 12:22:32 +02:00
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
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\Command\UpdateDataCommand
|
2020-07-30 12:22:32 +02:00
|
|
|
*/
|
|
|
|
class UpdateDataCommandTest extends TestCase
|
|
|
|
{
|
|
|
|
protected $testExtensionsToLoad = [
|
|
|
|
'typo3conf/ext/tracking',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $pathsToLinkInTestInstance = [
|
|
|
|
'typo3conf/ext/tracking/Tests/Functional/Fixtures/sites' => 'typo3conf/sites',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function updatesAllEntriesWithMissingOperatingSystem(): void
|
|
|
|
{
|
2021-08-16 09:56:19 +02:00
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/UpdateDataCommandTest/WithMissingOperatingSystem.xml');
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$subject = GeneralUtility::makeInstance(UpdateDataCommand::class);
|
|
|
|
$tester = new CommandTester($subject);
|
|
|
|
$tester->execute([], ['capture_stderr_separately' => true]);
|
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame(0, $tester->getStatusCode());
|
2020-07-30 12:22:32 +02:00
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
$records = $this->getAllRecords('tx_tracking_tag');
|
|
|
|
self::assertCount(8, $records);
|
|
|
|
self::assertSame([
|
|
|
|
'uid'=> '1',
|
|
|
|
'pid'=> '1',
|
|
|
|
'tstamp'=> '1630649915',
|
|
|
|
'crdate'=> '1630649915',
|
|
|
|
'cruser_id'=> '0',
|
|
|
|
'record_uid' => '1',
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[0]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid'=> '2',
|
|
|
|
'pid'=> '1',
|
|
|
|
'tstamp'=> '1630649915',
|
|
|
|
'crdate'=> '1630649915',
|
|
|
|
'cruser_id'=> '0',
|
|
|
|
'record_uid' => '1',
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'os',
|
|
|
|
'value' => 'Linux',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[1]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid'=> '3',
|
|
|
|
'pid'=> '1',
|
|
|
|
'tstamp'=> '1630649916',
|
|
|
|
'crdate'=> '1630649916',
|
|
|
|
'cruser_id'=> '0',
|
|
|
|
'record_uid' => '2',
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[2]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid'=> '4',
|
|
|
|
'pid'=> '1',
|
|
|
|
'tstamp'=> '1630649916',
|
|
|
|
'crdate'=> '1630649916',
|
|
|
|
'cruser_id'=> '0',
|
|
|
|
'record_uid' => '2',
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'os',
|
|
|
|
'value' => 'Android',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[3]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid'=> '5',
|
|
|
|
'pid'=> '1',
|
|
|
|
'tstamp'=> '1630649915',
|
|
|
|
'crdate'=> '1630649915',
|
|
|
|
'cruser_id'=> '0',
|
|
|
|
'record_uid' => '1',
|
|
|
|
'record_table_name' => 'tx_tracking_recordview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[4]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid'=> '6',
|
|
|
|
'pid'=> '1',
|
|
|
|
'tstamp'=> '1630649915',
|
|
|
|
'crdate'=> '1630649915',
|
|
|
|
'cruser_id'=> '0',
|
|
|
|
'record_uid' => '1',
|
|
|
|
'record_table_name' => 'tx_tracking_recordview',
|
|
|
|
'name' => 'os',
|
|
|
|
'value' => 'Linux',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[5]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid'=> '7',
|
|
|
|
'pid'=> '1',
|
|
|
|
'tstamp'=> '1630649916',
|
|
|
|
'crdate'=> '1630649916',
|
|
|
|
'cruser_id'=> '0',
|
|
|
|
'record_uid' => '2',
|
|
|
|
'record_table_name' => 'tx_tracking_recordview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[6]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid'=> '8',
|
|
|
|
'pid'=> '1',
|
|
|
|
'tstamp'=> '1630649916',
|
|
|
|
'crdate'=> '1630649916',
|
|
|
|
'cruser_id'=> '0',
|
|
|
|
'record_uid' => '2',
|
|
|
|
'record_table_name' => 'tx_tracking_recordview',
|
|
|
|
'name' => 'os',
|
|
|
|
'value' => 'Android',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[7]));
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function doesNotChangeExistingOperatingSystem(): void
|
|
|
|
{
|
2021-08-16 09:56:19 +02:00
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/UpdateDataCommandTest/WithOperatingSystem.xml');
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$subject = GeneralUtility::makeInstance(UpdateDataCommand::class);
|
|
|
|
$tester = new CommandTester($subject);
|
|
|
|
$tester->execute([], ['capture_stderr_separately' => true]);
|
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame(0, $tester->getStatusCode());
|
2020-07-30 12:22:32 +02:00
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
$records = $this->getAllRecords('tx_tracking_tag');
|
|
|
|
self::assertCount(4, $records);
|
|
|
|
self::assertSame([
|
|
|
|
'uid' => '3',
|
|
|
|
'pid' => '1',
|
|
|
|
'tstamp'=> '1630649915',
|
|
|
|
'crdate'=> '1630649915',
|
|
|
|
'cruser_id' => '0',
|
|
|
|
'record_uid' => '1',
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[0]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid' => '4',
|
|
|
|
'pid' => '1',
|
|
|
|
'tstamp'=> '1630649915',
|
|
|
|
'crdate'=> '1630649915',
|
|
|
|
'cruser_id' => '0',
|
|
|
|
'record_uid' => '1',
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'os',
|
|
|
|
'value' => 'Linux',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[1]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid' => '5',
|
|
|
|
'pid' => '1',
|
|
|
|
'tstamp'=> '1630649916',
|
|
|
|
'crdate'=> '1630649916',
|
|
|
|
'cruser_id' => '0',
|
|
|
|
'record_uid' => '2',
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'bot',
|
|
|
|
'value' => 'no',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[2]));
|
|
|
|
self::assertSame([
|
|
|
|
'uid' => '6',
|
|
|
|
'pid' => '1',
|
|
|
|
'tstamp'=> '1630649916',
|
|
|
|
'crdate'=> '1630649916',
|
|
|
|
'cruser_id' => '0',
|
|
|
|
'record_uid' => '2',
|
|
|
|
'record_table_name' => 'tx_tracking_pageview',
|
|
|
|
'name' => 'os',
|
|
|
|
'value' => 'Android',
|
|
|
|
'compatible_version' => Extension::getCompatibleVersionNow(),
|
|
|
|
], array_map('strval', $records[3]));
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function doesNothingIfNoRecordExists(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/Pages.xml');
|
|
|
|
|
|
|
|
$subject = GeneralUtility::makeInstance(UpdateDataCommand::class);
|
|
|
|
$tester = new CommandTester($subject);
|
|
|
|
$tester->execute([], ['capture_stderr_separately' => true]);
|
|
|
|
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertSame(0, $tester->getStatusCode());
|
2020-07-30 12:22:32 +02:00
|
|
|
|
|
|
|
$records = $this->getAllRecords('tx_tracking_pageview');
|
2021-08-16 09:56:19 +02:00
|
|
|
self::assertCount(0, $records);
|
|
|
|
|
|
|
|
$records = $this->getAllRecords('tx_tracking_tag');
|
|
|
|
self::assertCount(0, $records);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function doesNothingIfAllRecordsAreCompatible(): void
|
|
|
|
{
|
|
|
|
$this->importDataSet('EXT:tracking/Tests/Functional/Fixtures/UpdateDataCommandTest/WithCompatibleVersion.xml');
|
|
|
|
|
|
|
|
$subject = GeneralUtility::makeInstance(UpdateDataCommand::class);
|
|
|
|
$tester = new CommandTester($subject);
|
|
|
|
$tester->execute([], ['capture_stderr_separately' => true]);
|
|
|
|
|
|
|
|
self::assertSame(0, $tester->getStatusCode());
|
|
|
|
|
|
|
|
$records = $this->getAllRecords('tx_tracking_pageview');
|
|
|
|
self::assertCount(1, $records);
|
|
|
|
|
|
|
|
$records = $this->getAllRecords('tx_tracking_recordview');
|
|
|
|
self::assertCount(1, $records);
|
|
|
|
|
|
|
|
$records = $this->getAllRecords('tx_tracking_tag');
|
|
|
|
self::assertCount(4, $records);
|
|
|
|
foreach ($records as $record) {
|
|
|
|
self::assertSame(1663773639, $record['crdate']);
|
|
|
|
}
|
2020-07-30 12:22:32 +02:00
|
|
|
}
|
|
|
|
}
|