2021-05-21 18:16:33 +02:00
|
|
|
<?php
|
|
|
|
|
2024-02-05 11:25:00 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-05-21 18:16:33 +02:00
|
|
|
namespace DanielSiepmann\Tracking\Tests\Functional;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 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.
|
|
|
|
*/
|
2024-02-05 11:25:00 +01:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
2021-05-21 18:16:33 +02:00
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler;
|
|
|
|
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
|
2022-12-07 13:37:19 +01:00
|
|
|
use UnexpectedValueException;
|
2021-05-21 18:16:33 +02:00
|
|
|
|
2024-02-05 11:25:00 +01:00
|
|
|
#[TestDox('This extension works with TYPO3 feature:')]
|
|
|
|
final class Typo3FeaturesTest extends AbstractFunctionalTestCase
|
2021-05-21 18:16:33 +02:00
|
|
|
{
|
2022-12-07 13:37:19 +01:00
|
|
|
protected function setUp(): void
|
2021-11-25 14:40:00 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2023-05-11 08:48:15 +02:00
|
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/BackendUser.php');
|
|
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/Typo3FeaturesTest/PageWithRecords.php');
|
2022-12-07 13:37:19 +01:00
|
|
|
$this->setUpBackendUser(1);
|
2024-02-05 11:25:00 +01:00
|
|
|
$languageServiceFactory = $this->get(LanguageServiceFactory::class);
|
2021-11-25 14:40:00 +01:00
|
|
|
if (!$languageServiceFactory instanceof LanguageServiceFactory) {
|
2022-12-07 13:37:19 +01:00
|
|
|
throw new UnexpectedValueException('Did not retrieve LanguageServiceFactory.', 1637847250);
|
2021-11-25 14:40:00 +01:00
|
|
|
}
|
|
|
|
$GLOBALS['LANG'] = $languageServiceFactory->create('default');
|
|
|
|
}
|
|
|
|
|
2022-12-07 13:37:19 +01:00
|
|
|
protected function tearDown(): void
|
2021-11-25 14:40:00 +01:00
|
|
|
{
|
|
|
|
unset($GLOBALS['LANG']);
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2024-02-05 11:25:00 +01:00
|
|
|
#[TestDox('Copy pages. Tracking records will not be copied.')]
|
|
|
|
#[Test]
|
2021-05-21 18:16:33 +02:00
|
|
|
public function copyContainingRecords(): void
|
|
|
|
{
|
2024-07-02 18:07:03 +02:00
|
|
|
$dataHandler = $this->createDataHandler();
|
2021-05-21 18:16:33 +02:00
|
|
|
$dataHandler->start([], [
|
|
|
|
'pages' => [
|
|
|
|
1 => [
|
|
|
|
'copy' => 1,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
$dataHandler->process_cmdmap();
|
|
|
|
|
|
|
|
self::assertCount(0, $dataHandler->errorLog, 'Failed with errors: ' . implode(PHP_EOL, $dataHandler->errorLog));
|
|
|
|
$this->assertCSVDataSet(
|
|
|
|
'EXT:tracking/Tests/Functional/ExpectedResults/Typo3FeaturesTest/CopyPasteContainingRecords.csv'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-02-05 11:25:00 +01:00
|
|
|
#[TestDox('Copy individual tables, but always exclude tracking tables.')]
|
|
|
|
#[Test]
|
2021-05-21 18:16:33 +02:00
|
|
|
public function copyCustomTablesViaDataHandler(): void
|
|
|
|
{
|
2024-07-02 18:07:03 +02:00
|
|
|
$dataHandler = $this->createDataHandler();
|
2021-05-21 18:16:33 +02:00
|
|
|
$dataHandler->copyWhichTables = 'pages,tx_tracking_pageview,tx_tracking_recordview';
|
|
|
|
$dataHandler->start([], [
|
|
|
|
'pages' => [
|
|
|
|
1 => [
|
|
|
|
'copy' => 1,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
$dataHandler->process_cmdmap();
|
|
|
|
|
|
|
|
self::assertCount(0, $dataHandler->errorLog, 'Failed with errors: ' . implode(PHP_EOL, $dataHandler->errorLog));
|
|
|
|
$this->assertCSVDataSet(
|
|
|
|
'EXT:tracking/Tests/Functional/ExpectedResults/Typo3FeaturesTest/CopyPasteContainingRecords.csv'
|
|
|
|
);
|
|
|
|
}
|
2024-07-02 18:07:03 +02:00
|
|
|
|
|
|
|
private function createDataHandler(): DataHandler
|
|
|
|
{
|
|
|
|
// Prior TYPO3 v13.2
|
|
|
|
if ($this->has(DataHandler::class) === false) {
|
|
|
|
return new DataHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->get(DataHandler::class);
|
|
|
|
}
|
2021-05-21 18:16:33 +02:00
|
|
|
}
|