TYPO3 CMS  TYPO3_7-6
ViewHelperVariableContainerTest.php
Go to the documentation of this file.
1 <?php
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 
18 {
23 
24  protected function setUp()
25  {
26  $this->viewHelperVariableContainer = new \TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer();
27  }
28 
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 
47  {
48  $this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey');
49  }
50 
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 
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 
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 
86  {
87  $this->viewHelperVariableContainer->remove('TYPO3\\CMS\\Fluid\\ViewHelper\\NonExistent', 'nonExistentKey');
88  }
89 
93  public function viewCanBeReadOutAgain()
94  {
95  $view = $this->getMock(\TYPO3\CMS\Fluid\View\AbstractTemplateView::class, ['getTemplateSource', 'getLayoutSource', 'getPartialSource', 'hasTemplate', 'canRender', 'getTemplateIdentifier', 'getLayoutIdentifier', 'getPartialIdentifier']);
96  $this->viewHelperVariableContainer->setView($view);
97  $this->assertSame($view, $this->viewHelperVariableContainer->getView());
98  }
99 
104  {
105  $this->assertFalse($this->viewHelperVariableContainer->exists('TYPO3\Fluid\ViewHelper\NonExistent', 'nonExistentKey'));
106  }
107 
112  {
113  $this->viewHelperVariableContainer->add('TYPO3\Fluid\ViewHelper\NonExistent', 'someKey', 'someValue');
114  $this->assertTrue($this->viewHelperVariableContainer->exists('TYPO3\Fluid\ViewHelper\NonExistent', 'someKey'));
115  }
116 
121  {
122  $this->viewHelperVariableContainer->add('TYPO3\Fluid\ViewHelper\NonExistent', 'someKey', null);
123  $this->assertTrue($this->viewHelperVariableContainer->exists('TYPO3\Fluid\ViewHelper\NonExistent', 'someKey'));
124  }
125 }