‪TYPO3CMS  10.4
IfAuthenticatedViewHelperTest.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 ‪IfAuthenticatedViewHelperTest 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  $this->viewHelper = new ‪IfAuthenticatedViewHelper();
46  $this->injectDependenciesIntoViewHelper($this->viewHelper);
47  $this->viewHelper->initializeArguments();
48  }
49 
50  protected function ‪tearDown(): void
51  {
52  GeneralUtility::removeSingletonInstance(Context::class, $this->context);
53  parent::tearDown();
54  }
55 
60  {
61  $user = new FrontendUserAuthentication();
62  $user->user['uid'] = 13;
63  $this->context->setAspect('frontend.user', new UserAspect($user));
64 
65  $actualResult = $this->viewHelper->renderStatic(
66  ['then' => 'then child', 'else' => 'else child'],
67  function () {
68  },
69  $this->prophesize(RenderingContextInterface::class)->reveal()
70  );
71 
72  self::assertEquals('then child', $actualResult);
73  }
74 
79  {
80  $this->context->setAspect('frontend.user', new UserAspect());
81 
82  $actualResult = $this->viewHelper->renderStatic(
83  ['then' => 'then child', 'else' => 'else child'],
84  function () {
85  },
86  $this->prophesize(RenderingContextInterface::class)->reveal()
87  );
88 
89  self::assertEquals('else child', $actualResult);
90  }
91 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfAuthenticatedViewHelperTest\viewHelperRendersElseChildIfFeUserIsNotLoggedIn
‪viewHelperRendersElseChildIfFeUserIsNotLoggedIn()
Definition: IfAuthenticatedViewHelperTest.php:76
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security
Definition: IfAuthenticatedViewHelperTest.php:16
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfAuthenticatedViewHelperTest\setUp
‪setUp()
Definition: IfAuthenticatedViewHelperTest.php:39
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfAuthenticatedViewHelperTest\tearDown
‪tearDown()
Definition: IfAuthenticatedViewHelperTest.php:48
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfAuthenticatedViewHelperTest
Definition: IfAuthenticatedViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfAuthenticatedViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers Security IfAuthenticatedViewHelper $viewHelper
Definition: IfAuthenticatedViewHelperTest.php:33
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfAuthenticatedViewHelperTest\$context
‪Context $context
Definition: IfAuthenticatedViewHelperTest.php:37
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:30
‪TYPO3\CMS\Fluid\ViewHelpers\Security\IfAuthenticatedViewHelper
Definition: IfAuthenticatedViewHelper.php:58
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security\IfAuthenticatedViewHelperTest\viewHelperRendersThenChildIfFeUserIsLoggedIn
‪viewHelperRendersThenChildIfFeUserIsLoggedIn()
Definition: IfAuthenticatedViewHelperTest.php:57
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:38