[TASK] Make condition ViewHelper compilable in ext:fluid 64/39264/3
authorWouter Wolters <typo3@wouterwolters.nl>
Mon, 4 May 2015 17:00:13 +0000 (19:00 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 11 May 2015 11:20:47 +0000 (13:20 +0200)
Resolves: #66714
Releases: master
Change-Id: If6c2355944405db04b5a6be3972158cc4ed23e05
Reviewed-on: http://review.typo3.org/39264
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/fluid/Classes/ViewHelpers/Security/IfAuthenticatedViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Security/IfHasRoleViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Security/IfHasRoleViewHelperTest.php

index 1ade7db..1cd20ba 100644 (file)
@@ -54,16 +54,13 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Security;
 class IfAuthenticatedViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper {
 
        /**
-        * Renders <f:then> child if any FE user is currently authenticated, otherwise renders <f:else> child.
+        * This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
         *
-        * @return string the rendered string
-        * @api
+        * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
+        * @return bool
         */
-       public function render() {
-               if (isset($GLOBALS['TSFE']) && $GLOBALS['TSFE']->loginUser) {
-                       return $this->renderThenChild();
-               }
-               return $this->renderElseChild();
+       static protected function evaluateCondition($arguments = NULL) {
+               return isset($GLOBALS['TSFE']) && $GLOBALS['TSFE']->loginUser;
        }
 
 }
index 5f5abc9..818d963 100644 (file)
@@ -71,20 +71,17 @@ class IfHasRoleViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractCondi
         * @api
         */
        public function render($role) {
-               if ($this->frontendUserHasRole($role)) {
-                       return $this->renderThenChild();
-               } else {
-                       return $this->renderElseChild();
-               }
+               return parent::render();
        }
 
        /**
-        * Determines whether the currently logged in FE user belongs to the specified usergroup
+        * This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
         *
-        * @param string $role The usergroup (either the usergroup uid or its title)
-        * @return bool TRUE if the currently logged in FE user belongs to $role
+        * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
+        * @return bool
         */
-       protected function frontendUserHasRole($role) {
+       static protected function evaluateCondition($arguments = NULL) {
+               $role = $arguments['role'];
                if (!isset($GLOBALS['TSFE']) || !$GLOBALS['TSFE']->loginUser) {
                        return FALSE;
                }
index ff64719..8fa7427 100644 (file)
@@ -51,6 +51,9 @@ class IfHasRoleViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vi
         * @test
         */
        public function viewHelperRendersThenChildIfFeUserWithSpecifiedRoleIsLoggedIn() {
+               $this->arguments['role'] = 'Editor';
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+
                $actualResult = $this->viewHelper->render('Editor');
                $this->assertEquals('then child', $actualResult);
        }
@@ -59,6 +62,9 @@ class IfHasRoleViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vi
         * @test
         */
        public function viewHelperRendersThenChildIfFeUserWithSpecifiedRoleIdIsLoggedIn() {
+               $this->arguments['role'] = 1;
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+
                $actualResult = $this->viewHelper->render(1);
                $this->assertEquals('then child', $actualResult);
        }
@@ -67,6 +73,9 @@ class IfHasRoleViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vi
         * @test
         */
        public function viewHelperRendersElseChildIfFeUserWithSpecifiedRoleIsNotLoggedIn() {
+               $this->arguments['role'] = 'NonExistingRole';
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+
                $actualResult = $this->viewHelper->render('NonExistingRole');
                $this->assertEquals('else child', $actualResult);
        }
@@ -75,6 +84,9 @@ class IfHasRoleViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vi
         * @test
         */
        public function viewHelperRendersElseChildIfFeUserWithSpecifiedRoleIdIsNotLoggedIn() {
+               $this->arguments['role'] = 123;
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+
                $actualResult = $this->viewHelper->render(123);
                $this->assertEquals('else child', $actualResult);
        }