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