[BUGFIX] Properly mock LocalizationFactory in form tests 03/58703/2
authorSusanne Moog <susanne.moog@typo3.org>
Thu, 25 Oct 2018 18:49:02 +0000 (20:49 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 25 Oct 2018 20:39:13 +0000 (22:39 +0200)
Resolves: #86704
Releases: master
Change-Id: Ie30f22e641d76890a97bc47c51665d697aad93f5
Reviewed-on: https://review.typo3.org/58703
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/form/Tests/Unit/Service/Fixtures/de.locallang_form.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_additional_text.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_01.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_02.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_form.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_text.php [new file with mode: 0644]
typo3/sysext/form/Tests/Unit/Service/TranslationServiceTest.php

diff --git a/typo3/sysext/form/Tests/Unit/Service/Fixtures/de.locallang_form.php b/typo3/sysext/form/Tests/Unit/Service/Fixtures/de.locallang_form.php
new file mode 100644 (file)
index 0000000..c38dfe7
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+return [
+    'default' =>
+        [
+            'element.Page.renderingOptions.nextButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'FORM EN',
+                            'target' => 'FORM EN',
+                        ],
+                ],
+        ],
+    'de' =>
+        [
+            'element.Page.renderingOptions.nextButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'FORM EN',
+                            'target' => 'FORM DE',
+                        ],
+                ],
+        ],
+];
diff --git a/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_additional_text.php b/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_additional_text.php
new file mode 100644 (file)
index 0000000..0a7ad8c
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+return [
+    'default' =>
+        [
+            'element.Page.renderingOptions.nextButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'TEXT EN',
+                            'target' => 'TEXT EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-element-identifier ADDITIONAL LABEL EN',
+                            'target' => 'form-element-identifier ADDITIONAL LABEL EN',
+                        ],
+                ],
+        ],
+];
diff --git a/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_01.php b/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_01.php
new file mode 100644 (file)
index 0000000..a6cac45
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+return [
+    'default' =>
+        [
+            'form-runtime-identifier-42.element.form-runtime-identifier-42.renderingOptions.submitButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 submitButtonLabel EN',
+                            'target' => 'form-runtime-identifier-42 submitButtonLabel EN',
+                        ],
+                ],
+            'form-runtime-identifier-42.element.form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 form-element-identifierlabel EN',
+                            'target' => 'form-runtime-identifier-42 form-element-identifierlabel EN',
+                        ],
+                ],
+            'form-runtime-identifier-42.validation.error.form-runtime-identifier-42.123' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 error 123 EN',
+                            'target' => 'form-runtime-identifier-42 error 123 EN',
+                        ],
+                ],
+            'form-runtime-identifier-42.validation.error.form-element-identifier.123' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 form-element-identifier error 123 EN',
+                            'target' => 'form-runtime-identifier-42 form-element-identifier error 123 EN',
+                        ],
+                ],
+            'form-runtime-identifier-42.finisher.Foo.test' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 FooFinisher test EN',
+                            'target' => 'form-runtime-identifier-42 FooFinisher test EN',
+                        ],
+                ],
+        ],
+];
diff --git a/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_02.php b/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_02.php
new file mode 100644 (file)
index 0000000..e3f4535
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+
+return [
+    'default' =>
+        [
+            'form-runtime-identifier-42.element.form-runtime-identifier-42.renderingOptions.submitButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 submitButtonLabel EN',
+                            'target' => 'form-runtime-identifier-42 submitButtonLabel EN',
+                        ],
+                ],
+            'form-runtime-identifier-42.element.form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 form-element-identifierlabel EN',
+                            'target' => 'form-runtime-identifier-42 form-element-identifierlabel EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-runtime-identifier.renderingOptions.submitButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier submitButtonLabel EN',
+                            'target' => 'form-runtime-identifier submitButtonLabel EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifierlabel EN',
+                            'target' => 'form-runtime-identifier form-element-identifierlabel EN',
+                        ],
+                ],
+            'form-runtime-identifier-42.validation.error.form-runtime-identifier-42.123' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 error 123 EN',
+                            'target' => 'form-runtime-identifier-42 error 123 EN',
+                        ],
+                ],
+            'form-runtime-identifier-42.validation.error.form-element-identifier.123' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 form-element-identifier error 123 EN',
+                            'target' => 'form-runtime-identifier-42 form-element-identifier error 123 EN',
+                        ],
+                ],
+            'form-runtime-identifier.validation.error.form-runtime-identifier.123' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier error 123 EN',
+                            'target' => 'form-runtime-identifier error 123 EN',
+                        ],
+                ],
+            'form-runtime-identifier.validation.error.form-element-identifier.123' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifier error 123 EN',
+                            'target' => 'form-runtime-identifier form-element-identifier error 123 EN',
+                        ],
+                ],
+            'form-runtime-identifier-42.finisher.Foo.test' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier-42 FooFinisher test EN',
+                            'target' => 'form-runtime-identifier-42 FooFinisher test EN',
+                        ],
+                ],
+            'form-runtime-identifier.finisher.Foo.test' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier FooFinisher test EN',
+                            'target' => 'form-runtime-identifier FooFinisher test EN',
+                        ],
+                ],
+        ],
+];
diff --git a/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_form.php b/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_form.php
new file mode 100644 (file)
index 0000000..e188b41
--- /dev/null
@@ -0,0 +1,135 @@
+<?php
+
+return [
+    'default' =>
+        [
+            'element.Page.renderingOptions.nextButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'FORM EN',
+                            'target' => 'FORM EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifier LABEL EN',
+                            'target' => 'form-runtime-identifier form-element-identifier LABEL EN',
+                        ],
+                ],
+            'element.form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifier LABEL EN 1',
+                            'target' => 'form-runtime-identifier form-element-identifier LABEL EN 1',
+                        ],
+                ],
+            'element.Text.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifier LABEL EN 2',
+                            'target' => 'form-runtime-identifier form-element-identifier LABEL EN 2',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-element-identifier.properties.placeholder' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifier PLACEHOLDER EN',
+                            'target' => 'form-runtime-identifier form-element-identifier PLACEHOLDER EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-element-identifier-page.renderingOptions.nextButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifier nextButtonLabel EN',
+                            'target' => 'form-runtime-identifier form-element-identifier nextButtonLabel EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.options-form-element-identifier.properties.options.optionValue1' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier options-form-element-identifier option 1 EN',
+                            'target' => 'form-runtime-identifier options-form-element-identifier option 1 EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.options-form-element-identifier.properties.options.optionValue2' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier options-form-element-identifier option 2 EN',
+                            'target' => 'form-runtime-identifier options-form-element-identifier option 2 EN',
+                        ],
+                ],
+            'element.options-form-element-identifier.properties.options.optionValue1' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier options-form-element-identifier option 1 EN',
+                            'target' => 'form-runtime-identifier options-form-element-identifier option 1 EN',
+                        ],
+                ],
+            'element.options-form-element-identifier.properties.options.optionValue2' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier options-form-element-identifier option 2 EN',
+                            'target' => 'form-runtime-identifier options-form-element-identifier option 2 EN',
+                        ],
+                ],
+            'form-runtime-identifier.finisher.SaveToDatabase.subject' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifier SaveToDatabase subject EN',
+                            'target' => 'form-runtime-identifier form-element-identifier SaveToDatabase subject EN',
+                        ],
+                ],
+            'finisher.SaveToDatabase.subject' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-runtime-identifier form-element-identifier SaveToDatabase subject EN 1',
+                            'target' => 'form-runtime-identifier form-element-identifier SaveToDatabase subject EN 1',
+                        ],
+                ],
+            'my-form-runtime-identifier.element.my-form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'my-form-runtime-identifier my-form-element-identifier LABEL EN',
+                            'target' => 'my-form-runtime-identifier my-form-element-identifier LABEL EN',
+                        ],
+                ],
+            'element.my-form-element-with-translation-arguments.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'See %s or %s',
+                            'target' => 'See %s or %s',
+                        ],
+                ],
+            'my-form-runtime-identifier.finisher.SaveToDatabase.subject' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'my-form-runtime-identifier form-element-identifier SaveToDatabase subject EN',
+                            'target' => 'my-form-runtime-identifier form-element-identifier SaveToDatabase subject EN',
+                        ],
+                ],
+            'finisher.EmailToReceiverWithTranslationArguments.subject' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'My %s subject',
+                            'target' => 'My %s subject',
+                        ],
+                ],
+        ],
+];
diff --git a/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_text.php b/typo3/sysext/form/Tests/Unit/Service/Fixtures/locallang_text.php
new file mode 100644 (file)
index 0000000..785c72f
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+
+return [
+    'default' =>
+        [
+            'element.Page.renderingOptions.nextButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'TEXT EN',
+                            'target' => 'TEXT EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-element-identifier LABEL EN',
+                            'target' => 'form-element-identifier LABEL EN',
+                        ],
+                ],
+            'element.form-element-identifier.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-element-identifier LABEL EN 1',
+                            'target' => 'form-element-identifier LABEL EN 1',
+                        ],
+                ],
+            'element.Text.properties.label' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-element-identifier LABEL EN 2',
+                            'target' => 'form-element-identifier LABEL EN 2',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-element-identifier.properties.placeholder' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-element-identifier PLACEHOLDER EN',
+                            'target' => 'form-element-identifier PLACEHOLDER EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.form-element-identifier-page.renderingOptions.nextButtonLabel' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-element-identifier nextButtonLabel EN',
+                            'target' => 'form-element-identifier nextButtonLabel EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.options-form-element-identifier.properties.options.optionValue1' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'options-form-element-identifier option 1 EN',
+                            'target' => 'options-form-element-identifier option 1 EN',
+                        ],
+                ],
+            'form-runtime-identifier.element.options-form-element-identifier.properties.options.optionValue2' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'options-form-element-identifier option 2 EN',
+                            'target' => 'options-form-element-identifier option 2 EN',
+                        ],
+                ],
+            'element.options-form-element-identifier.properties.options.optionValue1' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'options-form-element-identifier option 1 EN',
+                            'target' => 'options-form-element-identifier option 1 EN',
+                        ],
+                ],
+            'element.options-form-element-identifier.properties.options.optionValue2' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'options-form-element-identifier option 2 EN',
+                            'target' => 'options-form-element-identifier option 2 EN',
+                        ],
+                ],
+            'form-runtime-identifier.finisher.SaveToDatabase.subject' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-element-identifier SaveToDatabase subject EN',
+                            'target' => 'form-element-identifier SaveToDatabase subject EN',
+                        ],
+                ],
+            'finisher.SaveToDatabase.subject' =>
+                [
+                    0 =>
+                        [
+                            'source' => 'form-element-identifier SaveToDatabase subject EN 1',
+                            'target' => 'form-element-identifier SaveToDatabase subject EN 1',
+                        ],
+                ],
+        ],
+];
index b7ac60f..fd8903e 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Localization\LanguageStore;
+use TYPO3\CMS\Core\Localization\LocalizationFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
 use TYPO3\CMS\Form\Domain\Model\FormElements\GenericFormElement;
