[TASK] Merge performance improvement from TYPO3.Fluid 82/36282/4
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 26 Jan 2015 20:55:36 +0000 (21:55 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 27 Jan 2015 20:15:53 +0000 (21:15 +0100)
Implementing CompilableInterface by adding renderStatic()
can lead to drastic performance improvements since fluid
then calls view helpers statically and the overhead of
instantiation, injection and reflection is gone.

This patch does this for a couple of format view helpers
that have been adapted in TYPO3.Fluid and which do not
differ from "upstream" too much.

As side effect, some of the changed view helpers now also
understand the $value argument.

Performance-wise, this patch is just the tip of the iceberg
and further patches for more often used view helpers will
follow.

TYPO3 Fluid issue: #47674

Resolves: #64521
Releases: master
Change-Id: I923424860c956c4c77cf56c9bf1623bb2fc8c68b
Reviewed-on: http://review.typo3.org/36282
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/fluid/Classes/ViewHelpers/Format/BytesViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlspecialcharsViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/PaddingViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/PrintfViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/StripTagsViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/BytesViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/Nl2brViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/PaddingViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/PrintfViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/StripTagsViewHelperTest.php

index 3ff98cc..f1dd72a 100644 (file)
@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Formats an integer with a byte count into human-readable form.
  *
@@ -34,12 +38,12 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class BytesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class BytesViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * @var array
         */
-       protected $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
+       static protected $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
 
        /**
         * Render the supplied byte count as a human readable string.
@@ -52,8 +56,21 @@ class BytesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
         * @api
         */
        public function render($value = NULL, $decimals = 0, $decimalSeparator = '.', $thousandsSeparator = ',') {
+               return self::renderStatic(array('value' => $value, 'decimals' => $decimals, 'decimalSeparator' => $decimalSeparator, 'thousandsSeparator' => $thousandsSeparator), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Applies htmlspecialchars() on the specified value.
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $value = $arguments['value'];
                if ($value === NULL) {
-                       $value = $this->renderChildren();
+                       $value = $renderChildrenClosure();
                }
 
                if (!is_integer($value) && !is_float($value)) {
@@ -65,13 +82,13 @@ class BytesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelpe
                }
                $bytes = max($value, 0);
                $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
-               $pow = min($pow, count($this->units) - 1);
+               $pow = min($pow, count(self::$units) - 1);
                $bytes /= pow(2, (10 * $pow));
 
                return sprintf(
                        '%s %s',
-                       number_format(round($bytes, 4 * $decimals), $decimals, $decimalSeparator, $thousandsSeparator),
-                       $this->units[$pow]
+                       number_format(round($bytes, 4 * $arguments['decimals']), $arguments['decimals'], $arguments['decimalSeparator'], $arguments['thousandsSeparator']),
+                       self::$units[$pow]
                );
        }
 
index e63f4c0..88fcd30 100644 (file)
@@ -69,6 +69,9 @@ class HtmlspecialcharsViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Format\Abs
        }
 
        /**
+        * This ViewHelper is used a *lot* because it is used by the escape interceptor.
+        * Therefore we render it to raw PHP code during compilation
+        *
         * @param string $argumentsVariableName
         * @param string $renderChildrenClosureVariableName
         * @param string $initializationPhpCode
index 0671a1a..53805b3 100644 (file)
@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Wrapper for PHPs nl2br function.
  * @see http://www.php.net/manual/en/function.nl2br.php
@@ -33,17 +37,34 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class Nl2brViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class Nl2brViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Replaces newline characters by HTML line breaks.
         *
+        * @param string $value string to format
         * @return string the altered string.
         * @api
         */
-       public function render() {
-               $content = $this->renderChildren();
-               return nl2br($content);
+       public function render($value = NULL) {
+               return self::renderStatic(array('value' => $value), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Applies nl2br() on the specified value.
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $value = $arguments['value'];
+               if ($value === NULL) {
+                       $value = $renderChildrenClosure();
+               }
+
+               return nl2br($value);
        }
 
 }
index b3daabf..028292b 100644 (file)
@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Formats a string using PHPs str_pad function.
  * @see http://www.php.net/manual/en/function.str_pad.php
@@ -40,7 +44,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class PaddingViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class PaddingViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Pad a string to a certain length with another string
@@ -48,20 +52,38 @@ class PaddingViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
         * @param int $padLength Length of the resulting string. If the value of pad_length is negative or less than the length of the input string, no padding takes place.
         * @param string $padString The padding string
         * @param string $padType Append the padding at this site (Possible values: right,left,both. Default: right)
+        * @param string $value string to format
         * @return string The formatted value
         * @api
         */
-       public function render($padLength, $padString = ' ', $padType = 'right') {
-               $string = $this->renderChildren();
+       public function render($padLength, $padString = ' ', $padType = 'right', $value = NULL) {
+               return self::renderStatic(array('padLength' => $padLength, 'padString' => $padString, 'padType' => $padType, 'value' => $value), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Applies str_pad() on the specified value.
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $value = $arguments['value'];
+               if ($value === NULL) {
+                       $value = $renderChildrenClosure();
+               }
                $padTypes = array(
                        'left' => STR_PAD_LEFT,
                        'right' => STR_PAD_RIGHT,
                        'both' => STR_PAD_BOTH
                );
+               $padType = $arguments['padType'];
                if (!isset($padTypes[$padType])) {
                        $padType = 'right';
                }
-               return str_pad($string, $padLength, $padString, $padTypes[$padType]);
+
+               return str_pad($value, $arguments['padLength'], $arguments['padString'], $padTypes[$padType]);
        }
 
 }
index 2db1eb1..8191496 100644 (file)
@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * A view helper for formatting values with printf. Either supply an array for
  * the arguments or a single value.
@@ -48,18 +52,35 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class PrintfViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class PrintfViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Format the arguments with the given printf format string.
         *
         * @param array $arguments The arguments for vsprintf
+        * @param string $value string to format
         * @return string The formatted value
         * @api
         */
-       public function render(array $arguments) {
-               $format = $this->renderChildren();
-               return vsprintf($format, $arguments);
+       public function render(array $arguments, $value = NULL) {
+               return self::renderStatic(array('arguments' => $arguments, 'value' => $value), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Applies vsprintf() on the specified value.
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $value = $arguments['value'];
+               if ($value === NULL) {
+                       $value = $renderChildrenClosure();
+               }
+
+               return vsprintf($value, $arguments['arguments']);
        }
 
 }
index 82c0dd9..adc4158 100644 (file)
@@ -11,6 +11,10 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+
 /**
  * Removes tags from the given string (applying PHPs strip_tags() function)
  *
@@ -34,7 +38,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class StripTagsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class StripTagsViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
@@ -53,8 +57,21 @@ class StripTagsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewH
         * @api
         */
        public function render($value = NULL) {
+               return self::renderStatic(array('value' => $value), $this->buildRenderChildrenClosure(), $this->renderingContext);
+       }
+
+       /**
+        * Applies strip_tags() on the specified value.
+        *
+        * @param array $arguments
+        * @param \Closure $renderChildrenClosure
+        * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $value = $arguments['value'];
                if ($value === NULL) {
-                       $value = $this->renderChildren();
+                       $value = $renderChildrenClosure();
                }
                if (!is_string($value)) {
                        return $value;
index bc27bb7..8386452 100644 (file)
@@ -11,18 +11,23 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+
 /**
  * Test case
  */
-class BytesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class BytesViewHelperTest extends ViewHelperBaseTestcase {
 
        /**
-        * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper
+        * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\BytesViewHelper
         */
        protected $viewHelper;
 
        public function setUp() {
+               parent::setUp();
                $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\BytesViewHelper::class, array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initializeArguments();
        }
 
        /**
index ecc8f3c..560ba0d 100644 (file)
@@ -11,18 +11,31 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+
 /**
  * Test case
  */
-class Nl2brViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class Nl2brViewHelperTest extends ViewHelperBaseTestcase {
+
+       /**
+        * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\Nl2brViewHelper
+        */
+       protected $viewHelper;
+
+       public function setUp() {
+               parent::setUp();
+               $this->viewHelper = $this->getMock('TYPO3\CMS\Fluid\ViewHelpers\Format\Nl2brViewHelper', array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initializeArguments();
+       }
 
        /**
         * @test
         */
        public function viewHelperDoesNotModifyTextWithoutLineBreaks() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\Nl2brViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('<p class="bodytext">Some Text without line breaks</p>'));
-               $actualResult = $viewHelper->render();
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('<p class="bodytext">Some Text without line breaks</p>'));
+               $actualResult = $this->viewHelper->render();
                $this->assertEquals('<p class="bodytext">Some Text without line breaks</p>', $actualResult);
        }
 
@@ -30,9 +43,8 @@ class Nl2brViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function viewHelperConvertsLineBreaksToBRTags() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\Nl2brViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(10) . 'Line 2'));
-               $actualResult = $viewHelper->render();
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(10) . 'Line 2'));
+               $actualResult = $this->viewHelper->render();
                $this->assertEquals('Line 1<br />' . chr(10) . 'Line 2', $actualResult);
        }
 
