‪TYPO3CMS  ‪main
IfAuthenticatedViewHelperTest.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;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 use TYPO3Fluid\Fluid\View\TemplateView;
28 
29 final class ‪IfAuthenticatedViewHelperTest extends FunctionalTestCase
30 {
31  protected bool ‪$initializeDatabase = false;
32 
33  #[Test]
35  {
36  $user = new ‪FrontendUserAuthentication();
37  $user->user['uid'] = 13;
38  $context = new ‪Context();
39  $context->setAspect('frontend.user', new ‪UserAspect($user));
40  GeneralUtility::setSingletonInstance(Context::class, $context);
41 
42  $renderingContext = $this->get(RenderingContextFactory::class)->create();
43  $renderingContext->getTemplatePaths()->setTemplateSource('<f:security.ifAuthenticated><f:then>then child</f:then><f:else>else child</f:else></f:security.ifAuthenticated>');
44  self::assertEquals('then child', (new TemplateView($renderingContext))->render());
45  }
46 
47  #[Test]
49  {
50  $context = new ‪Context();
51  $context->setAspect('frontend.user', new ‪UserAspect());
52  GeneralUtility::setSingletonInstance(Context::class, $context);
53 
54  $renderingContext = $this->get(RenderingContextFactory::class)->create();
55  $renderingContext->getTemplatePaths()->setTemplateSource('<f:security.ifAuthenticated><f:then>then child</f:then><f:else>else child</f:else></f:security.ifAuthenticated>');
56  self::assertEquals('else child', (new TemplateView($renderingContext))->render());
57  }
58 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Security\IfAuthenticatedViewHelperTest\viewHelperRendersElseChildIfFeUserIsNotLoggedIn
‪viewHelperRendersElseChildIfFeUserIsNotLoggedIn()
Definition: IfAuthenticatedViewHelperTest.php:48
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Security\IfAuthenticatedViewHelperTest\viewHelperRendersThenChildIfFeUserIsLoggedIn
‪viewHelperRendersThenChildIfFeUserIsLoggedIn()
Definition: IfAuthenticatedViewHelperTest.php:34
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Security\IfAuthenticatedViewHelperTest
Definition: IfAuthenticatedViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Security
Definition: IfAuthenticatedViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Security\IfAuthenticatedViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: IfAuthenticatedViewHelperTest.php:31
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:37