‪TYPO3CMS  ‪main
TranslationDiffSourceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\CMS\Backend\Utility\BackendUtility;
27 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
28 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
29 
30 final class ‪TranslationDiffSourceTest extends FunctionalTestCase
31 {
33 
34  private const ‪PAGE_DATAHANDLER = 88;
35  private const ‪LANGUAGE_PRESETS = [
36  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
37  'DA' => ['id' => 1, 'title' => 'Dansk', 'locale' => 'da_DK.UTF8'],
38  ];
39 
40  protected function ‪setUp(): void
41  {
42  parent::setUp();
43  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users_admin.csv');
44  $this->importCSVDataSet(__DIR__ . '/DataSet/TranslationDiffSourceTest.csv');
46  'test',
47  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
48  [
49  $this->‪buildDefaultLanguageConfiguration('EN', '/en/'),
50  $this->‪buildLanguageConfiguration('DA', '/da/'),
51  ],
52  $this->‪buildErrorHandlingConfiguration('Fluid', [404]),
53  );
54  $backendUser = $this->setUpBackendUser(1);
55  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
56  }
57 
58  #[Test]
60  {
61  $actionService = new ActionService();
62  $map = $actionService->localizeRecord('pages', self::PAGE_DATAHANDLER, 1);
63  $newPageId = $map['pages'][‪self::PAGE_DATAHANDLER];
64  $originalLanguageRecord = BackendUtility::getRecord('pages', self::PAGE_DATAHANDLER);
65  $translatedRecord = BackendUtility::getRecord('pages', $newPageId);
66  $transOrigDiffSourceField = json_decode($translatedRecord[‪$GLOBALS['TCA']['pages']['ctrl']['transOrigDiffSourceField']], true);
67 
68  self::assertEquals('DataHandlerTest', $originalLanguageRecord['title']);
69  self::assertEquals('DataHandlerTest', $transOrigDiffSourceField['title']);
70  }
71 
72  #[Test]
73  public function ‪transOrigDiffSourceNotUpdatedAfterUndo(): void
74  {
75  $actionService = new ActionService();
76  $map = $actionService->localizeRecord('pages', self::PAGE_DATAHANDLER, 1);
77  $newPageId = $map['pages'][‪self::PAGE_DATAHANDLER];
78  $actionService->modifyRecord(
79  'pages',
80  self::PAGE_DATAHANDLER,
81  [
82  'title' => 'Modified dataHandler',
83  ]
84  );
85 
86  $element = 'pages:' . ‪self::PAGE_DATAHANDLER;
87  $recordHistory = GeneralUtility::makeInstance(RecordHistory::class, $element);
88  $changeLog = $recordHistory->getChangeLog();
89  $recordHistoryRollback = GeneralUtility::makeInstance(RecordHistoryRollback::class);
90  $recordHistoryRollback->performRollback($element, $recordHistory->getDiff($changeLog));
91 
92  ‪$record = BackendUtility::getRecord('pages', self::PAGE_DATAHANDLER);
93  $translatedRecord = BackendUtility::getRecord('pages', $newPageId);
94  $transOrigDiffSourceField = json_decode($translatedRecord[‪$GLOBALS['TCA']['pages']['ctrl']['transOrigDiffSourceField']], true);
95 
96  self::assertEmpty(‪$record[‪$GLOBALS['TCA']['pages']['ctrl']['transOrigDiffSourceField']]);
97  self::assertEquals('DataHandlerTest', $transOrigDiffSourceField['title']);
98  }
99 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:116
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\TranslationDiffSourceTest\transOrigDiffSourceFieldWrittenAfterTranslation
‪transOrigDiffSourceFieldWrittenAfterTranslation()
Definition: TranslationDiffSourceTest.php:58
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler
Definition: CheckboxValidationTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\TranslationDiffSourceTest\transOrigDiffSourceNotUpdatedAfterUndo
‪transOrigDiffSourceNotUpdatedAfterUndo()
Definition: TranslationDiffSourceTest.php:72
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\TranslationDiffSourceTest\PAGE_DATAHANDLER
‪const PAGE_DATAHANDLER
Definition: TranslationDiffSourceTest.php:33
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\TranslationDiffSourceTest\setUp
‪setUp()
Definition: TranslationDiffSourceTest.php:39
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:96
‪TYPO3\CMS\Backend\History\RecordHistoryRollback
Definition: RecordHistoryRollback.php:29
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildErrorHandlingConfiguration
‪buildErrorHandlingConfiguration(string $handler, array $codes)
Definition: SiteBasedTestTrait.php:150
‪TYPO3\CMS\Backend\History\RecordHistory
Definition: RecordHistory.php:32
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\TranslationDiffSourceTest
Definition: TranslationDiffSourceTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:106
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\TranslationDiffSourceTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: TranslationDiffSourceTest.php:34