@@ -40,9 +52,8 @@ class Nl2brViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function viewHelperConvertsWindowsLineBreaksToBRTags() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\Nl2brViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(13) . chr(10) . 'Line 2'));
-               $actualResult = $viewHelper->render();
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(13) . chr(10) . 'Line 2'));
+               $actualResult = $this->viewHelper->render();
                $this->assertEquals('Line 1<br />' . chr(13) . chr(10) . 'Line 2', $actualResult);
        }
 
index f733b0a..4e01948 100644 (file)
@@ -11,18 +11,31 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+
 /**
  * Test case
  */
-class PaddingViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class PaddingViewHelperTest extends ViewHelperBaseTestcase {
+
+       /**
+        * @var \TYPO3\Fluid\ViewHelpers\Format\PaddingViewHelper
+        */
+       protected $viewHelper;
+
+       public function setUp() {
+               parent::setUp();
+               $this->viewHelper = $this->getMock('TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper', array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initializeArguments();
+       }
 
        /**
         * @test
         */
        public function stringsArePaddedWithBlanksByDefault() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
-               $actualResult = $viewHelper->render(10);
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
+               $actualResult = $this->viewHelper->render(10);
                $this->assertEquals('foo       ', $actualResult);
        }
 
@@ -30,9 +43,8 @@ class PaddingViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function paddingStringCanBeSpecified() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
-               $actualResult = $viewHelper->render(10, '-=');
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('foo'));
+               $actualResult = $this->viewHelper->render(10, '-=');
                $this->assertEquals('foo-=-=-=-', $actualResult);
        }
 
