diff --git a/Classes/EventListener/ProvideDefaultTypo3LocalizationModesEventListener.php b/Classes/EventListener/ProvideDefaultTypo3LocalizationModesEventListener.php index 219f2d6..88d2371 100644 --- a/Classes/EventListener/ProvideDefaultTypo3LocalizationModesEventListener.php +++ b/Classes/EventListener/ProvideDefaultTypo3LocalizationModesEventListener.php @@ -4,6 +4,7 @@ namespace WebVision\Deepl\Base\EventListener; +use TYPO3\CMS\Backend\Controller\Page\LocalizationController; use TYPO3\CMS\Core\Utility\MathUtility; use WebVision\Deepl\Base\Event\GetLocalizationModesEvent; use WebVision\Deepl\Base\Localization\LocalizationMode; @@ -24,22 +25,22 @@ public function __invoke(GetLocalizationModesEvent $event): void $modes = []; if ($this->allowTranslate($event)) { $modes[] = new LocalizationMode( - identifier: 'localize', + identifier: LocalizationController::ACTION_LOCALIZE, title: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate'), description: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate'), icon: 'actions-localize', - before: ['copy'], + before: [LocalizationController::ACTION_COPY], after: [], ); } if ($this->allowCopy($event)) { $modes[] = new LocalizationMode( - identifier: 'copy', + identifier: LocalizationController::ACTION_COPY, title: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy'), description: $event->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy'), icon: 'actions-edit-copy', before: [], - after: ['localize'], + after: [LocalizationController::ACTION_LOCALIZE], ); } diff --git a/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/Result/copyToLanguage.csv b/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/Result/copyToLanguage.csv new file mode 100644 index 0000000..63c86e2 --- /dev/null +++ b/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/Result/copyToLanguage.csv @@ -0,0 +1,4 @@ +"tt_content", +,"uid","pid","CType","sys_language_uid","header","l18n_parent","l10n_source" +,1,3,"header",0,"Content header",0,0 +,2,3,"header",1,"[Translate to Deutsch:] Content header",0,1 diff --git a/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/Result/localize.csv b/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/Result/localize.csv new file mode 100644 index 0000000..9382458 --- /dev/null +++ b/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/Result/localize.csv @@ -0,0 +1,4 @@ +"tt_content", +,"uid","pid","CType","sys_language_uid","header","l18n_parent","l10n_source" +,1,3,"header",0,"Content header",0,0 +,2,3,"header",1,"[Translate to Deutsch:] Content header",1,1 diff --git a/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/TranslationModeSetup.csv b/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/TranslationModeSetup.csv new file mode 100644 index 0000000..f0c41dc --- /dev/null +++ b/Tests/Functional/Controller/Backend/Fixtures/TranslationModes/TranslationModeSetup.csv @@ -0,0 +1,13 @@ +"pages", +,"uid","pid","doktype","sys_language_uid","l10n_parent","slug","title","TSconfig", +,1,0,1,0,0,"/","site 1","", +,2,0,1,1,1,"/","Seite 1","", +,3,1,1,0,0,"/home","Home","", +,4,1,1,1,3,"/start","Start","", +"tt_content", +,"uid","pid","CType","sys_language_uid","header" +,1,3,"header",0,"Content header" +"be_users", +,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","TSconfig","lastlogin","workspace_id" +# The password is "password" +,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,,1371033743,0 diff --git a/Tests/Functional/Controller/Backend/LocalizationControllerTest.php b/Tests/Functional/Controller/Backend/LocalizationControllerTest.php index 7a1d2de..fae676c 100644 --- a/Tests/Functional/Controller/Backend/LocalizationControllerTest.php +++ b/Tests/Functional/Controller/Backend/LocalizationControllerTest.php @@ -9,7 +9,9 @@ use SBUERK\TYPO3\Testing\SiteHandling\SiteBasedTestTrait; use SBUERK\TYPO3\Testing\TestCase\FunctionalTestCase; use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Http\ServerRequest; use TYPO3\CMS\Core\Localization\LanguageService; +use TYPO3\CMS\Core\Localization\LanguageServiceFactory; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\GeneralUtility; use WebVision\Deepl\Base\Controller\Backend\LocalizationController; @@ -52,12 +54,12 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo 'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate', 'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate', 'icon' => 'actions-localize', - 'before' => ['copy'], + 'before' => ['copyFromLanguage'], 'after' => [], 'restrictedSourceLanguageIds' => null, ], [ - 'identifier' => 'copy', + 'identifier' => 'copyFromLanguage', 'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy', 'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy', 'icon' => 'actions-edit-copy', @@ -79,12 +81,12 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo 'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate', 'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate', 'icon' => 'actions-localize', - 'before' => ['copy'], + 'before' => ['copyFromLanguage'], 'after' => [], 'restrictedSourceLanguageIds' => null, ], [ - 'identifier' => 'copy', + 'identifier' => 'copyFromLanguage', 'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy', 'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy', 'icon' => 'actions-edit-copy', @@ -114,7 +116,7 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo 'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate', 'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate', 'icon' => 'actions-localize', - 'before' => ['copy'], + 'before' => ['copyFromLanguage'], 'after' => [], 'restrictedSourceLanguageIds' => null, ], @@ -128,7 +130,7 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo 'expectedModesJsonString' => \json_encode( [ [ - 'identifier' => 'copy', + 'identifier' => 'copyFromLanguage', 'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy', 'description' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy', 'icon' => 'actions-edit-copy', @@ -187,6 +189,69 @@ public function dispatchGetLocalizationModesEventReturnsExpectedDefaultModesBase $this->assertSame($expectedModesJsonString, \json_encode($modes, JSON_THROW_ON_ERROR)); } + public static function translationModesDataProvider(): \Generator + { + yield 'Translation mode "localize" works' => [ + 'getParams' => [ + 'pageId' => 3, + 'srcLanguageId' => 0, + 'destLanguageId' => 1, + 'action' => 'localize', + 'uidList' => [1], + ], + 'expectedFixture' => __DIR__ . '/Fixtures/TranslationModes/Result/localize.csv', + ]; + yield 'Translation mode "copy" works' => [ + 'getParams' => [ + 'pageId' => 3, + 'srcLanguageId' => 0, + 'destLanguageId' => 1, + 'action' => 'copyFromLanguage', + 'uidList' => [1], + ], + 'expectedFixture' => __DIR__ . '/Fixtures/TranslationModes/Result/copyToLanguage.csv', + ]; + } + + /** + * @param array{ + * pageId: int, + * srcLanguageId: int, + * destLanguageId: int, + * action: string, + * uidList: int[] + * } $getParams + */ + #[DataProvider('translationModesDataProvider')] + #[Test] + public function translationModesWorkAsExpected( + array $getParams, + string $expectedFixture + ): void { + $this->importCSVDataSet(__DIR__ . '/Fixtures/TranslationModes/TranslationModeSetup.csv'); + $this->writeSiteConfiguration( + identifier: 'acme', + site: $this->buildSiteConfiguration( + rootPageId: 1, + ), + languages: [ + $this->buildDefaultLanguageConfiguration('EN', '/'), + $this->buildLanguageConfiguration('EN', '/eb/', ['EN'], 'strict'), + $this->buildLanguageConfiguration('DE', '/de/', ['DE'], 'strict'), + $this->buildLanguageConfiguration('FR', '/fr/', ['FR'], 'strict'), + ], + ); + $this->setUpFrontendRootPage(1, [], []); + $beUser = $this->setUpBackendUser(1); + $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class) + ->createFromUserPreferences($beUser); + $request = (new ServerRequest('http://localhost/typo3/ajax/records/localize/process')) + ->withQueryParams($getParams); + $response = $this->createSubject()->localizeRecords($request); + $this->assertSame(200, $response->getStatusCode()); + $this->assertCSVDataSet($expectedFixture); + } + private function createSubject(): LocalizationController { return $this->get(LocalizationController::class);