‪TYPO3CMS  9.5
IfHasRoleViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 
24 class ‪IfHasRoleViewHelperTest extends ViewHelperBaseTestcase
25 {
29  protected ‪$viewHelper;
30 
31  protected function ‪setUp()
32  {
33  parent::setUp();
34  ‪$GLOBALS['BE_USER'] = new \stdClass();
35  ‪$GLOBALS['BE_USER']->userGroups = [
36  [
37  'uid' => 1,
38  'title' => 'Editor'
39  ],
40  [
41  'uid' => 2,
42  'title' => 'OtherRole'
43  ]
44  ];
45  $this->viewHelper = new ‪IfHasRoleViewHelper();
46  $this->injectDependenciesIntoViewHelper($this->viewHelper);
47  $this->viewHelper->initializeArguments();
48  }
49 
50  protected function ‪tearDown()
51  {
52  unset(‪$GLOBALS['BE_USER']);
53  }
54 
59  {
60  $actualResult = $this->viewHelper->renderStatic(
61  ['role' => 'Editor', 'then' => 'then child', 'else' => 'else child'],
62  function () {
63  },
64  $this->prophesize(RenderingContextInterface::class)->reveal()
65  );
66 
67  $this->assertEquals('then child', $actualResult);
68  }
69 
74  {
75  $actualResult = $this->viewHelper->renderStatic(
76  ['role' => 1, 'then' => 'then child', 'else' => 'else child'],
77  function () {
78  },
79  $this->prophesize(RenderingContextInterface::class)->reveal()
80  );
81 
82  $this->assertEquals('then child', $actualResult);
83  }
84 
89  {
90  $actualResult = $this->viewHelper->renderStatic(
91  ['role' => 'NonExistingRole', 'then' => 'then child', 'else' => 'else child'],
92  function () {
93  },
94  $this->prophesize(RenderingContextInterface::class)->reveal()
95  );
96 
97  $this->assertEquals('else child', $actualResult);
98  }
99 
104  {
105  $actualResult = $this->viewHelper->renderStatic(
106  ['role' => 123, 'then' => 'then child', 'else' => 'else child'],
107  function () {
108  },
109  $this->prophesize(RenderingContextInterface::class)->reveal()
110  );
111 
112  $this->assertEquals('else child', $actualResult);
113  }
114 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\setUp
‪setUp()
Definition: IfHasRoleViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIdIsNotLoggedIn
‪viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIdIsNotLoggedIn()
Definition: IfHasRoleViewHelperTest.php:102
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest
Definition: IfHasRoleViewHelperTest.php:25
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIsLoggedIn
‪viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIsLoggedIn()
Definition: IfHasRoleViewHelperTest.php:57
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security
Definition: IfAuthenticatedViewHelperTest.php:3
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers Be Security IfAuthenticatedViewHelper $viewHelper
Definition: IfHasRoleViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIdIsLoggedIn
‪viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIdIsLoggedIn()
Definition: IfHasRoleViewHelperTest.php:72
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIsNotLoggedIn
‪viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIsNotLoggedIn()
Definition: IfHasRoleViewHelperTest.php:87
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\tearDown
‪tearDown()
Definition: IfHasRoleViewHelperTest.php:49
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Fluid\ViewHelpers\Be\Security\IfHasRoleViewHelper
Definition: IfHasRoleViewHelper.php:63