2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Fluid\ViewHelpers\Security\IfHasRoleViewHelper
;
18 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase
;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface
;
22 * Testcase for security.ifHasRole view helper
24 class IfHasRoleViewHelperTest
extends ViewHelperBaseTestcase
27 * @var \TYPO3\CMS\Fluid\ViewHelpers\Security\IfHasRoleViewHelper
29 protected $viewHelper;
31 protected function setUp()
34 $GLOBALS['TSFE'] = new \
stdClass();
35 $GLOBALS['TSFE']->loginUser
= 1;
36 $GLOBALS['TSFE']->fe_user
= new \
stdClass();
37 $GLOBALS['TSFE']->fe_user
->groupData
= [
39 'title' => ['Editor', 'OtherRole']
41 $this->viewHelper
= new IfHasRoleViewHelper();
42 $this->injectDependenciesIntoViewHelper($this->viewHelper
);
43 $this->viewHelper
->initializeArguments();
46 protected function tearDown()
48 unset($GLOBALS['TSFE']);
54 public function viewHelperRendersThenChildIfFeUserWithSpecifiedRoleIsLoggedIn()
56 $actualResult = $this->viewHelper
->renderStatic(
57 ['role' => 'Editor', 'then' => 'then child', 'else' => 'else child'],
60 $this->prophesize(RenderingContextInterface
::class)->reveal()
63 $this->assertEquals('then child', $actualResult);
69 public function viewHelperRendersThenChildIfFeUserWithSpecifiedRoleIdIsLoggedIn()
71 $actualResult = $this->viewHelper
->renderStatic(
72 ['role' => 1, 'then' => 'then child', 'else' => 'else child'],
75 $this->prophesize(RenderingContextInterface
::class)->reveal()
78 $this->assertEquals('then child', $actualResult);
84 public function viewHelperRendersElseChildIfFeUserWithSpecifiedRoleIsNotLoggedIn()
86 $actualResult = $this->viewHelper
->renderStatic(
87 ['role' => 'NonExistingRole', 'then' => 'then child', 'else' => 'else child'],
90 $this->prophesize(RenderingContextInterface
::class)->reveal()
93 $this->assertEquals('else child', $actualResult);
99 public function viewHelperRendersElseChildIfFeUserWithSpecifiedRoleIdIsNotLoggedIn()
101 $actualResult = $this->viewHelper
->renderStatic(
102 ['role' => 123, 'then' => 'then child', 'else' => 'else child'],
105 $this->prophesize(RenderingContextInterface
::class)->reveal()
108 $this->assertEquals('else child', $actualResult);