[FEATURE] EXT:form - support translation arguments
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Service / TranslationServiceTest.php
index 76377e9..2077ced 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
 use TYPO3\CMS\Form\Domain\Model\FormElements\GenericFormElement;
 use TYPO3\CMS\Form\Domain\Model\FormElements\Page;
+use TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface;
 use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
 use TYPO3\CMS\Form\Service\TranslationService;
 
@@ -876,6 +877,47 @@ class TranslationServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
         $this->assertEquals($expected, $this->mockTranslationService->_call('translateFormElementValue', $mockFormElement, ['label'], $mockFormRuntime));
     }
 
+    /**
+     * @test
+     */
+    public function supportsArgumentsForFormElementValueTranslations()
+    {
+        $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
+
+        $this->store->flushData($formRuntimeXlfPath);
+
+        /** @var FormRuntime|\Prophecy\Prophecy\ObjectProphecy */
+        $formRuntime = $this->prophesize(FormRuntime::class);
+        $formRuntime->getIdentifier()->willReturn('my-form-runtime-identifier');
+        $formRuntime->getRenderingOptions()->willReturn([
+            'translation' => [
+                'translationFile' => $formRuntimeXlfPath,
+                'translatePropertyValueIfEmpty' => true,
+            ],
+        ]);
+
+        /** @var RootRenderableInterface|\Prophecy\Prophecy\ObjectProphecy */
+        $element = $this->prophesize(RootRenderableInterface::class);
+        $element->getIdentifier()->willReturn('my-form-element-with-translation-arguments');
+        $element->getType()->willReturn(RootRenderableInterface::class);
+        $element->getLabel()->willReturn('See %s or %s');
+        $element->getRenderingOptions()->willReturn([
+            'translation' => [
+                'arguments' => [
+                        'label' => [
+                            'this',
+                            'that',
+                        ],
+                ],
+            ],
+        ]);
+
+        $expected = 'See this or that';
+        $result = $this->mockTranslationService->_call('translateFormElementValue', $element->reveal(), ['label'], $formRuntime->reveal());
+
+        $this->assertEquals($expected, $result);
+    }
+
     /**
      * @test
      */
@@ -908,6 +950,38 @@ class TranslationServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
         $this->assertEquals($expected, $this->mockTranslationService->_call('translateFinisherOption', $mockFormRuntime, $finisherIdentifier, 'subject', 'subject value', $finisherRenderingOptions));
     }
 
+    /**
+     * @test
+     */
+    public function supportsArgumentsForFinisherOptionTranslations()
+    {
+        $formRuntimeXlfPath = 'EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf';
+
+        $this->store->flushData($formRuntimeXlfPath);
+
+        /** @var FormRuntime|\Prophecy\Prophecy\ObjectProphecy */
+        $formRuntime = $this->prophesize(FormRuntime::class);
+        $formRuntime->getIdentifier()->willReturn('my-form-runtime-identifier');
+        $formRuntime->getRenderingOptions()->willReturn([
+            'translation' => [
+                'translationFile' => $formRuntimeXlfPath,
+                'translatePropertyValueIfEmpty' => true,
+            ],
+        ]);
+        $renderingOptions = [
+            'arguments' => [
+                'subject' => [
+                    'awesome',
+                ],
+            ],
+        ];
+
+        $expected = 'My awesome subject';
+        $result = $this->mockTranslationService->_call('translateFinisherOption', $formRuntime->reveal(), 'EmailToReceiverWithTranslationArguments', 'subject', 'My %s subject', $renderingOptions);
+
+        $this->assertEquals($expected, $result);
+    }
+
     /**
      * @test
      */