‪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 
23 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
24 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25 
29 class ‪IfHasRoleViewHelperTest extends ViewHelperBaseTestcase
30 {
34  protected ‪$viewHelper;
35 
39  protected ‪$context;
40 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $this->context = GeneralUtility::makeInstance(Context::class);
45  $user = new ‪FrontendUserAuthentication();
46  $user->user['uid'] = 13;
47  $user->groupData = [
48  'uid' => [1, 2],
49  'title' => ['Editor', 'OtherRole']
50  ];
51  $this->context->setAspect('frontend.user', new ‪UserAspect($user, [1, 2]));
52  $this->viewHelper = new ‪IfHasRoleViewHelper();
53  $this->injectDependenciesIntoViewHelper($this->viewHelper);
54  $this->viewHelper->initializeArguments();
55  }
56 
57  protected function ‪tearDown(): void
58  {
59  GeneralUtility::removeSingletonInstance(Context::class, $this->context);
60  parent::tearDown();
61  }
62 
67  {
68  $actualResult = $this->viewHelper->renderStatic(
69  ['role' => 'Editor', 'then' => 'then child', 'else' => 'else child'],
70  function () {
71  },
72  $this->prophesize(RenderingContextInterface::class)->reveal()
73  );
74 
75  self::assertEquals('then child', $actualResult);
76  }
77 
82  {
83  $actualResult = $this->viewHelper->renderStatic(
84  ['role' => 1, 'then' => 'then child', 'else' => 'else child'],
85  function () {
86  },
87  $this->prophesize(RenderingContextInterface::class)->reveal()
88  );
89 
90  self::assertEquals('then child', $actualResult);
91  }
92 
97  {
98  $actualResult = $this->viewHelper->renderStatic(
99  ['role' => 'NonExistingRole', 'then' => 'then child', 'else' => 'else child'],
100  function () {
101  },
102  $this->prophesize(RenderingContextInterface::class)->reveal()
103  );
104 
105  self::assertEquals('else child', $actualResult);
106  }
107 
112  {
113  $actualResult = $this->viewHelper->renderStatic(
114  ['role' => 123, 'then' => 'then child', 'else' => 'else child'],
115  function () {
116  },
117  $this->prophesize(RenderingContextInterface::class)->reveal()
118  );
119 
120  self::assertEquals('else child', $actualResult);
121  }
122 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest\viewHelperRendersElseChildIfFeUserWithSpecifiedRoleIdIsNotLoggedIn
‪viewHelperRendersElseChildIfFeUserWithSpecifiedRoleIdIsNotLoggedIn()
Definition: IfHasRoleViewHelperTest.php:109
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security
Definition: IfAuthenticatedViewHelperTest.php:16
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest\viewHelperRendersThenChildIfFeUserWithSpecifiedRoleIdIsLoggedIn
‪viewHelperRendersThenChildIfFeUserWithSpecifiedRoleIdIsLoggedIn()
Definition: IfHasRoleViewHelperTest.php:79
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest\$context
‪Context $context
Definition: IfHasRoleViewHelperTest.php:37
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest
Definition: IfHasRoleViewHelperTest.php:30
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest\viewHelperRendersElseChildIfFeUserWithSpecifiedRoleIsNotLoggedIn
‪viewHelperRendersElseChildIfFeUserWithSpecifiedRoleIsNotLoggedIn()
Definition: IfHasRoleViewHelperTest.php:94
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest\viewHelperRendersThenChildIfFeUserWithSpecifiedRoleIsLoggedIn
‪viewHelperRendersThenChildIfFeUserWithSpecifiedRoleIsLoggedIn()
Definition: IfHasRoleViewHelperTest.php:64
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest\setUp
‪setUp()
Definition: IfHasRoleViewHelperTest.php:39
‪TYPO3\CMS\Fluid\ViewHelpers\Security\IfHasRoleViewHelper
Definition: IfHasRoleViewHelper.php:73
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest\tearDown
‪tearDown()
Definition: IfHasRoleViewHelperTest.php:55
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfHasRoleViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers Security IfHasRoleViewHelper $viewHelper
Definition: IfHasRoleViewHelperTest.php:33
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:38