@@ -40,9 +52,8 @@ class PaddingViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function stringIsNotTruncatedIfPadLengthIsBelowStringLength() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('some long string'));
-               $actualResult = $viewHelper->render(5);
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('some long string'));
+               $actualResult = $this->viewHelper->render(5);
                $this->assertEquals('some long string', $actualResult);
        }
 
@@ -50,9 +61,8 @@ class PaddingViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function integersArePaddedCorrectly() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\PaddingViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(123));
-               $actualResult = $viewHelper->render(5, '0');
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(123));
+               $actualResult = $this->viewHelper->render(5, '0');
                $this->assertEquals('12300', $actualResult);
        }
 
index 3dd9e19..03d4550 100644 (file)
@@ -11,18 +11,31 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+
 /**
  * Test case
  */
-class PrintfViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class PrintfViewHelperTest extends ViewHelperBaseTestcase {
+
+       /**
+        * @var \TYPO3\Fluid\ViewHelpers\Format\PrintfViewHelper
+        */
+       protected $viewHelper;
+
+       public function setUp() {
+               parent::setUp();
+               $this->viewHelper = $this->getMock('TYPO3\CMS\Fluid\ViewHelpers\Format\PrintfViewHelper', array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initializeArguments();
+       }
 
        /**
         * @test
         */
        public function viewHelperCanUseArrayAsArgument() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\PrintfViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('%04d-%02d-%02d'));
-               $actualResult = $viewHelper->render(array('year' => 2009, 'month' => 4, 'day' => 5));
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('%04d-%02d-%02d'));
+               $actualResult = $this->viewHelper->render(array('year' => 2009, 'month' => 4, 'day' => 5));
                $this->assertEquals('2009-04-05', $actualResult);
        }
 
@@ -30,9 +43,8 @@ class PrintfViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function viewHelperCanSwapMultipleArguments() {
-               $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\PrintfViewHelper::class, array('renderChildren'));
-               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('%2$s %1$d %3$s %2$s'));
-               $actualResult = $viewHelper->render(array(123, 'foo', 'bar'));
+               $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('%2$s %1$d %3$s %2$s'));
+               $actualResult = $this->viewHelper->render(array(123, 'foo', 'bar'));
                $this->assertEquals('foo 123 bar foo', $actualResult);
        }
 
index b77dee2..1829d5d 100644 (file)
@@ -11,10 +11,12 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+
 /**
  * Test case
  */
-class StripTagsViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class StripTagsViewHelperTest extends ViewHelperBaseTestcase {
 
        /**
         * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\StripTagsViewHelper
@@ -22,7 +24,10 @@ class StripTagsViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        protected $viewHelper;
 
        public function setUp() {
+               parent::setUp();
                $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\StripTagsViewHelper::class, array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initializeArguments();
        }
 
        /**