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