‪TYPO3CMS  ‪main
IfHasRoleViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 use TYPO3Fluid\Fluid\View\TemplateView;
24 
25 final class ‪IfHasRoleViewHelperTest extends FunctionalTestCase
26 {
27  protected bool ‪$initializeDatabase = false;
28 
29  protected function ‪setUp(): void
30  {
31  parent::setUp();
32  ‪$GLOBALS['BE_USER'] = new \stdClass();
33  ‪$GLOBALS['BE_USER']->userGroups = [
34  [
35  'uid' => 1,
36  'title' => 'Editor',
37  ],
38  [
39  'uid' => 2,
40  'title' => 'OtherRole',
41  ],
42  ];
43  }
44 
45  #[Test]
47  {
48  $context = $this->get(RenderingContextFactory::class)->create();
49  $context->getTemplatePaths()->setTemplateSource(
50  '<f:be.security.ifHasRole role="1"><f:then>then child</f:then><f:else>else child</f:else></f:be.security.ifHasRole>'
51  );
52  self::assertEquals('then child', (new TemplateView($context))->render());
53  }
54 
55  #[Test]
57  {
58  $context = $this->get(RenderingContextFactory::class)->create();
59  $context->getTemplatePaths()->setTemplateSource(
60  '<f:be.security.ifHasRole role="NonExistingRole"><f:then>then child</f:then><f:else>else child</f:else></f:be.security.ifHasRole>'
61  );
62  self::assertEquals('else child', (new TemplateView($context))->render());
63  }
64 
65  #[Test]
67  {
68  $context = $this->get(RenderingContextFactory::class)->create();
69  $context->getTemplatePaths()->setTemplateSource(
70  '<f:be.security.ifHasRole role="123"><f:then>then child</f:then><f:else>else child</f:else></f:be.security.ifHasRole>'
71  );
72  self::assertEquals('else child', (new TemplateView($context))->render());
73  }
74 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIsLoggedIn
‪viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIsLoggedIn()
Definition: IfHasRoleViewHelperTest.php:46
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Security
Definition: IfAuthenticatedViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIsNotLoggedIn
‪viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIsNotLoggedIn()
Definition: IfHasRoleViewHelperTest.php:56
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIdIsNotLoggedIn
‪viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIdIsNotLoggedIn()
Definition: IfHasRoleViewHelperTest.php:66
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Security\IfHasRoleViewHelperTest
Definition: IfHasRoleViewHelperTest.php:26
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\setUp
‪setUp()
Definition: IfHasRoleViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\Security\IfHasRoleViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: IfHasRoleViewHelperTest.php:27