[TASK] Unit test DataHandler->clearPrefixFromValue() 27/55727/6
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 15 Feb 2018 03:16:51 +0000 (04:16 +0100)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Fri, 16 Feb 2018 12:02:50 +0000 (13:02 +0100)
Add a unit test to support the change from issue #83870.

Change-Id: Ic8a1006c56989a1aa2ef2734e1320447875f1138
Resolves: #83909
Related: #83870
Releases: master
Reviewed-on: https://review.typo3.org/55727
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php

index adc62df..0ef9c6d 100644 (file)
@@ -908,4 +908,37 @@ class DataHandlerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             ],
         ];
     }
+
+    /**
+     * @return array
+     */
+    public function clearPrefixFromValueRemovesPrefixDataProvider(): array
+    {
+        return [
+            'normal case' => ['Test (copy 42)', 'Test'],
+            // all cases below look fishy and indicate bugs
+            'with double spaces before' => ['Test  (copy 42)', 'Test '],
+            'with three spaces before' => ['Test   (copy 42)', 'Test  '],
+            'with space after' => ['Test (copy 42) ', 'Test (copy 42) '],
+            'with double spaces after' => ['Test (copy 42)  ', 'Test (copy 42)  '],
+            'with three spaces after' => ['Test (copy 42)   ', 'Test (copy 42)   '],
+            'with double tab before' => ['Test' . chr(9) . '(copy 42)', 'Test'],
+            'with double tab after' => ['Test (copy 42)' . chr(9), 'Test (copy 42)' . chr(9)],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider clearPrefixFromValueRemovesPrefixDataProvider
+     * @param string $input
+     * @param string $expected
+     */
+    public function clearPrefixFromValueRemovesPrefix(string $input, string $expected)
+    {
+        $languageServiceProphecy = $this->prophesize(\TYPO3\CMS\Core\Localization\LanguageService::class);
+        $languageServiceProphecy->sL('testLabel')->willReturn('(copy %s)');
+        $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
+        $GLOBALS['TCA']['testTable']['ctrl']['prependAtCopy'] = 'testLabel';
+        $this->assertEquals($expected, (new DataHandler())->clearPrefixFromValue('testTable', $input));
+    }
 }