[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / AliasViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
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 * Testcase for AliasViewHelper
16 */
17 class AliasViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase {
18
19 /**
20 * @test
21 */
22 public function renderAddsSingleValueToTemplateVariableContainerAndRemovesItAfterRendering() {
23 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\AliasViewHelper();
24
25 $mockViewHelperNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array('evaluateChildNodes'), array(), '', FALSE);
26 $mockViewHelperNode->expects($this->once())->method('evaluateChildNodes')->will($this->returnValue('foo'));
27
28 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('someAlias', 'someValue');
29 $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('someAlias');
30
31 $this->injectDependenciesIntoViewHelper($viewHelper);
32 $viewHelper->setViewHelperNode($mockViewHelperNode);
33 $viewHelper->render(array('someAlias' => 'someValue'));
34 }
35
36 /**
37 * @test
38 */
39 public function renderAddsMultipleValuesToTemplateVariableContainerAndRemovesThemAfterRendering() {
40 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\AliasViewHelper();
41
42 $mockViewHelperNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array('evaluateChildNodes'), array(), '', FALSE);
43 $mockViewHelperNode->expects($this->once())->method('evaluateChildNodes')->will($this->returnValue('foo'));
44
45 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('someAlias', 'someValue');
46 $this->templateVariableContainer->expects($this->at(1))->method('add')->with('someOtherAlias', 'someOtherValue');
47 $this->templateVariableContainer->expects($this->at(2))->method('remove')->with('someAlias');
48 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('someOtherAlias');
49
50 $this->injectDependenciesIntoViewHelper($viewHelper);
51 $viewHelper->setViewHelperNode($mockViewHelperNode);
52 $viewHelper->render(array('someAlias' => 'someValue', 'someOtherAlias' => 'someOtherValue'));
53 }
54
55 /**
56 * @test
57 */
58 public function renderDoesNotTouchTemplateVariableContainerAndReturnsChildNodesIfMapIsEmpty() {
59 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\AliasViewHelper();
60
61 $mockViewHelperNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array('evaluateChildNodes'), array(), '', FALSE);
62 $mockViewHelperNode->expects($this->once())->method('evaluateChildNodes')->will($this->returnValue('foo'));
63
64 $this->templateVariableContainer->expects($this->never())->method('add');
65 $this->templateVariableContainer->expects($this->never())->method('remove');
66
67 $this->injectDependenciesIntoViewHelper($viewHelper);
68 $viewHelper->setViewHelperNode($mockViewHelperNode);
69
70 $this->assertEquals('foo', $viewHelper->render(array()));
71 }
72 }