[TASK] Move ViewHelper arguments to initializeArguments() in ext:install 24/49124/3
authorWouter Wolters <typo3@wouterwolters.nl>
Wed, 20 Jul 2016 09:43:05 +0000 (11:43 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Thu, 21 Jul 2016 05:30:33 +0000 (07:30 +0200)
Resolves: #76912
Releases: master
Change-Id: Icf881eb735f1530a86faaa3f93dac64209cb0624
Reviewed-on: https://review.typo3.org/49124
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
typo3/sysext/install/Classes/ViewHelpers/Be/ContainerViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/ConstantViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/File/ExistsViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/File/ImageDimensionViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/File/SizeViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/Format/CropViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/Format/ImageMagickCommandsViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/Format/PhpErrorCodeViewHelper.php
typo3/sysext/install/Classes/ViewHelpers/Object/ArrayValueByKeyViewHelper.php
typo3/sysext/install/Tests/Unit/ViewHelpers/Format/PhpErrorCodeViewHelperTest.php

index 3899099..3925b62 100644 (file)
@@ -52,18 +52,29 @@ class ContainerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBacken
     protected $escapeChildren = false;
 
     /**
     protected $escapeChildren = false;
 
     /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('pageTitle', 'string', 'title tag of the module. Not required by default, as BE modules are shown in a frame', false, '');
+        $this->registerArgument('addCssFiles', 'array', 'Custom CSS files to be loaded', false, []);
+        $this->registerArgument('addJsFiles', 'array', 'Custom JavaScript files to be loaded', false, []);
+    }
+
+    /**
      * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
      *
      * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
      *
-     * @param string $pageTitle title tag of the module. Not required by default, as BE modules are shown in a frame
-     * @param array $addCssFiles Custom CSS files to be loaded
-     * @param array $addJsFiles Custom JavaScript files to be loaded
-     *
      * @return string
      * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
      * @see \TYPO3\CMS\Core\Page\PageRenderer
      */
      * @return string
      * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
      * @see \TYPO3\CMS\Core\Page\PageRenderer
      */
-    public function render($pageTitle = '', $addCssFiles = array(), $addJsFiles = array())
+    public function render()
     {
     {
+        $pageTitle = $this->arguments['pageTitle'];
+        $addCssFiles = $this->arguments['addCssFiles'];
+        $addJsFiles = $this->arguments['addJsFiles'];
+
         $doc = $this->getDocInstance();
         $pageRenderer = $this->getPageRenderer();
 
         $doc = $this->getDocInstance();
         $pageRenderer = $this->getPageRenderer();
 
index 5eee595..07625a2 100644 (file)
@@ -25,17 +25,23 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 class ConstantViewHelper extends AbstractViewHelper
 {
     /**
 class ConstantViewHelper extends AbstractViewHelper
 {
     /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('name', 'string', 'Name of the constant', true);
+    }
+
+    /**
      * Render a constant
      *
      * Render a constant
      *
-     * @param string $name Name of the constant
      * @return string Value of constant
      */
      * @return string Value of constant
      */
-    public function render($name)
+    public function render()
     {
         return static::renderStatic(
     {
         return static::renderStatic(
-            array(
-                'name' => $name,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 45c900d..abf3ad1 100644 (file)
@@ -34,18 +34,21 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  */
 class ExistsViewHelper extends AbstractViewHelper
 {
  */
 class ExistsViewHelper extends AbstractViewHelper
 {
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('file', 'string', 'Absolute path', true);
+    }
+
     /**
      * Check if given file is a regular file
      *
     /**
      * Check if given file is a regular file
      *
-     * @param string $file Absolute path
      * @return bool
      */
      * @return bool
      */
-    public function render($file)
+    public function render()
     {
         return static::renderStatic(
     {
         return static::renderStatic(
-            array(
-                'file' => $file,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 05ac08f..2c554ae 100644 (file)
@@ -41,18 +41,24 @@ class ImageDimensionViewHelper extends AbstractViewHelper
     protected $escapeChildren = false;
 
     /**
     protected $escapeChildren = false;
 
     /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('dimension', 'string', '', false, 'width');
+    }
+
+    /**
      * Get width / height from image file
      *
      * Get width / height from image file
      *
-     * @param string $dimension Either width or height
      * @throws \TYPO3\CMS\Install\ViewHelpers\Exception
      * @return int width or height
      */
      * @throws \TYPO3\CMS\Install\ViewHelpers\Exception
      * @return int width or height
      */
-    public function render($dimension = 'width')
+    public function render()
     {
         return static::renderStatic(
     {
         return static::renderStatic(
-            array(
-                'dimension' => $dimension,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 8a5cee0..07432af 100644 (file)
@@ -42,18 +42,24 @@ class SizeViewHelper extends AbstractViewHelper
     protected $escapeChildren = false;
 
     /**
     protected $escapeChildren = false;
 
     /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('format', 'bool', 'If true, file size will be formatted', false, true);
+    }
+
+    /**
      * Get size from file
      *
      * Get size from file
      *
-     * @param bool $format If true, file size will be formatted
      * @throws \TYPO3\CMS\Install\ViewHelpers\Exception
      * @return int File size
      */
      * @throws \TYPO3\CMS\Install\ViewHelpers\Exception
      * @return int File size
      */
-    public function render($format = true)
+    public function render()
     {
         return static::renderStatic(
     {
         return static::renderStatic(
-            array(
-                'format' => $format,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 6bc4c22..77d8ecb 100644 (file)
@@ -49,18 +49,24 @@ class CropViewHelper extends AbstractViewHelper
     protected $escapeChildren = false;
 
     /**
     protected $escapeChildren = false;
 
     /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('maxCharacters', 'int', '', true);
+    }
+
+    /**
      * Render the cropped text
      *
      * Render the cropped text
      *
-     * @param int $maxCharacters Place where to truncate the string
      * @throws \TYPO3\CMS\Install\ViewHelpers\Exception
      * @return string cropped text
      */
      * @throws \TYPO3\CMS\Install\ViewHelpers\Exception
      * @return string cropped text
      */
-    public function render($maxCharacters)
+    public function render()
     {
         return static::renderStatic(
     {
         return static::renderStatic(
-            array(
-                'maxCharacters' => $maxCharacters,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 3919702..f2e3769 100644 (file)
@@ -32,17 +32,23 @@ class ImageMagickCommandsViewHelper extends AbstractViewHelper
     protected $escapeOutput = false;
 
     /**
     protected $escapeOutput = false;
 
     /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('commands', 'array', 'Given commands', false, []);
+    }
+
+    /**
      * Display image magick commands
      *
      * Display image magick commands
      *
-     * @param array $commands Given commands
      * @return string Formatted commands
      */
      * @return string Formatted commands
      */
-    public function render(array $commands = array())
+    public function render()
     {
         return static::renderStatic(
     {
         return static::renderStatic(
-            array(
-                'commands' => $commands,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index c2af1d3..c8effda 100644 (file)
@@ -46,17 +46,23 @@ class PhpErrorCodeViewHelper extends AbstractViewHelper
     );
 
     /**
     );
 
     /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('phpErrorCode', 'int', '', true);
+    }
+
+    /**
      * Render a readable string for PHP error code
      *
      * Render a readable string for PHP error code
      *
-     * @param int $phpErrorCode
      * @return string
      */
      * @return string
      */
-    public function render($phpErrorCode)
+    public function render()
     {
         return static::renderStatic(
     {
         return static::renderStatic(
-            array(
-                'phpErrorCode' => $phpErrorCode,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index e0d565c..56491ea 100644 (file)
@@ -35,19 +35,24 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 class ArrayValueByKeyViewHelper extends AbstractViewHelper
 {
     /**
 class ArrayValueByKeyViewHelper extends AbstractViewHelper
 {
     /**
+     * Initialize arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('array', 'array', 'The array being processed', true);
+        $this->registerArgument('key', 'mixed', 'The key being accessed', true);
+    }
+
+    /**
      * Get the value of an key in an array.
      *
      * Get the value of an key in an array.
      *
-     * @param array $array The array being processed
-     * @param mixed $key The key being accessed
      * @return string
      */
      * @return string
      */
-    public function render(array $array, $key)
+    public function render()
     {
         return static::renderStatic(
     {
         return static::renderStatic(
-            array(
-                'array' => $array,
-                'key' => $key,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index f313411..d3332ea 100644 (file)
@@ -14,13 +14,12 @@ namespace TYPO3\CMS\Install\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!
  */
 
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
-use TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextFixture;
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
 
 /**
  * Test case
  */
 
 /**
  * Test case
  */
-class PhpErrorCodeViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
+class PhpErrorCodeViewHelperTest extends ViewHelperBaseTestcase
 {
     /**
      * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper
 {
     /**
      * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper
@@ -32,12 +31,10 @@ class PhpErrorCodeViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     protected function setUp()
     {
      */
     protected function setUp()
     {
-        $this->viewHelper = $this->getMockBuilder(\TYPO3\CMS\Install\ViewHelpers\Format\PhpErrorCodeViewHelper::class)
-            ->setMethods(array('dummy'))
-            ->getMock();
-        /** @var RenderingContext $renderingContext */
-        $renderingContext = new RenderingContextFixture();
-        $this->viewHelper->setRenderingContext($renderingContext);
+        parent::setUp();
+        $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Install\ViewHelpers\Format\PhpErrorCodeViewHelper::class, ['dummy']);
+        $this->injectDependenciesIntoViewHelper($this->viewHelper);
+        $this->viewHelper->initializeArguments();
     }
 
     /**
     }
 
     /**
@@ -73,7 +70,10 @@ class PhpErrorCodeViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function renderPhpCodesCorrectly($errorCode, $expectedString)
     {
      */
     public function renderPhpCodesCorrectly($errorCode, $expectedString)
     {
-        $actualString = $this->viewHelper->render($errorCode);
+        $this->viewHelper->setArguments([
+            'phpErrorCode' => $errorCode
+        ]);
+        $actualString = $this->viewHelper->render();
         $this->assertEquals($expectedString, $actualString);
     }
 }
         $this->assertEquals($expectedString, $actualString);
     }
 }