18427e6861d5dda9f13a801c76c917a843044c7b
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / CaseViewHelperTest.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 General Public License, either version 3 of the *
9 * License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 /**
15 * Testcase for CaseViewHelper
16 */
17 class CaseViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase {
18
19 /**
20 * @var \TYPO3\CMS\Fluid\ViewHelpers\CaseViewHelper
21 */
22 protected $viewHelper;
23
24 public function setUp() {
25 parent::setUp();
26 $this->viewHelper = $this->getMock('TYPO3\CMS\Fluid\ViewHelpers\CaseViewHelper', array('renderChildren'));
27 $this->injectDependenciesIntoViewHelper($this->viewHelper);
28 $this->viewHelper->initializeArguments();
29 }
30
31 /**
32 * @test
33 * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
34 */
35 public function renderThrowsExceptionIfSwitchExpressionIsNotSetInViewHelperVariableContainer() {
36 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue(FALSE));
37 $this->viewHelper->render('foo');
38 }
39
40 /**
41 * @test
42 */
43 public function renderReturnsChildNodesIfTheSpecifiedValueIsEqualToTheSwitchExpression() {
44 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue(TRUE));
45 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue('someValue'));
46
47 $renderedChildNodes = 'ChildNodes';
48 $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($renderedChildNodes));
49
50 $this->assertSame($renderedChildNodes, $this->viewHelper->render('someValue'));
51 }
52
53 /**
54 * @test
55 */
56 public function renderSetsBreakStateInViewHelperVariableContainerIfTheSpecifiedValueIsEqualToTheSwitchExpression() {
57 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue(TRUE));
58 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue('someValue'));
59
60 $this->viewHelperVariableContainer->expects($this->once())->method('addOrUpdate')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'break', TRUE);
61
62 $this->viewHelper->render('someValue');
63 }
64
65 /**
66 * @test
67 */
68 public function renderWeaklyComparesSpecifiedValueWithSwitchExpression() {
69 $numericValue = 123;
70 $stringValue = '123';
71
72 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue(TRUE));
73 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue($numericValue));
74
75 $this->viewHelperVariableContainer->expects($this->once())->method('addOrUpdate')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'break', TRUE);
76
77 $this->viewHelper->render($stringValue);
78 }
79
80
81 /**
82 * @test
83 */
84 public function renderReturnsAnEmptyStringIfTheSpecifiedValueIsNotEqualToTheSwitchExpression() {
85 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue(TRUE));
86 $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with('TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper', 'switchExpression')->will($this->returnValue('someValue'));
87 $this->assertSame('', $this->viewHelper->render('someOtherValue'));
88 }
89
90 }