[TASK] Introduce setArgument function to ViewHelperBaseTest 89/48889/5
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 11 Jul 2016 09:56:10 +0000 (11:56 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 11 Jul 2016 15:15:38 +0000 (17:15 +0200)
During the current refactoring of ViewHelpers loosing their
render() arguments, the test classes need to be adapted.

In order to ease that process a little bit, a helper method
has been introduced into the ViewHelperBaseTestcase.

The first implementation and show case is part of this change.

Resolves: #77026
Releases: master
Change-Id: I7063c5a431294c03426b4fdd92db3c0c825c3cfc
Reviewed-on: https://review.typo3.org/48889
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/HtmlentitiesViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/ViewHelperBaseTestcase.php

index 0ea3106..524ccee 100644 (file)
@@ -13,19 +13,14 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  *
  * The TYPO3 project - inspiring people to share!
  */
-use Prophecy\Prophecy\ObjectProphecy;
-use TYPO3\CMS\Extbase\Reflection\ReflectionService;
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
 use TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper;
 
 /**
  * Test case
  */
-class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
+class HtmlentitiesViewHelperTest extends ViewHelperBaseTestcase
 {
-    /**
-     * @var ReflectionService|ObjectProphecy
-     */
-    protected $reflectionServiceProphecy;
 
     /**
      * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper
@@ -41,9 +36,9 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     protected function setUp()
     {
-        $this->reflectionServiceProphecy = $this->prophesize(ReflectionService::class);
+        parent::setUp();
         $this->viewHelper = new HtmlentitiesViewHelper();
-        $this->viewHelper->injectReflectionService($this->reflectionServiceProphecy->reveal());
+        $this->injectDependenciesIntoViewHelper($this->viewHelper);
     }
 
     /**
@@ -52,6 +47,7 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     public function renderUsesValueAsSourceIfSpecified()
     {
         $this->setArgumentsUnderTest(
+            $this->viewHelper,
             [
                 'value' => 'Some string',
             ]
@@ -70,7 +66,7 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                 return 'Some string';
             }
         );
-        $this->setArgumentsUnderTest();
+        $this->setArgumentsUnderTest($this->viewHelper);
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals('Some string', $actualResult);
     }
@@ -82,6 +78,7 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $source = 'This is a sample text without special characters.';
         $this->setArgumentsUnderTest(
+            $this->viewHelper,
             [
                 'value' => $source,
             ]
@@ -97,7 +94,10 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $source = 'Some special characters: &©"\'';
         $this->setArgumentsUnderTest(
-            ['value' => $source]
+            $this->viewHelper,
+            [
+                'value' => $source
+            ]
         );
         $expectedResult = 'Some special characters: &amp;&copy;&quot;\'';
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
@@ -111,6 +111,7 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $source = 'Some special characters: &©"\'';
         $this->setArgumentsUnderTest(
+            $this->viewHelper,
             [
                 'value' => $source,
                 'keepQuotes' => true,
@@ -128,6 +129,7 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $source = utf8_decode('Some special characters: &©"\'');
         $this->setArgumentsUnderTest(
+            $this->viewHelper,
             [
                 'value' => $source,
                 'encoding' => 'ISO-8859-1',
@@ -145,7 +147,10 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $source = 'already &quot;encoded&quot;';
         $this->setArgumentsUnderTest(
-            ['value' => $source]
+            $this->viewHelper,
+            [
+                'value' => $source
+            ]
         );
         $expectedResult = 'already &amp;quot;encoded&amp;quot;';
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
@@ -159,6 +164,7 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $source = 'already &quot;encoded&quot;';
         $this->setArgumentsUnderTest(
+            $this->viewHelper,
             [
                 'value' => $source,
                 'doubleEncode' => false,
@@ -179,26 +185,12 @@ class HtmlentitiesViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $source = new \stdClass();
         $this->setArgumentsUnderTest(
-            ['value' => $source]
+            $this->viewHelper,
+            [
+                'value' => $source
+            ]
         );
         $actualResult = $this->viewHelper->render();
         $this->assertSame($source, $actualResult);
     }
-
-    /**
-     * Helper function to merge arguments with default arguments according to their registration
-     * This usually happens in ViewHelperInvoker before the view helper methods are called
-     *
-     * @param array $arguments
-     */
-    protected function setArgumentsUnderTest(array $arguments = [])
-    {
-        $argumentDefinitions = $this->viewHelper->prepareArguments();
-        foreach ($argumentDefinitions as $argumentName => $argumentDefinition) {
-            if (!isset($arguments[$argumentName])) {
-                $arguments[$argumentName] = $argumentDefinition->getDefaultValue();
-            }
-        }
-        $this->viewHelper->setArguments($arguments);
-    }
 }
index fe06621..f20f244 100644 (file)
@@ -13,7 +13,9 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Extbase\Reflection\ReflectionService;
 use TYPO3\CMS\Fluid\Core\Variables\CmsVariableProvider;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
@@ -115,5 +117,27 @@ abstract class ViewHelperBaseTestcase extends \TYPO3\CMS\Core\Tests\UnitTestCase
         if ($viewHelper instanceof \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper || $viewHelper instanceof AbstractTagBasedViewHelper) {
             $viewHelper->_set('tag', $this->tagBuilder);
         }
+        if ($viewHelper instanceof AbstractViewHelper) {
+            $reflectionServiceProphecy = $this->prophesize(ReflectionService::class);
+            $viewHelper->injectReflectionService($reflectionServiceProphecy->reveal());
+        }
+    }
+
+    /**
+     * Helper function to merge arguments with default arguments according to their registration
+     * This usually happens in ViewHelperInvoker before the view helper methods are called
+     *
+     * @param ViewHelperInterface $viewHelper
+     * @param array $arguments
+     */
+    protected function setArgumentsUnderTest(ViewHelperInterface $viewHelper, array $arguments = [])
+    {
+        $argumentDefinitions = $viewHelper->prepareArguments();
+        foreach ($argumentDefinitions as $argumentName => $argumentDefinition) {
+            if (!isset($arguments[$argumentName])) {
+                $arguments[$argumentName] = $argumentDefinition->getDefaultValue();
+            }
+        }
+        $viewHelper->setArguments($arguments);
     }
 }