[TASK] Move render arguments to initializeArguments() 01/49501/2
authorNicole Cordes <typo3@cordes.co>
Wed, 17 Aug 2016 09:52:06 +0000 (11:52 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 20 Aug 2016 10:37:59 +0000 (12:37 +0200)
Move the argument registrations away from the render() method
to initializeArguments() of the last missing ViewHelpers of EXT:fluid.

Resolves: #77529
Releases: master
Change-Id: I4113f17b19a2883f23c62dc5bd3779f8640d4f97
Reviewed-on: https://review.typo3.org/49501
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/fluid/Classes/ViewHelpers/Be/Buttons/ShortcutViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Link/EmailViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Link/ExternalViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Link/TypolinkViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/EmailViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/ExternalViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/TypolinkViewHelperTest.php

index b9feb14..948ee25 100644 (file)
@@ -53,24 +53,15 @@ class ShortcutViewHelper extends AbstractBackendViewHelper
     protected $escapeOutput = false;
 
     /**
-     * Renders a shortcut button as known from the TYPO3 backend
+     * Initialize arguments.
      *
-     * @param array $getVars list of GET variables to store. By default the current id, module and all module arguments will be stored
-     * @param array $setVars list of SET[] variables to store. See DocumentTemplate::makeShortcutIcon(). Normally won't be used by Extbase modules
-     *
-     * @return string the rendered shortcut button
-     * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::makeShortcutIcon()
+     * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
      */
-    public function render(array $getVars = array(), array $setVars = array())
+    public function initializeArguments()
     {
-        return static::renderStatic(
-            array(
-                'getVars' => $getVars,
-                'setVars' => $setVars
-            ),
-            $this->buildRenderChildrenClosure(),
-            $this->renderingContext
-        );
+        parent::initializeArguments();
+        $this->registerArgument('getVars', 'array', 'List of GET variables to store. By default the current id, module and all module arguments will be stored', false, []);
+        $this->registerArgument('setVars', 'array', 'List of SET[] variables to store. See DocumentTemplate::makeShortcutIcon(). Normally won\'t be used by Extbase modules', false, []);
     }
 
     /**
index b38b6ac..25f6733 100644 (file)
@@ -50,6 +50,7 @@ class EmailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
     public function initializeArguments()
     {
         parent::initializeArguments();
+        $this->registerArgument('email', 'string', 'The email address to be turned into a link', true);
         $this->registerUniversalTagAttributes();
         $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
         $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
@@ -58,11 +59,12 @@ class EmailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
     }
 
     /**
-     * @param string $email The email address to be turned into a link.
      * @return string Rendered email link
      */
-    public function render($email)
+    public function render()
     {
+        $email = $this->arguments['email'];
+
         if ($this->isFrontendAvailable()) {
             list($linkHref, $linkText) = $GLOBALS['TSFE']->cObj->getMailTo($email, '');
             $escapeSpecialCharacters = !isset($GLOBALS['TSFE']->spamProtectEmailAddresses) || $GLOBALS['TSFE']->spamProtectEmailAddresses !== 'ascii';
index 0b6a2a8..be7c991 100644 (file)
@@ -51,6 +51,8 @@ class ExternalViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBas
     public function initializeArguments()
     {
         parent::initializeArguments();
+        $this->registerArgument('uri', 'string', 'The URI that will be put in the href attribute of the rendered link tag', true);
+        $this->registerArgument('defaultScheme', 'string', 'Scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'http');
         $this->registerUniversalTagAttributes();
         $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
         $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
@@ -59,13 +61,14 @@ class ExternalViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBas
     }
 
     /**
-     * @param string $uri the URI that will be put in the href attribute of the rendered link tag
-     * @param string $defaultScheme scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already
      * @return string Rendered link
      * @api
      */
-    public function render($uri, $defaultScheme = 'http')
+    public function render()
     {
+        $uri = $this->arguments['uri'];
+        $defaultScheme = $this->arguments['defaultScheme'];
+
         $scheme = parse_url($uri, PHP_URL_SCHEME);
         if ($scheme === null && $defaultScheme !== '') {
             $uri = $defaultScheme . '://' . $uri;
index d92aede..e8dc0b4 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
  */
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Exception;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
@@ -57,28 +58,30 @@ class TypolinkViewHelper extends AbstractViewHelper
     protected $escapeOutput = false;
 
     /**
-     * Render
+     * Initialize ViewHelper arguments
      *
-     * @param string $parameter stdWrap.typolink style parameter string
-     * @param string $target
-     * @param string $class
-     * @param string $title
-     * @param string $additionalParams
-     * @param array $additionalAttributes
+     * @throws Exception
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true);
+        $this->registerArgument('target', 'string', '', false, '');
+        $this->registerArgument('class', 'string', '', false, '');
+        $this->registerArgument('title', 'string', '', false, '');
+        $this->registerArgument('additionalParams', 'string', '', false, '');
+        $this->registerArgument('additionalAttributes', 'array', '', false, []);
+    }
+
+    /**
+     * Render
      *
      * @return string
      */
-    public function render($parameter, $target = '', $class = '', $title = '', $additionalParams = '', $additionalAttributes = array())
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'parameter' => $parameter,
-                'target' => $target,
-                'class' => $class,
-                'title' => $title,
-                'additionalParams' => $additionalParams,
-                'additionalAttributes' => $additionalAttributes
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index a260533..7e7bea2 100644 (file)
@@ -43,7 +43,6 @@ class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHe
             ->setMethods(array('renderChildren'))
             ->getMock();
         $this->injectDependenciesIntoViewHelper($this->viewHelper);
-        $this->viewHelper->initializeArguments();
     }
 
     /**
@@ -59,8 +58,14 @@ class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHe
         $mockTagBuilder->expects($this->once())->method('setContent')->with('some content');
         $this->viewHelper->_set('tag', $mockTagBuilder);
         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'email' => 'some@email.tld',
+            ]
+        );
         $this->viewHelper->initialize();
-        $this->viewHelper->render('some@email.tld');
+        $this->viewHelper->render();
     }
 
     /**
@@ -74,8 +79,14 @@ class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHe
         $mockTagBuilder->expects($this->once())->method('setContent')->with('some@email.tld');
         $this->viewHelper->_set('tag', $mockTagBuilder);
         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue(null));
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'email' => 'some@email.tld',
+            ]
+        );
         $this->viewHelper->initialize();
-        $this->viewHelper->render('some@email.tld');
+        $this->viewHelper->render();
     }
 
     /**
@@ -145,10 +156,13 @@ class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHe
             ->getMock();
         $viewHelper->expects($this->once())->method('isFrontendAvailable')->willReturn(true);
         $viewHelper->expects($this->once())->method('renderChildren')->willReturn(null);
+        $viewHelper->setArguments([
+            'email' => $email,
+        ]);
         $viewHelper->initialize();
         $this->assertSame(
             $expected,
-            $viewHelper->render($email)
+            $viewHelper->render()
         );
     }
 }
index 9b94fbc..1f864ca 100644 (file)
@@ -16,12 +16,12 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Link;
 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
 
 /**
- * Test for \TYPO3\CMS\Fluid\ViewHelpers\Link\EmailViewHelper
+ * Test for \TYPO3\CMS\Fluid\ViewHelpers\Link\ExternalViewHelper
  */
 class ExternalViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase
 {
     /**
-     * @var \TYPO3\CMS\Fluid\ViewHelpers\Link\EmailViewHelper
+     * @var \TYPO3\CMS\Fluid\ViewHelpers\Link\ExternalViewHelper
      */
     protected $viewHelper;
 
@@ -30,7 +30,6 @@ class ExternalViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vie
         parent::setUp();
         $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Link\ExternalViewHelper::class, array('renderChildren'));
         $this->injectDependenciesIntoViewHelper($this->viewHelper);
-        $this->viewHelper->initializeArguments();
     }
 
     /**
@@ -48,8 +47,14 @@ class ExternalViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vie
 
         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
 
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'uri' => 'http://www.some-domain.tld',
+            ]
+        );
         $this->viewHelper->initialize();
-        $this->viewHelper->render('http://www.some-domain.tld');
+        $this->viewHelper->render();
     }
 
     /**
@@ -67,8 +72,14 @@ class ExternalViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vie
 
         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
 
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'uri' => 'www.some-domain.tld',
+            ]
+        );
         $this->viewHelper->initialize();
-        $this->viewHelper->render('www.some-domain.tld');
+        $this->viewHelper->render();
     }
 
     /**
@@ -86,8 +97,15 @@ class ExternalViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vie
 
         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
 
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'uri' => 'some-domain.tld',
+                'defaultScheme' => 'ftp',
+            ]
+        );
         $this->viewHelper->initialize();
-        $this->viewHelper->render('some-domain.tld', 'ftp');
+        $this->viewHelper->render();
     }
 
     /**
@@ -105,7 +123,14 @@ class ExternalViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vie
 
         $this->viewHelper->expects($this->any())->method('renderChildren')->will($this->returnValue('some content'));
 
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'uri' => 'some-domain.tld',
+                'defaultScheme' => '',
+            ]
+        );
         $this->viewHelper->initialize();
-        $this->viewHelper->render('some-domain.tld', '');
+        $this->viewHelper->render();
     }
 }
index 816a435..b695819 100644 (file)
@@ -35,7 +35,7 @@ class TypolinkViewHelperTest extends ViewHelperBaseTestcase
     protected function setUp()
     {
         $this->subject = $this->getAccessibleMock(TypolinkViewHelper::class, array('renderChildren'));
-        /** @var RenderingContext  $renderingContext */
+        /** @var RenderingContext $renderingContext */
         $renderingContext = $this->createMock(\TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextFixture::class);
         $this->subject->setRenderingContext($renderingContext);
     }
@@ -46,10 +46,18 @@ class TypolinkViewHelperTest extends ViewHelperBaseTestcase
     public function renderReturnsResultOfContentObjectRenderer()
     {
         $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
+        $this->subject->setArguments([
+            'parameter' => '42',
+            'target' => '',
+            'class' => '',
+            'title' => '',
+            'additionalParams' => '',
+            'additionalAttributes' => [],
+        ]);
         $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
         $contentObjectRendererMock->expects($this->once())->method('stdWrap')->will($this->returnValue('foo'));
         GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererMock);
-        $this->assertEquals('foo', $this->subject->render('42'));
+        $this->assertEquals('foo', $this->subject->render());
     }
 
     /**