Raised Extbase and Fluid to version 1.3.0
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / AliasViewHelperTest.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 require_once(dirname(__FILE__) . '/ViewHelperBaseTestcase.php');
24
25 /**
26 * Testcase for AliasViewHelper
27 *
28 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 */
30 class Tx_Fluid_Tests_Unit_ViewHelpers_AliasViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
31
32 /**
33 * @test
34 * @author Bastian Waidelich <bastian@typo3.org>
35 */
36 public function renderAddsSingleValueToTemplateVariableContainerAndRemovesItAfterRendering() {
37 $viewHelper = new Tx_Fluid_ViewHelpers_AliasViewHelper();
38
39 $mockViewHelperNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode', array('evaluateChildNodes'), array(), '', FALSE);
40 $mockViewHelperNode->expects($this->once())->method('evaluateChildNodes')->will($this->returnValue('foo'));
41
42 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('someAlias', 'someValue');
43 $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('someAlias');
44
45 $viewHelper->setTemplateVariableContainer($this->templateVariableContainer);
46 $viewHelper->setViewHelperNode($mockViewHelperNode);
47 $viewHelper->setRenderingContext($this->renderingContext);
48 $viewHelper->render(array('someAlias' => 'someValue'));
49 }
50
51 /**
52 * @test
53 * @author Bastian Waidelich <bastian@typo3.org>
54 */
55 public function renderAddsMultipleValuesToTemplateVariableContainerAndRemovesThemAfterRendering() {
56 $viewHelper = new Tx_Fluid_ViewHelpers_AliasViewHelper();
57
58 $mockViewHelperNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode', array('evaluateChildNodes'), array(), '', FALSE);
59 $mockViewHelperNode->expects($this->once())->method('evaluateChildNodes')->will($this->returnValue('foo'));
60
61 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('someAlias', 'someValue');
62 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('someOtherAlias', 'someOtherValue');
63 $this->templateVariableContainer->expects($this->at(2))->method('remove')->with('someAlias');
64 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('someOtherAlias');
65
66 $viewHelper->setTemplateVariableContainer($this->templateVariableContainer);
67 $viewHelper->setViewHelperNode($mockViewHelperNode);
68 $viewHelper->setRenderingContext($this->renderingContext);
69 $viewHelper->render(array('someAlias' => 'someValue', 'someOtherAlias' => 'someOtherValue'));
70 }
71
72 /**
73 * @test
74 * @author Bastian Waidelich <bastian@typo3.org>
75 */
76 public function renderDoesNotTouchTemplateVariableContainerAndReturnsChildNodesIfMapIsEmpty() {
77 $viewHelper = new Tx_Fluid_ViewHelpers_AliasViewHelper();
78
79 $mockViewHelperNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode', array('evaluateChildNodes'), array(), '', FALSE);
80 $mockViewHelperNode->expects($this->once())->method('evaluateChildNodes')->will($this->returnValue('foo'));
81
82 $this->templateVariableContainer->expects($this->never())->method('add');
83 $this->templateVariableContainer->expects($this->never())->method('remove');
84
85 $viewHelper->setTemplateVariableContainer($this->templateVariableContainer);
86 $viewHelper->setViewHelperNode($mockViewHelperNode);
87 $viewHelper->setRenderingContext($this->renderingContext);
88
89 $this->assertEquals('foo', $viewHelper->render(array()));
90 }
91 }
92
93
94
95 ?>