99use SBUERK \TYPO3 \Testing \SiteHandling \SiteBasedTestTrait ;
1010use SBUERK \TYPO3 \Testing \TestCase \FunctionalTestCase ;
1111use TYPO3 \CMS \Backend \Utility \BackendUtility ;
12+ use TYPO3 \CMS \Core \Http \ServerRequest ;
1213use TYPO3 \CMS \Core \Localization \LanguageService ;
14+ use TYPO3 \CMS \Core \Localization \LanguageServiceFactory ;
1315use TYPO3 \CMS \Core \Site \SiteFinder ;
1416use TYPO3 \CMS \Core \Utility \GeneralUtility ;
1517use WebVision \Deepl \Base \Controller \Backend \LocalizationController ;
@@ -52,12 +54,12 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
5254 'title ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate ' ,
5355 'description ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate ' ,
5456 'icon ' => 'actions-localize ' ,
55- 'before ' => ['copy ' ],
57+ 'before ' => ['copyFromLanguage ' ],
5658 'after ' => [],
5759 'restrictedSourceLanguageIds ' => null ,
5860 ],
5961 [
60- 'identifier ' => 'copy ' ,
62+ 'identifier ' => 'copyFromLanguage ' ,
6163 'title ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy ' ,
6264 'description ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy ' ,
6365 'icon ' => 'actions-edit-copy ' ,
@@ -79,12 +81,12 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
7981 'title ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate ' ,
8082 'description ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate ' ,
8183 'icon ' => 'actions-localize ' ,
82- 'before ' => ['copy ' ],
84+ 'before ' => ['copyFromLanguage ' ],
8385 'after ' => [],
8486 'restrictedSourceLanguageIds ' => null ,
8587 ],
8688 [
87- 'identifier ' => 'copy ' ,
89+ 'identifier ' => 'copyFromLanguage ' ,
8890 'title ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy ' ,
8991 'description ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy ' ,
9092 'icon ' => 'actions-edit-copy ' ,
@@ -114,7 +116,7 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
114116 'title ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.translate ' ,
115117 'description ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.translate ' ,
116118 'icon ' => 'actions-localize ' ,
117- 'before ' => ['copy ' ],
119+ 'before ' => ['copyFromLanguage ' ],
118120 'after ' => [],
119121 'restrictedSourceLanguageIds ' => null ,
120122 ],
@@ -128,7 +130,7 @@ public static function dispatchGetLocalizationModesEventReturnsExpectedDefaultMo
128130 'expectedModesJsonString ' => \json_encode (
129131 [
130132 [
131- 'identifier ' => 'copy ' ,
133+ 'identifier ' => 'copyFromLanguage ' ,
132134 'title ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.wizard.button.copy ' ,
133135 'description ' => 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:localize.educate.copy ' ,
134136 'icon ' => 'actions-edit-copy ' ,
@@ -187,6 +189,69 @@ public function dispatchGetLocalizationModesEventReturnsExpectedDefaultModesBase
187189 $ this ->assertSame ($ expectedModesJsonString , \json_encode ($ modes , JSON_THROW_ON_ERROR ));
188190 }
189191
192+ public static function translationModesDataProvider (): \Generator
193+ {
194+ yield 'Translation mode "localize" works ' => [
195+ 'getParams ' => [
196+ 'pageId ' => 3 ,
197+ 'srcLanguageId ' => 0 ,
198+ 'destLanguageId ' => 1 ,
199+ 'action ' => 'localize ' ,
200+ 'uidList ' => [1 ],
201+ ],
202+ 'expectedFixture ' => __DIR__ . '/Fixtures/TranslationModes/Result/localize.csv ' ,
203+ ];
204+ yield 'Translation mode "copy" works ' => [
205+ 'getParams ' => [
206+ 'pageId ' => 3 ,
207+ 'srcLanguageId ' => 0 ,
208+ 'destLanguageId ' => 1 ,
209+ 'action ' => 'copyFromLanguage ' ,
210+ 'uidList ' => [1 ],
211+ ],
212+ 'expectedFixture ' => __DIR__ . '/Fixtures/TranslationModes/Result/copyToLanguage.csv ' ,
213+ ];
214+ }
215+
216+ /**
217+ * @param array{
218+ * pageId: int,
219+ * srcLanguageId: int,
220+ * destLanguageId: int,
221+ * action: string,
222+ * uidList: int[]
223+ * } $getParams
224+ */
225+ #[DataProvider('translationModesDataProvider ' )]
226+ #[Test]
227+ public function translationModesWorkAsExpected (
228+ array $ getParams ,
229+ string $ expectedFixture
230+ ): void {
231+ $ this ->importCSVDataSet (__DIR__ . '/Fixtures/TranslationModes/TranslationModeSetup.csv ' );
232+ $ this ->writeSiteConfiguration (
233+ identifier: 'acme ' ,
234+ site: $ this ->buildSiteConfiguration (
235+ rootPageId: 1 ,
236+ ),
237+ languages: [
238+ $ this ->buildDefaultLanguageConfiguration ('EN ' , '/ ' ),
239+ $ this ->buildLanguageConfiguration ('EN ' , '/eb/ ' , ['EN ' ], 'strict ' ),
240+ $ this ->buildLanguageConfiguration ('DE ' , '/de/ ' , ['DE ' ], 'strict ' ),
241+ $ this ->buildLanguageConfiguration ('FR ' , '/fr/ ' , ['FR ' ], 'strict ' ),
242+ ],
243+ );
244+ $ this ->setUpFrontendRootPage (1 , [], []);
245+ $ beUser = $ this ->setUpBackendUser (1 );
246+ $ GLOBALS ['LANG ' ] = GeneralUtility::makeInstance (LanguageServiceFactory::class)
247+ ->createFromUserPreferences ($ beUser );
248+ $ request = (new ServerRequest ('http://localhost/typo3/ajax/records/localize/process ' ))
249+ ->withQueryParams ($ getParams );
250+ $ response = $ this ->createSubject ()->localizeRecords ($ request );
251+ $ this ->assertSame (200 , $ response ->getStatusCode ());
252+ $ this ->assertCSVDataSet ($ expectedFixture );
253+ }
254+
190255 private function createSubject (): LocalizationController
191256 {
192257 return $ this ->get (LocalizationController::class);
0 commit comments