[!!!][TASK] Drop "documentation" extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Security / IfAuthenticatedViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Security;
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
17 use TYPO3\CMS\Fluid\ViewHelpers\Security\IfAuthenticatedViewHelper;
18 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20
21 /**
22 * Testcase for security.ifAuthenticated view helper
23 */
24 class IfAuthenticatedViewHelperTest extends ViewHelperBaseTestcase
25 {
26 /**
27 * @var \TYPO3\CMS\Fluid\ViewHelpers\Security\IfAuthenticatedViewHelper
28 */
29 protected $viewHelper;
30
31 protected function setUp()
32 {
33 parent::setUp();
34 $GLOBALS['TSFE'] = new \stdClass();
35 $this->viewHelper = new IfAuthenticatedViewHelper();
36 $this->injectDependenciesIntoViewHelper($this->viewHelper);
37 $this->viewHelper->initializeArguments();
38 }
39
40 protected function tearDown()
41 {
42 unset($GLOBALS['TSFE']);
43 }
44
45 /**
46 * @test
47 */
48 public function viewHelperRendersThenChildIfFeUserIsLoggedIn()
49 {
50 $GLOBALS['TSFE']->loginUser = 1;
51
52 $actualResult = $this->viewHelper->renderStatic(
53 ['then' => 'then child', 'else' => 'else child'],
54 function () {
55 },
56 $this->prophesize(RenderingContextInterface::class)->reveal()
57 );
58
59 $this->assertEquals('then child', $actualResult);
60 }
61
62 /**
63 * @test
64 */
65 public function viewHelperRendersElseChildIfFeUserIsNotLoggedIn()
66 {
67 $GLOBALS['TSFE']->loginUser = 0;
68
69 $actualResult = $this->viewHelper->renderStatic(
70 ['then' => 'then child', 'else' => 'else child'],
71 function () {
72 },
73 $this->prophesize(RenderingContextInterface::class)->reveal()
74 );
75
76 $this->assertEquals('else child', $actualResult);
77 }
78 }