‪TYPO3CMS  10.4
IfHasRoleViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 
25 class ‪IfHasRoleViewHelperTest extends ViewHelperBaseTestcase
26 {
30  protected ‪$viewHelper;
31 
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35  ‪$GLOBALS['BE_USER'] = new \stdClass();
36  ‪$GLOBALS['BE_USER']->userGroups = [
37  [
38  'uid' => 1,
39  'title' => 'Editor'
40  ],
41  [
42  'uid' => 2,
43  'title' => 'OtherRole'
44  ]
45  ];
46  $this->viewHelper = new ‪IfHasRoleViewHelper();
47  $this->injectDependenciesIntoViewHelper($this->viewHelper);
48  $this->viewHelper->initializeArguments();
49  }
50 
51  protected function ‪tearDown(): void
52  {
53  unset(‪$GLOBALS['BE_USER']);
54  parent::tearDown();
55  }
56 
61  {
62  $actualResult = $this->viewHelper->renderStatic(
63  ['role' => 'Editor', 'then' => 'then child', 'else' => 'else child'],
64  function () {
65  },
66  $this->prophesize(RenderingContextInterface::class)->reveal()
67  );
68 
69  self::assertEquals('then child', $actualResult);
70  }
71 
76  {
77  $actualResult = $this->viewHelper->renderStatic(
78  ['role' => 1, 'then' => 'then child', 'else' => 'else child'],
79  function () {
80  },
81  $this->prophesize(RenderingContextInterface::class)->reveal()
82  );
83 
84  self::assertEquals('then child', $actualResult);
85  }
86 
91  {
92  $actualResult = $this->viewHelper->renderStatic(
93  ['role' => 'NonExistingRole', 'then' => 'then child', 'else' => 'else child'],
94  function () {
95  },
96  $this->prophesize(RenderingContextInterface::class)->reveal()
97  );
98 
99  self::assertEquals('else child', $actualResult);
100  }
101 
106  {
107  $actualResult = $this->viewHelper->renderStatic(
108  ['role' => 123, 'then' => 'then child', 'else' => 'else child'],
109  function () {
110  },
111  $this->prophesize(RenderingContextInterface::class)->reveal()
112  );
113 
114  self::assertEquals('else child', $actualResult);
115  }
116 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\setUp
‪setUp()
Definition: IfHasRoleViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIdIsNotLoggedIn
‪viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIdIsNotLoggedIn()
Definition: IfHasRoleViewHelperTest.php:104
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest
Definition: IfHasRoleViewHelperTest.php:26
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIsLoggedIn
‪viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIsLoggedIn()
Definition: IfHasRoleViewHelperTest.php:59
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security
Definition: IfAuthenticatedViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers Be Security IfAuthenticatedViewHelper $viewHelper
Definition: IfHasRoleViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIdIsLoggedIn
‪viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIdIsLoggedIn()
Definition: IfHasRoleViewHelperTest.php:74
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIsNotLoggedIn
‪viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIsNotLoggedIn()
Definition: IfHasRoleViewHelperTest.php:89
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\tearDown
‪tearDown()
Definition: IfHasRoleViewHelperTest.php:50
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Fluid\ViewHelpers\Be\Security\IfHasRoleViewHelper
Definition: IfHasRoleViewHelper.php:64