[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Be / IfHasRoleViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Be;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * Testcase for be.security.ifHasRole view helper
21 */
22 class IfHasRoleViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase {
23
24 /**
25 * @var \TYPO3\CMS\Fluid\ViewHelpers\Be\Security\IfAuthenticatedViewHelper
26 */
27 protected $viewHelper;
28
29 public function setUp() {
30 parent::setUp();
31 $GLOBALS['BE_USER'] = new \stdClass();
32 $GLOBALS['BE_USER']->userGroups = array(
33 array(
34 'uid' => 1,
35 'title' => 'Editor'
36 ),
37 array(
38 'uid' => 2,
39 'title' => 'OtherRole'
40 )
41 );
42 $this->viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\Security\\IfHasRoleViewHelper', array('renderThenChild', 'renderElseChild'));
43 $this->viewHelper->expects($this->any())->method('renderThenChild')->will($this->returnValue('then child'));
44 $this->viewHelper->expects($this->any())->method('renderElseChild')->will($this->returnValue('else child'));
45 $this->injectDependenciesIntoViewHelper($this->viewHelper);
46 $this->viewHelper->initializeArguments();
47 }
48
49 /**
50 * @test
51 */
52 public function viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIsLoggedIn() {
53 $actualResult = $this->viewHelper->render('Editor');
54 $this->assertEquals('then child', $actualResult);
55 }
56
57 /**
58 * @test
59 */
60 public function viewHelperRendersThenChildIfBeUserWithSpecifiedRoleIdIsLoggedIn() {
61 $actualResult = $this->viewHelper->render(1);
62 $this->assertEquals('then child', $actualResult);
63 }
64
65 /**
66 * @test
67 */
68 public function viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIsNotLoggedIn() {
69 $actualResult = $this->viewHelper->render('editor');
70 $this->assertEquals('else child', $actualResult);
71 }
72
73 /**
74 * @test
75 */
76 public function viewHelperRendersElseChildIfBeUserWithSpecifiedRoleIdIsNotLoggedIn() {
77 $actualResult = $this->viewHelper->render(123);
78 $this->assertEquals('else child', $actualResult);
79 }
80 }