@@ -59,6 +60,7 @@ class TranslationServiceTest extends UnitTestCase
      */
     public function setUp()
     {
+        $this->resetSingletonInstances = true;
         $cacheManagerProphecy = $this->prophesize(CacheManager::class);
         GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
         $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
@@ -66,6 +68,28 @@ class TranslationServiceTest extends UnitTestCase
         $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false);
         $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null);
 
+        $localizationFactory = $this->prophesize(LocalizationFactory::class);
+        $localizationFactory
+            ->getParsedData('EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf', 'default')
+            ->willReturn(include __DIR__ . '/Fixtures/locallang_form.php');
+        $localizationFactory
+            ->getParsedData('EXT:form/Tests/Unit/Service/Fixtures/locallang_form.xlf', 'de')
+            ->willReturn(include __DIR__ . '/Fixtures/de.locallang_form.php');
+        $localizationFactory
+            ->getParsedData('EXT:form/Tests/Unit/Service/Fixtures/locallang_additional_text.xlf', 'default')
+            ->willReturn(include __DIR__ . '/Fixtures/locallang_additional_text.php');
+        $localizationFactory
+            ->getParsedData('EXT:form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_01.xlf', 'default')
+            ->willReturn(include __DIR__ . '/Fixtures/locallang_ceuid_suffix_01.php');
+        $localizationFactory
+            ->getParsedData('EXT:form/Tests/Unit/Service/Fixtures/locallang_ceuid_suffix_02.xlf', 'default')
+            ->willReturn(include __DIR__ . '/Fixtures/locallang_ceuid_suffix_02.php');
+        $localizationFactory
+            ->getParsedData('EXT:form/Tests/Unit/Service/Fixtures/locallang_text.xlf', 'default')
+            ->willReturn(include __DIR__ . '/Fixtures/locallang_text.php');
+
+        GeneralUtility::setSingletonInstance(LocalizationFactory::class, $localizationFactory->reveal());
+
         $this->mockConfigurationManager = $this->getAccessibleMock(ConfigurationManager::class, [
             'getConfiguration'
         ], [], '', false);