[BUGFIX] Fix multi-checkbox/radiobox labels for values containing dots
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Service / TranslationServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Service;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Cache\CacheManager;
18 use TYPO3\CMS\Core\Localization\LanguageStore;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
21 use TYPO3\CMS\Form\Domain\Model\FormElements\GenericFormElement;
22 use TYPO3\CMS\Form\Domain\Model\FormElements\Page;
23 use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
24 use TYPO3\CMS\Form\Service\TranslationService;
25 use TYPO3\CMS\Lang\LanguageService;
26
27 /**
28 * Test case
29 */
30 class TranslationServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
31 {
32
33 /**
34 * @var array A backup of registered singleton instances
35 */
36 protected $singletonInstances = [];
37
38 /**
39 * @var ConfigurationManager
40 */
41 protected $mockConfigurationManager;
42
43 /**
44 * @var TranslationService
45 */
46 protected $mockTranslationService;
47
48 /**
49 * @var LanguageStore
50 */
51 protected $store;
52
53 /**
54 * Set up
55 */
56 public function setUp()
57 {
58 $this->mockConfigurationManager = $this->getAccessibleMock(ConfigurationManager::class, [
59 'getConfiguration'
60 ], [], '', false);
61
62 $this->mockTranslationService = $this->getAccessibleMock(TranslationService::class, [
63 'getConfigurationManager',
64 'getLanguageService'
65 ], [], '', false);
66
67 $this->mockTranslationService
68 ->expects($this->any())
69 ->method('getLanguageService')
70 ->willReturn(GeneralUtility::makeInstance(LanguageService::class));
71
72 $this->mockTranslationService
73 ->expects($this->any())
74 ->method('getConfigurationManager')
75 ->willReturn($this->mockConfigurationManager);
76
77 GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
78 $this->store = GeneralUtility::makeInstance(LanguageStore::class);
79 $this->store->initialize();
80
81 $this->singletonInstances = GeneralUtility::getSingletonInstances();
82 }
83
84 /**
85 * Tear down
86 */
87 public function tearDown()
88 {
89 GeneralUtility::resetSingletonInstances($this->singletonInstances);
90 parent::tearDown();
91 }
92
93 /**
94 * @test
95 */
96 public function translateReturnsExistingDefaultLanguageKeyIfFullExtDefaultLanguageKeyIsRequested()
97 {
98 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
99 $expected = 'FORM EN';
100
101 $this->store->flushData($xlfPath);
102 $this->assertEquals($expected, $this->mockTranslationService->_call(
103 'translate',
104 $xlfPath . ':element.Page.renderingOptions.nextButtonLabel'
105 ));
106 }
107
108 /**
109 * @test
110 */
111 public function translateReturnsExistingDefaultLanguageKeyIfFullLLLExtDefaultLanguageKeyIsRequested()
112 {
113 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
114 $expected = 'FORM EN';
115
116 $this->store->flushData($xlfPath);
117 $this->assertEquals($expected, $this->mockTranslationService->_call(
118 'translate',
119 'LLL:' . $xlfPath . ':element.Page.renderingOptions.nextButtonLabel'
120 ));
121 }
122
123 /**
124 * @test
125 */
126 public function translateReturnsExistingDefaultLanguageKeyIfDefaultLanguageKeyIsRequestedAndDefaultValueIsGiven()
127 {
128 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
129 $expected = 'FORM EN';
130
131 $this->store->flushData($xlfPath);
132 $this->assertEquals($expected, $this->mockTranslationService->_call(
133 'translate',
134 $xlfPath . ':element.Page.renderingOptions.nextButtonLabel',
135 null,
136 null,
137 null,
138 'defaultValue'
139 ));
140 }
141
142 /**
143 * @test
144 */
145 public function translateReturnsEmptyStringIfNonExistingDefaultLanguageKeyIsRequested()
146 {
147 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
148 $this->store->flushData($xlfPath);
149
150 $expected = '';
151 $this->assertEquals($expected, $this->mockTranslationService->_call(
152 'translate',
153 $xlfPath . ':element.Page.renderingOptions.nonExisting'
154 ));
155 }
156
157 /**
158 * @test
159 */
160 public function translateReturnsDefaultValueIfNonExistingDefaultLanguageKeyIsRequestedAndDefaultValueIsGiven()
161 {
162 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
163 $this->store->flushData($xlfPath);
164
165 $expected = 'defaultValue';
166 $this->assertEquals($expected, $this->mockTranslationService->_call(
167 'translate',
168 $xlfPath . ':element.Page.renderingOptions.nonExisting',
169 null,
170 null,
171 null,
172 'defaultValue'
173 ));
174 }
175
176 /**
177 * @test
178 */
179 public function translateReturnsExistingLanguageKeyForLanguageIfExtPathLanguageKeyIsRequested()
180 {
181 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
182 $expected = 'FORM DE';
183
184 $this->store->flushData($xlfPath);
185 $this->assertEquals($expected, $this->mockTranslationService->_call(
186 'translate',
187 $xlfPath . ':element.Page.renderingOptions.nextButtonLabel',
188 null,
189 null,
190 'de'
191 ));
192 }
193
194 /**
195 * @test
196 */
197 public function translateReturnsDefaultValueIfNonExistingLanguageKeyForLanguageIsRequestedAndDefaultValueIsGiven()
198 {
199 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
200 $expected = 'defaultValue';
201
202 $this->store->flushData($xlfPath);
203 $this->assertEquals($expected, $this->mockTranslationService->_call(
204 'translate',
205 $xlfPath . ':element.Page.renderingOptions.nonExisting',
206 null,
207 null,
208 'de',
209 'defaultValue'
210 ));
211 }
212
213 /**
214 * @test
215 */
216 public function translateReturnsEmptyStringIfNonExistingLanguageKeyForLanguageIsRequested()
217 {
218 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
219 $expected = '';
220
221 $this->store->flushData($xlfPath);
222 $this->assertEquals($expected, $this->mockTranslationService->_call(
223 'translate',
224 $xlfPath . ':element.Page.renderingOptions.nonExisting',
225 null,
226 null,
227 'de'
228 ));
229 }
230
231 /**
232 * @test
233 */
234 public function translateReturnsExistingDefaultLanguageKeyIfDefaultLanguageKeyIsRequestedAndExtFilePathIsGiven()
235 {
236 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
237 $expected = 'FORM EN';
238
239 $this->store->flushData($xlfPath);
240 $this->assertEquals($expected, $this->mockTranslationService->_call(
241 'translate',
242 'element.Page.renderingOptions.nextButtonLabel',
243 null,
244 $xlfPath
245 ));
246 }
247
248 /**
249 * @test
250 */
251 public function translateReturnsExistingDefaultLanguageKeyIfDefaultLanguageKeyIsRequestedAndLLLExtFilePathIsGiven()
252 {
253 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
254 $expected = 'FORM EN';
255
256 $this->store->flushData($xlfPath);
257 $this->assertEquals($expected, $this->mockTranslationService->_call(
258 'translate',
259 'element.Page.renderingOptions.nextButtonLabel',
260 null,
261 'LLL:' . $xlfPath
262 ));
263 }
264
265 /**
266 * @test
267 */
268 public function translateValuesRecursiveTranslateRecursive()
269 {
270 $xlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
271
272 $input = [
273 'Stan' => [
274 'Steve' => 'Roger'
275 ],
276 [
277 'Francine' => [
278 'Klaus' => 'element.Page.renderingOptions.nextButtonLabel'
279 ],
280 ],
281 ];
282
283 $expected = [
284 'Stan' => [
285 'Steve' => 'Roger'
286 ],
287 [
288 'Francine' => [
289 'Klaus' => 'FORM EN'
290 ],
291 ],
292 ];
293
294 $this->store->flushData($xlfPath);
295 $this->assertEquals($expected, $this->mockTranslationService->_call(
296 'translateValuesRecursive',
297 $input,
298 $xlfPath
299 ));
300 }
301
302 /**
303 * @test
304 */
305 public function translateFormElementValueTranslateLabelForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
306 {
307 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
308 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
309
310 $formRuntimeIdentifier = 'form-runtime-identifier';
311 $formElementIdentifier = 'form-element-identifier';
312
313 $formRuntimeRenderingOptions = [
314 'translation' => [
315 'translationFile' => $formRuntimeXlfPath,
316 'translatePropertyValueIfEmpty' => true
317 ],
318 ];
319
320 $formElementRenderingOptions = [
321 'translation' => [
322 'translationFile' => $textElementXlfPath,
323 'translatePropertyValueIfEmpty' => true
324 ],
325 ];
326
327 $expected = 'form-element-identifier LABEL EN';
328
329 $this->store->flushData($formRuntimeXlfPath);
330 $this->store->flushData($textElementXlfPath);
331
332 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
333
334 $mockFormElement->_set('type', 'Text');
335 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
336 $mockFormElement->_set('identifier', $formElementIdentifier);
337 $mockFormElement->_set('label', 'some label');
338
339 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
340 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
341 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
342
343 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
344 }
345
346 /**
347 * @test
348 */
349 public function translateFormElementValueTranslateLabelForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
350 {
351 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
352 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
353
354 $formRuntimeIdentifier = 'form-runtime-identifier';
355 $formElementIdentifier = 'form-element-identifier';
356
357 $formRuntimeRenderingOptions = [
358 'translation' => [
359 'translationFile' => $formRuntimeXlfPath,
360 'translatePropertyValueIfEmpty' => true
361 ],
362 ];
363
364 $formElementRenderingOptions = [
365 'translation' => [
366 'translationFile' => $textElementXlfPath,
367 'translatePropertyValueIfEmpty' => true
368 ],
369 ];
370
371 $expected = 'form-element-identifier LABEL EN';
372
373 $this->store->flushData($formRuntimeXlfPath);
374 $this->store->flushData($textElementXlfPath);
375
376 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
377
378 $mockFormElement->_set('type', 'Text');
379 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
380 $mockFormElement->_set('identifier', $formElementIdentifier);
381 $mockFormElement->_set('label', '');
382
383 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
384 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
385 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
386
387 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
388 }
389
390 /**
391 * @test
392 */
393 public function translateFormElementValueNotTranslateLabelForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsEmptyAndPropertyShouldNotBeTranslatedAndTranslationExists()
394 {
395 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
396 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
397
398 $formRuntimeIdentifier = 'form-runtime-identifier';
399 $formElementIdentifier = 'form-element-identifier';
400
401 $formRuntimeRenderingOptions = [
402 'translation' => [
403 'translationFile' => $formRuntimeXlfPath,
404 'translatePropertyValueIfEmpty' => true
405 ],
406 ];
407
408 $formElementRenderingOptions = [
409 'translation' => [
410 'translationFile' => $textElementXlfPath,
411 'translatePropertyValueIfEmpty' => false
412 ],
413 ];
414
415 $expected = '';
416
417 $this->store->flushData($formRuntimeXlfPath);
418 $this->store->flushData($textElementXlfPath);
419
420 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
421
422 $mockFormElement->_set('type', 'Text');
423 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
424 $mockFormElement->_set('identifier', $formElementIdentifier);
425 $mockFormElement->_set('label', '');
426
427 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
428 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
429 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
430
431 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
432 }
433
434 /**
435 * @test
436 */
437 public function translateFormElementValueTranslateLabelForConcreteFormElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
438 {
439 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
440 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
441
442 $formRuntimeIdentifier = 'another-form-runtime-identifier';
443 $formElementIdentifier = 'form-element-identifier';
444
445 $formRuntimeRenderingOptions = [
446 'translation' => [
447 'translationFile' => $formRuntimeXlfPath,
448 'translatePropertyValueIfEmpty' => true
449 ],
450 ];
451
452 $formElementRenderingOptions = [
453 'translation' => [
454 'translationFile' => $textElementXlfPath,
455 'translatePropertyValueIfEmpty' => true
456 ],
457 ];
458
459 $expected = 'form-element-identifier LABEL EN 1';
460
461 $this->store->flushData($formRuntimeXlfPath);
462 $this->store->flushData($textElementXlfPath);
463
464 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
465
466 $mockFormElement->_set('type', 'Text');
467 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
468 $mockFormElement->_set('identifier', $formElementIdentifier);
469 $mockFormElement->_set('label', 'some label');
470
471 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
472 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
473 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
474
475 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
476 }
477
478 /**
479 * @test
480 */
481 public function translateFormElementValueTranslateLabelForFormElementTypeIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
482 {
483 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
484 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
485
486 $formRuntimeIdentifier = 'another-form-runtime-identifier';
487 $formElementIdentifier = 'another-form-element-identifier';
488
489 $formRuntimeRenderingOptions = [
490 'translation' => [
491 'translationFile' => $formRuntimeXlfPath,
492 'translatePropertyValueIfEmpty' => true
493 ],
494 ];
495
496 $formElementRenderingOptions = [
497 'translation' => [
498 'translationFile' => $textElementXlfPath,
499 'translatePropertyValueIfEmpty' => true
500 ],
501 ];
502
503 $expected = 'form-element-identifier LABEL EN 2';
504
505 $this->store->flushData($formRuntimeXlfPath);
506 $this->store->flushData($textElementXlfPath);
507
508 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
509
510 $mockFormElement->_set('type', 'Text');
511 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
512 $mockFormElement->_set('identifier', $formElementIdentifier);
513 $mockFormElement->_set('label', 'some label');
514
515 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
516 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
517 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
518
519 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
520 }
521
522 /**
523 * @test
524 */
525 public function translateFormElementValueTranslatePropertyForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementPropertyIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
526 {
527 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
528 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
529
530 $formRuntimeIdentifier = 'form-runtime-identifier';
531 $formElementIdentifier = 'form-element-identifier';
532
533 $formRuntimeRenderingOptions = [
534 'translation' => [
535 'translationFile' => $formRuntimeXlfPath,
536 'translatePropertyValueIfEmpty' => true
537 ],
538 ];
539
540 $formElementRenderingOptions = [
541 'translation' => [
542 'translationFile' => $textElementXlfPath,
543 'translatePropertyValueIfEmpty' => true
544 ],
545 ];
546 $formElementProperties = [
547 'placeholder' => 'placeholder',
548 ];
549
550 $expected = 'form-element-identifier PLACEHOLDER EN';
551
552 $this->store->flushData($formRuntimeXlfPath);
553 $this->store->flushData($textElementXlfPath);
554
555 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
556
557 $mockFormElement->_set('type', 'Text');
558 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
559 $mockFormElement->_set('identifier', $formElementIdentifier);
560 $mockFormElement->_set('properties', $formElementProperties);
561
562 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
563 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
564 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
565
566 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['placeholder'], $mockFormRuntime));
567 }
568
569 /**
570 * @test
571 */
572 public function translateFormElementValueNotTranslatePropertyForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementPropertyIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationNotExists()
573 {
574 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
575 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
576
577 $formRuntimeIdentifier = 'another-form-runtime-identifier';
578 $formElementIdentifier = 'another-form-element-identifier';
579
580 $formRuntimeRenderingOptions = [
581 'translation' => [
582 'translationFile' => $formRuntimeXlfPath,
583 'translatePropertyValueIfEmpty' => true
584 ],
585 ];
586
587 $formElementRenderingOptions = [
588 'translation' => [
589 'translationFile' => $textElementXlfPath,
590 'translatePropertyValueIfEmpty' => true
591 ],
592 ];
593 $formElementProperties = [
594 'placeholder' => 'placeholder',
595 ];
596
597 $expected = 'placeholder';
598
599 $this->store->flushData($formRuntimeXlfPath);
600 $this->store->flushData($textElementXlfPath);
601
602 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
603
604 $mockFormElement->_set('type', 'Text');
605 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
606 $mockFormElement->_set('identifier', $formElementIdentifier);
607 $mockFormElement->_set('properties', $formElementProperties);
608
609 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
610 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
611 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
612
613 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['placeholder'], $mockFormRuntime));
614 }
615
616 /**
617 * @test
618 */
619 public function translateFormElementValueTranslateRenderingOptionForConcreteFormAndConcreteSectionElementIfElementRenderingOptionsContainsATranslationFileAndElementRenderingOptionIsNotEmptyAndRenderingOptionShouldBeTranslatedAndTranslationExists()
620 {
621 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
622 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
623
624 $formRuntimeIdentifier = 'form-runtime-identifier';
625 $formElementIdentifier = 'form-element-identifier-page';
626
627 $formRuntimeRenderingOptions = [
628 'translation' => [
629 'translationFile' => $formRuntimeXlfPath,
630 'translatePropertyValueIfEmpty' => true
631 ],
632 ];
633
634 $formElementRenderingOptions = [
635 'nextButtonLabel' => 'next button label',
636 'translation' => [
637 'translationFile' => $textElementXlfPath,
638 'translatePropertyValueIfEmpty' => true
639 ],
640 ];
641 $formElementProperties = [
642 'placeholder' => 'placeholder',
643 ];
644
645 $expected = 'form-element-identifier nextButtonLabel EN';
646
647 $this->store->flushData($formRuntimeXlfPath);
648 $this->store->flushData($textElementXlfPath);
649
650 $mockFormElement = $this->getAccessibleMock(Page::class, ['dummy'], [], '', false);
651
652 $mockFormElement->_set('type', 'Page');
653 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
654 $mockFormElement->_set('identifier', $formElementIdentifier);
655 $mockFormElement->_set('properties', $formElementProperties);
656
657 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
658 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
659 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
660
661 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['nextButtonLabel'], $mockFormRuntime));
662 }
663
664 /**
665 * @test
666 */
667 public function translateFormElementValueTranslateOptionsPropertyForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementOptionsPropertyIsAnArrayAndPropertyShouldBeTranslatedAndTranslationExists()
668 {
669 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
670 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
671
672 $formRuntimeIdentifier = 'form-runtime-identifier';
673 $formElementIdentifier = 'options-form-element-identifier';
674
675 $formRuntimeRenderingOptions = [
676 'translation' => [
677 'translationFile' => $formRuntimeXlfPath,
678 'translatePropertyValueIfEmpty' => true
679 ],
680 ];
681
682 $formElementRenderingOptions = [
683 'translation' => [
684 'translationFile' => $textElementXlfPath,
685 'translatePropertyValueIfEmpty' => true
686 ],
687 ];
688 $formElementProperties = [
689 'options' => [
690 'optionValue1' => 'optionLabel1',
691 'optionValue2' => 'optionLabel2'
692 ],
693 ];
694
695 $expected = [
696 'optionValue1' => 'options-form-element-identifier option 1 EN',
697 'optionValue2' => 'options-form-element-identifier option 2 EN'
698 ];
699
700 $this->store->flushData($formRuntimeXlfPath);
701 $this->store->flushData($textElementXlfPath);
702
703 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
704
705 $mockFormElement->_set('type', 'Text');
706 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
707 $mockFormElement->_set('identifier', $formElementIdentifier);
708 $mockFormElement->_set('properties', $formElementProperties);
709
710 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
711 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
712 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
713
714 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['options'], $mockFormRuntime));
715 }
716
717 /**
718 * @test
719 */
720 public function translateFormElementValueTranslateOptionsPropertyForConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementOptionsPropertyIsAnArrayAndPropertyShouldBeTranslatedAndTranslationExists()
721 {
722 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
723 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
724
725 $formRuntimeIdentifier = 'another-form-runtime-identifier';
726 $formElementIdentifier = 'options-form-element-identifier';
727
728 $formRuntimeRenderingOptions = [
729 'translation' => [
730 'translationFile' => $formRuntimeXlfPath,
731 'translatePropertyValueIfEmpty' => true
732 ],
733 ];
734
735 $formElementRenderingOptions = [
736 'translation' => [
737 'translationFile' => $textElementXlfPath,
738 'translatePropertyValueIfEmpty' => true
739 ],
740 ];
741 $formElementProperties = [
742 'options' => [
743 'optionValue1' => 'optionLabel1',
744 'optionValue2' => 'optionLabel2'
745 ],
746 ];
747
748 $expected = [
749 'optionValue1' => 'options-form-element-identifier option 1 EN',
750 'optionValue2' => 'options-form-element-identifier option 2 EN'
751 ];
752
753 $this->store->flushData($formRuntimeXlfPath);
754 $this->store->flushData($textElementXlfPath);
755
756 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
757
758 $mockFormElement->_set('type', 'Text');
759 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
760 $mockFormElement->_set('identifier', $formElementIdentifier);
761 $mockFormElement->_set('properties', $formElementProperties);
762
763 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
764 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
765 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
766
767 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['options'], $mockFormRuntime));
768 }
769
770 /**
771 * @test
772 */
773 public function translateFinisherOptionTranslateOptionForConcreteFormIfFinisherTranslationOptionsContainsATranslationFileAndFinisherOptionIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
774 {
775 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
776 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
777
778 $formRuntimeIdentifier = 'form-runtime-identifier';
779 $finisherIdentifier = 'SaveToDatabaseFinisher';
780
781 $formRuntimeRenderingOptions = [
782 'translation' => [
783 'translationFile' => $formRuntimeXlfPath,
784 'translatePropertyValueIfEmpty' => true
785 ],
786 ];
787
788 $finisherRenderingOptions = [
789 'translationFile' => $textElementXlfPath,
790 'translatePropertyValueIfEmpty' => true
791 ];
792
793 $expected = 'form-element-identifier SaveToDatabase subject EN';
794
795 $this->store->flushData($formRuntimeXlfPath);
796 $this->store->flushData($textElementXlfPath);
797
798 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
799 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
800 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
801
802 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, $finisherIdentifier, 'subject', 'subject value', $finisherRenderingOptions));
803 }
804
805 /**
806 * @test
807 */
808 public function translateFinisherOptionTranslateOptionIfFinisherTranslationOptionsContainsATranslationFileAndFinisherOptionIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
809 {
810 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
811 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
812
813 $formRuntimeIdentifier = 'another-form-runtime-identifier';
814 $finisherIdentifier = 'SaveToDatabaseFinisher';
815
816 $formRuntimeRenderingOptions = [
817 'translation' => [
818 'translationFile' => $formRuntimeXlfPath,
819 'translatePropertyValueIfEmpty' => true
820 ],
821 ];
822
823 $finisherRenderingOptions = [
824 'translationFile' => $textElementXlfPath,
825 'translatePropertyValueIfEmpty' => true
826 ];
827
828 $expected = 'form-element-identifier SaveToDatabase subject EN 1';
829
830 $this->store->flushData($formRuntimeXlfPath);
831 $this->store->flushData($textElementXlfPath);
832
833 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
834 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
835 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
836
837 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, $finisherIdentifier, 'subject', 'subject value', $finisherRenderingOptions));
838 }
839
840 /**
841 * @test
842 */
843 public function translateFormElementValueTranslateLabelForConcreteFormAndConcreteElementFromFormRumtimeTranslationFileIfElementRenderingOptionsContainsNoTranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
844 {
845 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
846 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
847
848 $formRuntimeIdentifier = 'my-form-runtime-identifier';
849 $formElementIdentifier = 'my-form-element-identifier';
850
851 $formRuntimeRenderingOptions = [
852 'translation' => [
853 'translationFile' => $formRuntimeXlfPath,
854 'translatePropertyValueIfEmpty' => true
855 ],
856 ];
857
858 $formElementRenderingOptions = [];
859
860 $expected = 'my-form-runtime-identifier my-form-element-identifier LABEL EN';
861
862 $this->store->flushData($formRuntimeXlfPath);
863 $this->store->flushData($textElementXlfPath);
864
865 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
866
867 $mockFormElement->_set('type', 'Text');
868 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
869 $mockFormElement->_set('identifier', $formElementIdentifier);
870 $mockFormElement->_set('label', 'some label');
871
872 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
873 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
874 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
875
876 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
877 }
878
879 /**
880 * @test
881 */
882 public function translateFinisherOptionTranslateOptionForConcreteFormFromFormRuntimeIfFinisherTranslationOptionsContainsNoTranslationFileAndFinisherOptionIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
883 {
884 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
885 $textElementXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf';
886
887 $formRuntimeIdentifier = 'my-form-runtime-identifier';
888 $finisherIdentifier = 'SaveToDatabaseFinisher';
889
890 $formRuntimeRenderingOptions = [
891 'translation' => [
892 'translationFile' => $formRuntimeXlfPath,
893 'translatePropertyValueIfEmpty' => true
894 ],
895 ];
896
897 $finisherRenderingOptions = [];
898
899 $expected = 'my-form-runtime-identifier form-element-identifier SaveToDatabase subject EN';
900
901 $this->store->flushData($formRuntimeXlfPath);
902 $this->store->flushData($textElementXlfPath);
903
904 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
905 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
906 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
907
908 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, $finisherIdentifier, 'subject', 'subject value', $finisherRenderingOptions));
909 }
910
911 /**
912 * @test
913 */
914 public function translateFormElementValueTranslateLabelFromAdditionalTranslationForConcreteFormAndConcreteElementIfElementRenderingOptionsContainsATranslationFileAndElementLabelIsNotEmptyAndPropertyShouldBeTranslatedAndTranslationExists()
915 {
916 $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
917 $textElementXlfPaths = [
918 10 => 'EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf',
919 20 => 'EXT:form/Tests/Unit/Service/Fixtures/locallang_additional_text.xlf'
920 ];
921
922 $formRuntimeIdentifier = 'form-runtime-identifier';
923 $formElementIdentifier = 'form-element-identifier';
924
925 $formRuntimeRenderingOptions = [
926 'translation' => [
927 'translationFile' => $formRuntimeXlfPath,
928 'translatePropertyValueIfEmpty' => true
929 ],
930 ];
931
932 $formElementRenderingOptions = [
933 'translation' => [
934 'translationFile' => $textElementXlfPaths,
935 'translatePropertyValueIfEmpty' => true
936 ],
937 ];
938
939 $expected = 'form-element-identifier ADDITIONAL LABEL EN';
940
941 $this->store->flushData($formRuntimeXlfPath);
942
943 foreach ($textElementXlfPaths as $textElementXlfPath) {
944 $this->store->flushData($textElementXlfPath);
945 }
946
947 $mockFormElement = $this->getAccessibleMock(GenericFormElement::class, ['dummy'], [], '', false);
948
949 $mockFormElement->_set('type', 'Text');
950 $mockFormElement->_set('renderingOptions', $formElementRenderingOptions);
951 $mockFormElement->_set('identifier', $formElementIdentifier);
952 $mockFormElement->_set('label', 'some label');
953
954 $mockFormRuntime = $this->getAccessibleMock(FormRuntime::class, ['getIdentifier', 'getRenderingOptions'], [], '', false);
955 $mockFormRuntime->expects($this->any())->method('getIdentifier')->willReturn($formRuntimeIdentifier);
956 $mockFormRuntime->expects($this->any())->method('getRenderingOptions')->willReturn($formRuntimeRenderingOptions);
957
958 $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
959 }
960 }