[TASK] Move arguments to initializeArguments() in EmailVH in ext:fluid 77/48877/10
authorRoberto Torresani <erreti@gmail.com>
Sun, 10 Jul 2016 16:26:39 +0000 (18:26 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 11 Jul 2016 16:36:02 +0000 (18:36 +0200)
Move the argument registrations away from the render() method
to initializeArguments(), to prevent any errors with PHP7 and
subclassed ViewHelpers if/when render() method signatures change
Change the UnitTest form EmailViewHelper with setArguments()
Introduce the function setArgumentsUnderTest()

Resolves: #77012
Releases: master
Change-Id: Id6910af603c9ba5e0f638986b52c751b1021431c
Reviewed-on: https://review.typo3.org/48877
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Bamboo TYPO3com <info@typo3.com>
typo3/sysext/fluid/Classes/ViewHelpers/Uri/EmailViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Uri/EmailViewHelperTest.php

index d221520..c942505 100644 (file)
@@ -33,14 +33,28 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 class EmailViewHelper extends AbstractViewHelper
 {
     /**
-     * @param string $email The email address to be turned into a URI
+     * Initialize arguments
+     *
+     * @return void
+     * @api
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('email', 'string', 'The email address to be turned into a URI', true);
+    }
+
+    /**
+     *
      * @return string Rendered email link
      */
-    public function render($email)
+    public function render()
     {
+        $email = $this->arguments['email'];
+
         return static::renderStatic(
             array(
-                'email' => $email
+                'email' => $email,
             ),
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
index f7ba6a4..74fe72c 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Uri;
  */
 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
 use TYPO3\CMS\Fluid\ViewHelpers\Uri\EmailViewHelper;
-use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 
 /**
  * Testcase for the email uri view helper
@@ -30,11 +29,8 @@ class EmailViewHelperTest extends ViewHelperBaseTestcase
     protected function setUp()
     {
         parent::setUp();
-        $GLOBALS['TSFE'] = new \stdClass();
-        $GLOBALS['TSFE']->cObj = $this->createMock(ContentObjectRenderer::class);
         $this->viewHelper = new EmailViewHelper();
         $this->injectDependenciesIntoViewHelper($this->viewHelper);
-        $this->viewHelper->initializeArguments();
     }
 
     /**
@@ -42,8 +38,14 @@ class EmailViewHelperTest extends ViewHelperBaseTestcase
      */
     public function renderReturnsFirstResultOfGetMailTo()
     {
-        $this->viewHelper->initialize();
-        $actualResult = $this->viewHelper->render('some@email.tld');
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'email' => 'some@email.tld'
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+
         $this->assertEquals('mailto:some@email.tld', $actualResult);
     }
 }