[BUGFIX] Adapt a couple of broken test file namespaces
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Service / TranslationServiceTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Form\Tests\Unit\Service;
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
18 use Prophecy\Argument;
19 use TYPO3\CMS\Core\Cache\CacheManager;
20 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
21 use TYPO3\CMS\Core\Localization\LanguageService;
22 use TYPO3\CMS\Core\Localization\LanguageStore;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
25 use TYPO3\CMS\Form\Domain\Model\FormElements\GenericFormElement;
26 use TYPO3\CMS\Form\Domain\Model\FormElements\Page;
27 use TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface;
28 use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
29 use TYPO3\CMS\Form\Service\TranslationService;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31
32 /**
33 * Test case
34 */
35 class TranslationServiceTest extends UnitTestCase
36 {
37 /**
38 * @var array A backup of registered singleton instances
39 */
40 protected $singletonInstances = [];
41
42 /**
43 * @var ConfigurationManager
44 */
45 protected $mockConfigurationManager;
46
47 /**
48 * @var TranslationService
49 */
50 protected $mockTranslationService;
51
52 /**
53 * @var LanguageStore
54 */
55 protected $store;
56
57 /**
58 * Set up
59 */
60 public function setUp()
61 {
62 $this->singletonInstances = GeneralUtility::getSingletonInstances();
63
64 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
65 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
66 $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
67 $cacheManagerProphecy->getCache('l10n')->willReturn($cacheFrontendProphecy->reveal());
68 $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
69 $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
70
71 $this->mockConfigurationManager = $this->getAccessibleMock(ConfigurationManager::class, [
72 'getConfiguration'
73 ], [], '', false);
74
75 $this->mockTranslationService = $this->getAccessibleMock(TranslationService::class, [
76 'getConfigurationManager',
77 'getLanguageService'
78 ], [], '', false);
79
80 $this->mockTranslationService
81 ->expects($this->any())
82 ->method('getLanguageService')
83 ->willReturn(GeneralUtility::makeInstance(LanguageService::class));
84
85 $this->mockTranslationService
86 ->expects($this->any())
87 ->method('getConfigurationManager')
88 ->willReturn($this->mockConfigurationManager);
89
90 $this->store = GeneralUtility::makeInstance(LanguageStore::class);
91 $this->store->initialize();
92 }
93
94 /**
95 * Tear down
96 */
97 public function tearDown(): void
98 {
99 GeneralUtility::resetSingletonInstances($this->singletonInstances);
100 parent::tearDown();
101 }
102
103 /**
104 * @test
105 */
106 public function translateReturnsExistingDefaultLanguageKeyIfFullExtDefaultLanguageKeyIsRequested(): void
107 {
108 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
109 $expected = 'FORM EN';
110
111 $this->store->flushData($xlfPath);
112 $this->assertEquals($expected, $this->mockTranslationService->_call(
113 'translate',
114 $xlfPath . ':element.Page.renderingOptions.nextButtonLabel'
115 ));
116 }
117
118 /**
119 * @test
120 */
121 public function translateReturnsExistingDefaultLanguageKeyIfFullLLLExtDefaultLanguageKeyIsRequested(): void
122 {
123 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
124 $expected = 'FORM EN';
125
126 $this->store->flushData($xlfPath);
127 $this->assertEquals($expected, $this->mockTranslationService->_call(
128 'translate',
129 'LLL:' . $xlfPath . ':element.Page.renderingOptions.nextButtonLabel'
130 ));
131 }
132
133 /**
134 * @test
135 */
136 public function translateReturnsExistingDefaultLanguageKeyIfDefaultLanguageKeyIsRequestedAndDefaultValueIsGiven(): void
137 {
138 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
139 $expected = 'FORM EN';
140
141 $this->store->flushData($xlfPath);
142 $this->assertEquals($expected, $this->mockTranslationService->_call(
143 'translate',
144 $xlfPath . ':element.Page.renderingOptions.nextButtonLabel',
145 null,
146 null,
147 null,
148 'defaultValue'
149 ));
150 }
151
152 /**
153 * @test
154 */
155 public function translateReturnsEmptyStringIfNonExistingDefaultLanguageKeyIsRequested(): void
156 {
157 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
158 $this->store->flushData($xlfPath);
159
160 $expected = '';
161 $this->assertEquals($expected, $this->mockTranslationService->_call(
162 'translate',
163 $xlfPath . ':element.Page.renderingOptions.nonExisting'
164 ));
165 }
166
167 /**
168 * @test
169 */
170 public function translateReturnsDefaultValueIfNonExistingDefaultLanguageKeyIsRequestedAndDefaultValueIsGiven(): void
171 {
172 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
173 $this->store->flushData($xlfPath);
174
175 $expected = 'defaultValue';
176 $this->assertEquals($expected, $this->mockTranslationService->_call(
177 'translate',
178 $xlfPath . ':element.Page.renderingOptions.nonExisting',
179 null,
180 null,
181 null,
182 'defaultValue'
183 ));
184 }
185
186 /**
187 * @test
188 */
189 public function translateReturnsExistingLanguageKeyForLanguageIfExtPathLanguageKeyIsRequested(): void
190 {
191 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
192 $expected = 'FORM DE';
193
194 $this->store->flushData($xlfPath);
195 $this->assertEquals($expected, $this->mockTranslationService->_call(
196 'translate',
197 $xlfPath . ':element.Page.renderingOptions.nextButtonLabel',
198 null,
199 null,
200 'de'
201 ));
202 }
203
204 /**
205 * @test
206 */
207 public function translateReturnsDefaultValueIfNonExistingLanguageKeyForLanguageIsRequestedAndDefaultValueIsGiven(): void
208 {
209 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
210 $expected = 'defaultValue';
211
212 $this->store->flushData($xlfPath);
213 $this->assertEquals($expected, $this->mockTranslationService->_call(
214 'translate',
215 $xlfPath . ':element.Page.renderingOptions.nonExisting',
216 null,
217 null,
218 'de',
219 'defaultValue'
220 ));
221 }
222
223 /**
224 * @test
225 */
226 public function translateReturnsEmptyStringIfNonExistingLanguageKeyForLanguageIsRequested(): void
227 {
228 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
229 $expected = '';
230
231 $this->store->flushData($xlfPath);
232 $this->assertEquals($expected, $this->mockTranslationService->_call(
233 'translate',
234 $xlfPath . ':element.Page.renderingOptions.nonExisting',
235 null,
236 null,
237 'de'
238 ));
239 }
240
241 /**
242 * @test
243 */
244 public function translateReturnsExistingDefaultLanguageKeyIfDefaultLanguageKeyIsRequestedAndExtFilePathIsGiven(): void
245 {
246 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
247 $expected = 'FORM EN';
248
249 $this->store->flushData($xlfPath);
250 $this->assertEquals($expected, $this->mockTranslationService->_call(
251 'translate',
252 'element.Page.renderingOptions.nextButtonLabel',
253 null,
254 $xlfPath
255 ));
256 }
257
258 /**
259 * @test
260 */
261 public function translateReturnsExistingDefaultLanguageKeyIfDefaultLanguageKeyIsRequestedAndLLLExtFilePathIsGiven(): void
262 {
263 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
264 $expected = 'FORM EN';
265
266 $this->store->flushData($xlfPath);
267 $this->assertEquals($expected, $this->mockTranslationService->_call(
268 'translate',
269 'element.Page.renderingOptions.nextButtonLabel',
270 null,
271 'LLL:' . $xlfPath
272 ));
273 }
274
275 /**
276 * @test
277 */
278 public function translateValuesRecursiveTranslateRecursive(): void
279 {
280 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
281
282 $input = [
283 'Stan' => [
284 'Steve' => 'Roger'
285 ],
286 [
287 'Francine' => [
288 'Klaus' => 'element.Page.renderingOptions.nextButtonLabel'
289 ],
290 ],
291 ];
292
293 $expected = [
294 'Stan' => [
295 'Steve' => 'Roger'
296 ],
297 [
298 'Francine' => [
299 'Klaus' => 'FORM EN'
300 ],
301 ],
302 ];
303
304 $this->store->flushData($xlfPath);
305 $this->assertEquals($expected, $this->mockTranslationService->_call(
306 'translateValuesRecursive',
307 $input,
308 $xlfPath
309 ));
310 }
311
312 /**
313 * @test
314 */
315 public function translateFormElementValueTranslateLabelForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
316 {
317 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
318 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
319
320 $formRuntimeIdentifier = 'form-runtime-identifier';
321 $formElementIdentifier = 'form-element-identifier';
322
323 $formRuntimeRenderingOptions = [
324 'translation' => [
325 'translationFile' => $formRuntimeXlfPath,
326 'translatePropertyValueIfEmpty' => true
327 ],
328 ];
329
330 $formElementRenderingOptions = [
331 'translation' => [
332 'translationFile' => $textElementXlfPath,
333 'translatePropertyValueIfEmpty' => true
334 ],
335 ];
336
337 $expected = 'form-element-identifier LABEL EN';
338
339 $this->store->flushData($formRuntimeXlfPath);
340 $this->store->flushData($textElementXlfPath);
341
342 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
343
344 $mockFormElement->_set('type', 'Text');
345 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
346 $mockFormElement->_set('identifier', $formElementIdentifier);
347 $mockFormElement->_set('label', 'some label');
348
349 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
350 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
351 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
352
353 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
354 }
355
356 /**
357 * @test
358 */
359 public function translateFormElementValueTranslateLabelForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
360 {
361 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
362 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
363
364 $formRuntimeIdentifier = 'form-runtime-identifier';
365 $formElementIdentifier = 'form-element-identifier';
366
367 $formRuntimeRenderingOptions = [
368 'translation' => [
369 'translationFile' => $formRuntimeXlfPath,
370 'translatePropertyValueIfEmpty' => true
371 ],
372 ];
373
374 $formElementRenderingOptions = [
375 'translation' => [
376 'translationFile' => $textElementXlfPath,
377 'translatePropertyValueIfEmpty' => true
378 ],
379 ];
380
381 $expected = 'form-element-identifier LABEL EN';
382
383 $this->store->flushData($formRuntimeXlfPath);
384 $this->store->flushData($textElementXlfPath);
385
386 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
387
388 $mockFormElement->_set('type', 'Text');
389 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
390 $mockFormElement->_set('identifier', $formElementIdentifier);
391 $mockFormElement->_set('label', '');
392
393 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
394 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
395 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
396
397 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
398 }
399
400 /**
401 * @test
402 */
403 public function translateFormElementValueNotTranslateLabelForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsEmptyAndPropertyShouldNotBeTranslatedAndTranslationExists(): void
404 {
405 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
406 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
407
408 $formRuntimeIdentifier = 'form-runtime-identifier';
409 $formElementIdentifier = 'form-element-identifier';
410
411 $formRuntimeRenderingOptions = [
412 'translation' => [
413 'translationFile' => $formRuntimeXlfPath,
414 'translatePropertyValueIfEmpty' => true
415 ],
416 ];
417
418 $formElementRenderingOptions = [
419 'translation' => [
420 'translationFile' => $textElementXlfPath,
421 'translatePropertyValueIfEmpty' => false
422 ],
423 ];
424
425 $expected = '';
426
427 $this->store->flushData($formRuntimeXlfPath);
428 $this->store->flushData($textElementXlfPath);
429
430 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
431
432 $mockFormElement->_set('type', 'Text');
433 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
434 $mockFormElement->_set('identifier', $formElementIdentifier);
435 $mockFormElement->_set('label', '');
436
437 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
438 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
439 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
440
441 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
442 }
443
444 /**
445 * @test
446 */
447 public function translateFormElementValueTranslateLabelForConcreteFormElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
448 {
449 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
450 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
451
452 $formRuntimeIdentifier = 'another-form-runtime-identifier';
453 $formElementIdentifier = 'form-element-identifier';
454
455 $formRuntimeRenderingOptions = [
456 'translation' => [
457 'translationFile' => $formRuntimeXlfPath,
458 'translatePropertyValueIfEmpty' => true
459 ],
460 ];
461
462 $formElementRenderingOptions = [
463 'translation' => [
464 'translationFile' => $textElementXlfPath,
465 'translatePropertyValueIfEmpty' => true
466 ],
467 ];
468
469 $expected = 'form-element-identifier LABEL EN 1';
470
471 $this->store->flushData($formRuntimeXlfPath);
472 $this->store->flushData($textElementXlfPath);
473
474 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
475
476 $mockFormElement->_set('type', 'Text');
477 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
478 $mockFormElement->_set('identifier', $formElementIdentifier);
479 $mockFormElement->_set('label', 'some label');
480
481 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
482 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
483 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
484
485 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
486 }
487
488 /**
489 * @test
490 */
491 public function translateFormElementValueTranslateLabelForFormElementTypeIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
492 {
493 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
494 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
495
496 $formRuntimeIdentifier = 'another-form-runtime-identifier';
497 $formElementIdentifier = 'another-form-element-identifier';
498
499 $formRuntimeRenderingOptions = [
500 'translation' => [
501 'translationFile' => $formRuntimeXlfPath,
502 'translatePropertyValueIfEmpty' => true
503 ],
504 ];
505
506 $formElementRenderingOptions = [
507 'translation' => [
508 'translationFile' => $textElementXlfPath,
509 'translatePropertyValueIfEmpty' => true
510 ],
511 ];
512
513 $expected = 'form-element-identifier LABEL EN 2';
514
515 $this->store->flushData($formRuntimeXlfPath);
516 $this->store->flushData($textElementXlfPath);
517
518 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
519
520 $mockFormElement->_set('type', 'Text');
521 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
522 $mockFormElement->_set('identifier', $formElementIdentifier);
523 $mockFormElement->_set('label', 'some label');
524
525 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
526 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
527 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
528
529 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
530 }
531
532 /**
533 * @test
534 */
535 public function translateFormElementValueTranslatePropertyForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementPropertyIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
536 {
537 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
538 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
539
540 $formRuntimeIdentifier = 'form-runtime-identifier';
541 $formElementIdentifier = 'form-element-identifier';
542
543 $formRuntimeRenderingOptions = [
544 'translation' => [
545 'translationFile' => $formRuntimeXlfPath,
546 'translatePropertyValueIfEmpty' => true
547 ],
548 ];
549
550 $formElementRenderingOptions = [
551 'translation' => [
552 'translationFile' => $textElementXlfPath,
553 'translatePropertyValueIfEmpty' => true
554 ],
555 ];
556 $formElementProperties = [
557 'placeholder' => 'placeholder',
558 ];
559
560 $expected = 'form-element-identifier PLACEHOLDER EN';
561
562 $this->store->flushData($formRuntimeXlfPath);
563 $this->store->flushData($textElementXlfPath);
564
565 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
566
567 $mockFormElement->_set('type', 'Text');
568 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
569 $mockFormElement->_set('identifier', $formElementIdentifier);
570 $mockFormElement->_set('properties', $formElementProperties);
571
572 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
573 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
574 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
575
576 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['placeholder'], $mockFormRuntime));
577 }
578
579 /**
580 * @test
581 */
582 public function translateFormElementValueNotTranslatePropertyForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementPropertyIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationNotExists(): void
583 {
584 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
585 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
586
587 $formRuntimeIdentifier = 'another-form-runtime-identifier';
588 $formElementIdentifier = 'another-form-element-identifier';
589
590 $formRuntimeRenderingOptions = [
591 'translation' => [
592 'translationFile' => $formRuntimeXlfPath,
593 'translatePropertyValueIfEmpty' => true
594 ],
595 ];
596
597 $formElementRenderingOptions = [
598 'translation' => [
599 'translationFile' => $textElementXlfPath,
600 'translatePropertyValueIfEmpty' => true
601 ],
602 ];
603 $formElementProperties = [
604 'placeholder' => 'placeholder',
605 ];
606
607 $expected = 'placeholder';
608
609 $this->store->flushData($formRuntimeXlfPath);
610 $this->store->flushData($textElementXlfPath);
611
612 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
613
614 $mockFormElement->_set('type', 'Text');
615 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
616 $mockFormElement->_set('identifier', $formElementIdentifier);
617 $mockFormElement->_set('properties', $formElementProperties);
618
619 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
620 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
621 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
622
623 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['placeholder'], $mockFormRuntime));
624 }
625
626 /**
627 * @test
628 */
629 public function translateFormElementValueTranslateRenderingOptionForConcreteFormAndConcreteSectionElementIfElementRenderingOptionsContainsATranslationFileAndElementRenderingOptionIsNotEmptyAndRenderingOptionShouldBeTranslatedAndTranslationExists(): void
630 {
631 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
632 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
633
634 $formRuntimeIdentifier = 'form-runtime-identifier';
635 $formElementIdentifier = 'form-element-identifier-page';
636
637 $formRuntimeRenderingOptions = [
638 'translation' => [
639 'translationFile' => $formRuntimeXlfPath,
640 'translatePropertyValueIfEmpty' => true
641 ],
642 ];
643
644 $formElementRenderingOptions = [
645 'nextButtonLabel' => 'next button label',
646 'translation' => [
647 'translationFile' => $textElementXlfPath,
648 'translatePropertyValueIfEmpty' => true
649 ],
650 ];
651 $formElementProperties = [
652 'placeholder' => 'placeholder',
653 ];
654
655 $expected = 'form-element-identifier nextButtonLabel EN';
656
657 $this->store->flushData($formRuntimeXlfPath);
658 $this->store->flushData($textElementXlfPath);
659
660 $mockFormElement = $this->getAccessibleMock(Page::class, ['dummy'], [], '', false);
661
662 $mockFormElement->_set('type', 'Page');
663 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
664 $mockFormElement->_set('identifier', $formElementIdentifier);
665 $mockFormElement->_set('properties', $formElementProperties);
666
667 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
668 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
669 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
670
671 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['nextButtonLabel'], $mockFormRuntime));
672 }
673
674 /**
675 * @test
676 */
677 public function translateFormElementValueTranslateOptionsPropertyForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementOptionsPropertyIsAnArrayAndPropertyShouldBeTranslatedAndTranslationExists(): void
678 {
679 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
680 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
681
682 $formRuntimeIdentifier = 'form-runtime-identifier';
683 $formElementIdentifier = 'options-form-element-identifier';
684
685 $formRuntimeRenderingOptions = [
686 'translation' => [
687 'translationFile' => $formRuntimeXlfPath,
688 'translatePropertyValueIfEmpty' => true
689 ],
690 ];
691
692 $formElementRenderingOptions = [
693 'translation' => [
694 'translationFile' => $textElementXlfPath,
695 'translatePropertyValueIfEmpty' => true
696 ],
697 ];
698 $formElementProperties = [
699 'options' => [
700 'optionValue1' => 'optionLabel1',
701 'optionValue2' => 'optionLabel2'
702 ],
703 ];
704
705 $expected = [
706 'optionValue1' => 'options-form-element-identifier option 1 EN',
707 'optionValue2' => 'options-form-element-identifier option 2 EN'
708 ];
709
710 $this->store->flushData($formRuntimeXlfPath);
711 $this->store->flushData($textElementXlfPath);
712
713 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
714
715 $mockFormElement->_set('type', 'Text');
716 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
717 $mockFormElement->_set('identifier', $formElementIdentifier);
718 $mockFormElement->_set('properties', $formElementProperties);
719
720 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
721 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
722 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
723
724 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['options'], $mockFormRuntime));
725 }
726
727 /**
728 * @test
729 */
730 public function translateFormElementValueTranslateOptionsPropertyForConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementOptionsPropertyIsAnArrayAndPropertyShouldBeTranslatedAndTranslationExists(): void
731 {
732 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
733 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
734
735 $formRuntimeIdentifier = 'another-form-runtime-identifier';
736 $formElementIdentifier = 'options-form-element-identifier';
737
738 $formRuntimeRenderingOptions = [
739 'translation' => [
740 'translationFile' => $formRuntimeXlfPath,
741 'translatePropertyValueIfEmpty' => true
742 ],
743 ];
744
745 $formElementRenderingOptions = [
746 'translation' => [
747 'translationFile' => $textElementXlfPath,
748 'translatePropertyValueIfEmpty' => true
749 ],
750 ];
751 $formElementProperties = [
752 'options' => [
753 'optionValue1' => 'optionLabel1',
754 'optionValue2' => 'optionLabel2'
755 ],
756 ];
757
758 $expected = [
759 'optionValue1' => 'options-form-element-identifier option 1 EN',
760 'optionValue2' => 'options-form-element-identifier option 2 EN'
761 ];
762
763 $this->store->flushData($formRuntimeXlfPath);
764 $this->store->flushData($textElementXlfPath);
765
766 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
767
768 $mockFormElement->_set('type', 'Text');
769 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
770 $mockFormElement->_set('identifier', $formElementIdentifier);
771 $mockFormElement->_set('properties', $formElementProperties);
772
773 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
774 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
775 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
776
777 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['options'], $mockFormRuntime));
778 }
779
780 /**
781 * @test
782 */
783 public function translateFinisherOptionTranslateOptionForConcreteFormIfFinisherTranslationOptionsContainsATranslationFileAndFinisherOptionIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
784 {
785 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
786 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
787
788 $formRuntimeIdentifier = 'form-runtime-identifier';
789 $finisherIdentifier = 'SaveToDatabaseFinisher';
790
791 $formRuntimeRenderingOptions = [
792 'translation' => [
793 'translationFile' => $formRuntimeXlfPath,
794 'translatePropertyValueIfEmpty' => true
795 ],
796 ];
797
798 $finisherRenderingOptions = [
799 'translationFile' => $textElementXlfPath,
800 'translatePropertyValueIfEmpty' => true
801 ];
802
803 $expected = 'form-element-identifier SaveToDatabase subject EN';
804
805 $this->store->flushData($formRuntimeXlfPath);
806 $this->store->flushData($textElementXlfPath);
807
808 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
809 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
810 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
811
812 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, $finisherIdentifier, 'subject', 'subject value', $finisherRenderingOptions));
813 }
814
815 /**
816 * @test
817 */
818 public function translateFinisherOptionTranslateOptionIfFinisherTranslationOptionsContainsATranslationFileAndFinisherOptionIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
819 {
820 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
821 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
822
823 $formRuntimeIdentifier = 'another-form-runtime-identifier';
824 $finisherIdentifier = 'SaveToDatabaseFinisher';
825
826 $formRuntimeRenderingOptions = [
827 'translation' => [
828 'translationFile' => $formRuntimeXlfPath,
829 'translatePropertyValueIfEmpty' => true
830 ],
831 ];
832
833 $finisherRenderingOptions = [
834 'translationFile' => $textElementXlfPath,
835 'translatePropertyValueIfEmpty' => true
836 ];
837
838 $expected = 'form-element-identifier SaveToDatabase subject EN 1';
839
840 $this->store->flushData($formRuntimeXlfPath);
841 $this->store->flushData($textElementXlfPath);
842
843 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
844 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
845 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
846
847 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, $finisherIdentifier, 'subject', 'subject value', $finisherRenderingOptions));
848 }
849
850 /**
851 * @test
852 */
853 public function translateFormElementValueTranslateLabelForConcreteFormAndConcreteElementFromFormRumtimeTranslationFileIfElementRenderingOptionsContainsNoTranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
854 {
855 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
856 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
857
858 $formRuntimeIdentifier = 'my-form-runtime-identifier';
859 $formElementIdentifier = 'my-form-element-identifier';
860
861 $formRuntimeRenderingOptions = [
862 'translation' => [
863 'translationFile' => $formRuntimeXlfPath,
864 'translatePropertyValueIfEmpty' => true
865 ],
866 ];
867
868 $formElementRenderingOptions = [];
869
870 $expected = 'my-form-runtime-identifier my-form-element-identifier LABEL EN';
871
872 $this->store->flushData($formRuntimeXlfPath);
873 $this->store->flushData($textElementXlfPath);
874
875 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
876
877 $mockFormElement->_set('type', 'Text');
878 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
879 $mockFormElement->_set('identifier', $formElementIdentifier);
880 $mockFormElement->_set('label', 'some label');
881
882 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
883 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
884 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
885
886 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
887 }
888
889 /**
890 * @test
891 */
892 public function supportsArgumentsForFormElementValueTranslations(): void
893 {
894 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
895
896 $this->store->flushData($formRuntimeXlfPath);
897
898 /** @var FormRuntime|\Prophecy\Prophecy\ObjectProphecy */
899 $formRuntime = $this->prophesize(FormRuntime::class);
900 $formRuntime->getIdentifier()->willReturn('my-form-runtime-identifier');
901 $formRuntime->getRenderingOptions()->willReturn([
902 'translation' => [
903 'translationFile' => $formRuntimeXlfPath,
904 'translatePropertyValueIfEmpty' => true,
905 ],
906 ]);
907
908 /** @var RootRenderableInterface|\Prophecy\Prophecy\ObjectProphecy */
909 $element = $this->prophesize(RootRenderableInterface::class);
910 $element->getIdentifier()->willReturn('my-form-element-with-translation-arguments');
911 $element->getType()->willReturn(RootRenderableInterface::class);
912 $element->getLabel()->willReturn('See %s or %s');
913 $element->getRenderingOptions()->willReturn([
914 'translation' => [
915 'arguments' => [
916 'label' => [
917 'this',
918 'that',
919 ],
920 ],
921 ],
922 ]);
923
924 $expected = 'See this or that';
925 $result = $this->mockTranslationService->_call('translateFormElementValue', $element->reveal(), ['label'], $formRuntime->reveal());
926
927 $this->assertEquals($expected, $result);
928 }
929
930 /**
931 * @test
932 */
933 public function translateFinisherOptionTranslateOptionForConcreteFormFromFormRuntimeIfFinisherTranslationOptionsContainsNoTranslationFileAndFinisherOptionIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
934 {
935 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
936 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
937
938 $formRuntimeIdentifier = 'my-form-runtime-identifier';
939 $finisherIdentifier = 'SaveToDatabaseFinisher';
940
941 $formRuntimeRenderingOptions = [
942 'translation' => [
943 'translationFile' => $formRuntimeXlfPath,
944 'translatePropertyValueIfEmpty' => true
945 ],
946 ];
947
948 $finisherRenderingOptions = [];
949
950 $expected = 'my-form-runtime-identifier form-element-identifier SaveToDatabase subject EN';
951
952 $this->store->flushData($formRuntimeXlfPath);
953 $this->store->flushData($textElementXlfPath);
954
955 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
956 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
957 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
958
959 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, $finisherIdentifier, 'subject', 'subject value', $finisherRenderingOptions));
960 }
961
962 /**
963 * @test
964 */
965 public function supportsArgumentsForFinisherOptionTranslations(): void
966 {
967 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
968
969 $this->store->flushData($formRuntimeXlfPath);
970
971 /** @var FormRuntime|\Prophecy\Prophecy\ObjectProphecy */
972 $formRuntime = $this->prophesize(FormRuntime::class);
973 $formRuntime->getIdentifier()->willReturn('my-form-runtime-identifier');
974 $formRuntime->getRenderingOptions()->willReturn([
975 'translation' => [
976 'translationFile' => $formRuntimeXlfPath,
977 'translatePropertyValueIfEmpty' => true,
978 ],
979 ]);
980 $renderingOptions = [
981 'arguments' => [
982 'subject' => [
983 'awesome',
984 ],
985 ],
986 ];
987
988 $expected = 'My awesome subject';
989 $result = $this->mockTranslationService->_call('translateFinisherOption', $formRuntime->reveal(), 'EmailToReceiverWithTranslationArguments', 'subject', 'My %s subject', $renderingOptions);
990
991 $this->assertEquals($expected, $result);
992 }
993
994 /**
995 * @test
996 */
997 public function translateFormElementValueTranslateLabelFromAdditionalTranslationForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists(): void
998 {
999 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
1000 $textElementXlfPaths = [
1001 10 => 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf',
1002 20 => 'EXT:form/Tests/Unit/Service/Fixtures/locallang_additional_text.xlf'
1003 ];
1004
1005 $formRuntimeIdentifier = 'form-runtime-identifier';
1006 $formElementIdentifier = 'form-element-identifier';
1007
1008 $formRuntimeRenderingOptions = [
1009 'translation' => [
1010 'translationFile' => $formRuntimeXlfPath,
1011 'translatePropertyValueIfEmpty' => true
1012 ],
1013 ];
1014
1015 $formElementRenderingOptions = [
1016 'translation' => [
1017 'translationFile' => $textElementXlfPaths,
1018 'translatePropertyValueIfEmpty' => true
1019 ],
1020 ];
1021
1022 $expected = 'form-element-identifier ADDITIONAL LABEL EN';
1023
1024 $this->store->flushData($formRuntimeXlfPath);
1025
1026 foreach ($textElementXlfPaths as $textElementXlfPath) {
1027 $this->store->flushData($textElementXlfPath);
1028 }
1029
1030 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
1031
1032 $mockFormElement->_set('type', 'Text');
1033 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
1034 $mockFormElement->_set('identifier', $formElementIdentifier);
1035 $mockFormElement->_set('label', 'some label');
1036
1037 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
1038 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
1039 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
1040
1041 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
1042 }
1043
1044 /**
1045 * @test
1046 */
1047 public function translateFormElementTranslateFormWithContentElementUidIfFormContainsNoOriginalIdentifier(): void
1048 {
1049 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_01.xlf';
1050
1051 $formRuntimeIdentifier = 'form-runtime-identifier-42';
1052 $formElementIdentifier = 'form-element-identifier';
1053
1054 $formRuntimeRenderingOptions = [
1055 'submitButtonLabel' => '',
1056 'translation' => [
1057 'translationFile' => $formRuntimeXlfPath,
1058 'translatePropertyValueIfEmpty' => true
1059 ],
1060 ];
1061
1062 $this->store->flushData($formRuntimeXlfPath);
1063
1064 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions', 'getType'], [], '', false);
1065
1066 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
1067 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
1068 $mockFormRuntime->expects($this->any())->method('getType')->willReturn('Form');
1069
1070 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
1071
1072 $mockFormElement->_set('type', 'Text');
1073 $mockFormElement->_set('identifier', $formElementIdentifier);
1074 $mockFormElement->_set('label', '');
1075
1076 $expected = 'form-runtime-identifier-42 submitButtonLabel EN';
1077 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormRuntime, ['submitButtonLabel'], $mockFormRuntime));
1078
1079 $expected = 'form-runtime-identifier-42 form-element-identifierlabel EN';
1080 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
1081 }
1082
1083 /**
1084 * @test
1085 */
1086 public function translateFormElementTranslateFormWithContentElementUidIfFormContainsOriginalIdentifier(): void
1087 {
1088 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_02.xlf';
1089
1090 $formRuntimeIdentifier = 'form-runtime-identifier-42';
1091 $formElementIdentifier = 'form-element-identifier';
1092
1093 $formRuntimeRenderingOptions = [
1094 'submitButtonLabel' => '',
1095 '_originalIdentifier' => 'form-runtime-identifier',
1096 'translation' => [
1097 'translationFile' => $formRuntimeXlfPath,
1098 'translatePropertyValueIfEmpty' => true
1099 ],
1100 ];
1101
1102 $this->store->flushData($formRuntimeXlfPath);
1103
1104 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions', 'getType'], [], '', false);
1105
1106 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
1107 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
1108 $mockFormRuntime->expects($this->any())->method('getType')->willReturn('Form');
1109
1110 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
1111
1112 $mockFormElement->_set('type', 'Text');
1113 $mockFormElement->_set('identifier', $formElementIdentifier);
1114 $mockFormElement->_set('label', '');
1115
1116 $expected = 'form-runtime-identifier submitButtonLabel EN';
1117 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormRuntime, ['submitButtonLabel'], $mockFormRuntime));
1118
1119 $expected = 'form-runtime-identifier form-element-identifierlabel EN';
1120 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
1121 }
1122
1123 /**
1124 * @test
1125 */
1126 public function translateFormElementErrorTranslateErrorFromFormWithContentElementUidIfFormContainsNoOriginalIdentifier(): void
1127 {
1128 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_01.xlf';
1129
1130 $formRuntimeIdentifier = 'form-runtime-identifier-42';
1131 $formElementIdentifier = 'form-element-identifier';
1132
1133 $formRuntimeRenderingOptions = [
1134 'translation' => [
1135 'translationFile' => $formRuntimeXlfPath,
1136 'translatePropertyValueIfEmpty' => true
1137 ],
1138 ];
1139
1140 $this->store->flushData($formRuntimeXlfPath);
1141
1142 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions', 'getType', 'getProperties'], [], '', false);
1143
1144 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
1145 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
1146 $mockFormRuntime->expects($this->any())->method('getType')->willReturn('Form');
1147 $mockFormRuntime->expects($this->any())->method('getProperties')->willReturn([]);
1148
1149 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
1150
1151 $mockFormElement->_set('type', 'Text');
1152 $mockFormElement->_set('identifier', $formElementIdentifier);
1153 $mockFormElement->_set('label', '');
1154 $mockFormElement->_set('properties', []);
1155
1156 $expected = 'form-runtime-identifier-42 error 123 EN';
1157 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementError', $mockFormRuntime, 123, [], 'default value', $mockFormRuntime));
1158
1159 $expected = 'form-runtime-identifier-42 form-element-identifier error 123 EN';
1160 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementError', $mockFormElement, 123, [], 'default value', $mockFormRuntime));
1161 }
1162
1163 /**
1164 * @test
1165 */
1166 public function translateFormElementErrorTranslateErrorFromFormWithContentElementUidIfFormContainsOriginalIdentifier(): void
1167 {
1168 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_02.xlf';
1169
1170 $formRuntimeIdentifier = 'form-runtime-identifier-42';
1171 $formElementIdentifier = 'form-element-identifier';
1172
1173 $formRuntimeRenderingOptions = [
1174 '_originalIdentifier' => 'form-runtime-identifier',
1175 'translation' => [
1176 'translationFile' => $formRuntimeXlfPath,
1177 'translatePropertyValueIfEmpty' => true
1178 ],
1179 ];
1180
1181 $this->store->flushData($formRuntimeXlfPath);
1182
1183 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions', 'getType', 'getProperties'], [], '', false);
1184
1185 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
1186 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
1187 $mockFormRuntime->expects($this->any())->method('getType')->willReturn('Form');
1188 $mockFormRuntime->expects($this->any())->method('getProperties')->willReturn([]);
1189
1190 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
1191
1192 $mockFormElement->_set('type', 'Text');
1193 $mockFormElement->_set('identifier', $formElementIdentifier);
1194 $mockFormElement->_set('label', '');
1195 $mockFormElement->_set('properties', []);
1196
1197 $expected = 'form-runtime-identifier error 123 EN';
1198 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementError', $mockFormRuntime, 123, [], 'default value', $mockFormRuntime));
1199
1200 $expected = 'form-runtime-identifier form-element-identifier error 123 EN';
1201 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementError', $mockFormElement, 123, [], 'default value', $mockFormRuntime));
1202 }
1203
1204 /**
1205 * @test
1206 */
1207 public function translateFinisherOptionTranslateOptionFromFormWithContentElementUidIfFormContainsNoOriginalIdentifier(): void
1208 {
1209 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_01.xlf';
1210
1211 $formRuntimeIdentifier = 'form-runtime-identifier-42';
1212
1213 $formRuntimeRenderingOptions = [
1214 'translation' => [
1215 'translationFile' => $formRuntimeXlfPath,
1216 'translatePropertyValueIfEmpty' => true
1217 ],
1218 ];
1219
1220 $this->store->flushData($formRuntimeXlfPath);
1221
1222 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions', 'getType', 'getProperties'], [], '', false);
1223
1224 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
1225 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
1226 $mockFormRuntime->expects($this->any())->method('getType')->willReturn('Form');
1227 $mockFormRuntime->expects($this->any())->method('getProperties')->willReturn([]);
1228
1229 $expected = 'form-runtime-identifier-42 FooFinisher test EN';
1230 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, 'Foo', 'test', 'value', []));
1231 }
1232
1233 /**
1234 * @test
1235 */
1236 public function translateFinisherOptionTranslateOptionFromFormWithContentElementUidIfFormContainsOriginalIdentifier(): void
1237 {
1238 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_02.xlf';
1239
1240 $formRuntimeIdentifier = 'form-runtime-identifier-42';
1241
1242 $formRuntimeRenderingOptions = [
1243 '_originalIdentifier' => 'form-runtime-identifier',
1244 'translation' => [
1245 'translationFile' => $formRuntimeXlfPath,
1246 'translatePropertyValueIfEmpty' => true
1247 ],
1248 ];
1249
1250 $this->store->flushData($formRuntimeXlfPath);
1251
1252 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions', 'getType', 'getProperties'], [], '', false);
1253
1254 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
1255 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
1256 $mockFormRuntime->expects($this->any())->method('getType')->willReturn('Form');
1257 $mockFormRuntime->expects($this->any())->method('getProperties')->willReturn([]);
1258
1259 $expected = 'form-runtime-identifier FooFinisher test EN';
1260 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, 'Foo', 'test', 'value', []));
1261 }
1262 }