[TASK] Removes extra empty lines
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / ViewHelper / ViewHelperVariableContainerTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\ViewHelper;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 /**
15 * Test case
16 */
17 class ViewHelperVariableContainerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
18 {
19 /**
20 * @var \TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer
21 */
22 protected $viewHelperVariableContainer;
23
24 protected function setUp()
25 {
26 $this->viewHelperVariableContainer = new \TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer();
27 }
28
29 /**
30 * @test
31 */
32 public function storedDataCanBeReadOutAgain()
33 {
34 $variable = 'Hello world';
35 $this->assertFalse($this->viewHelperVariableContainer->exists(\TYPO3\CMS\Fluid\ViewHelpers\TestViewHelper::class, 'test'));
36 $this->viewHelperVariableContainer->add(\TYPO3\CMS\Fluid\ViewHelpers\TestViewHelper::class, 'test', $variable);
37 $this->assertTrue($this->viewHelperVariableContainer->exists(\TYPO3\CMS\Fluid\ViewHelpers\TestViewHelper::class, 'test'));
38
39 $this->assertEquals($variable, $this->viewHelperVariableContainer->get(\TYPO3\CMS\Fluid\ViewHelpers\TestViewHelper::class, 'test'));
40 }
41
42 /**
43 * @test
44 * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
45 */
46 public function gettingNonNonExistentValueThrowsException()
47 {
48 $this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey');
49 }
50
51 /**
52 * @test
53 * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
54 */
55 public function settingKeyWhichIsAlreadyStoredThrowsException()
56 {
57 $this->viewHelperVariableContainer->add('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey', 'value1');
58 $this->viewHelperVariableContainer->add('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey', 'value2');
59 }
60
61 /**
62 * @test
63 */
64 public function addOrUpdateWorks()
65 {
66 $this->viewHelperVariableContainer->add('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey', 'value1');
67 $this->viewHelperVariableContainer->addOrUpdate('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey', 'value2');
68 $this->assertEquals($this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey'), 'value2');
69 }
70
71 /**
72 * @test
73 */
74 public function aSetValueCanBeRemovedAgain()
75 {
76 $this->viewHelperVariableContainer->add('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey', 'value1');
77 $this->viewHelperVariableContainer->remove('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey');
78 $this->assertFalse($this->viewHelperVariableContainer->exists('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey'));
79 }
80
81 /**
82 * @test
83 * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
84 */
85 public function removingNonExistentKeyThrowsException()
86 {
87 $this->viewHelperVariableContainer->remove('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey');
88 }
89
90 /**
91 * @test
92 */
93 public function viewCanBeReadOutAgain()
94 {
95 $view = $this->getMock(\TYPO3\CMS\Fluid\View\AbstractTemplateView::class, array('getTemplateSource', 'getLayoutSource', 'getPartialSource', 'hasTemplate', 'canRender', 'getTemplateIdentifier', 'getLayoutIdentifier', 'getPartialIdentifier'));
96 $this->viewHelperVariableContainer->setView($view);
97 $this->assertSame($view, $this->viewHelperVariableContainer->getView());
98 }
99
100 /**
101 * @test
102 */
103 public function existsReturnsFalseIfTheSpecifiedKeyDoesNotExist()
104 {
105 $this->assertFalse($this->viewHelperVariableContainer->exists('TYPO3\Fluid\ViewHelper\NonExistent', 'nonExistentKey'));
106 }
107
108 /**
109 * @test
110 */
111 public function existsReturnsTrueIfTheSpecifiedKeyExists()
112 {
113 $this->viewHelperVariableContainer->add('TYPO3\Fluid\ViewHelper\NonExistent', 'someKey', 'someValue');
114 $this->assertTrue($this->viewHelperVariableContainer->exists('TYPO3\Fluid\ViewHelper\NonExistent', 'someKey'));
115 }
116
117 /**
118 * @test
119 */
120 public function existsReturnsTrueIfTheSpecifiedKeyExistsAndIsNull()
121 {
122 $this->viewHelperVariableContainer->add('TYPO3\Fluid\ViewHelper\NonExistent', 'someKey', null);
123 $this->assertTrue($this->viewHelperVariableContainer->exists('TYPO3\Fluid\ViewHelper\NonExistent', 'someKey'));
124 }
125 }