TYPO3  7.6
CaseViewHelperTest.php
Go to the documentation of this file.
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 
18 {
22  protected $viewHelper;
23 
24  protected function setUp()
25  {
26  parent::setUp();
27  $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\CaseViewHelper::class, array('buildRenderChildrenClosure'));
28  $this->viewHelper->expects($this->any())->method('buildRenderChildrenClosure')->will($this->returnValue(function () {
29  return 'ChildNodes';
30  }));
31  $this->injectDependenciesIntoViewHelper($this->viewHelper);
32  $this->viewHelper->initializeArguments();
33  }
34 
40  {
41  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(false));
42  $this->viewHelper->render('foo');
43  }
44 
49  {
50  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(true));
51  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(array(array(
52  'break' => false,
53  'expression' => 'someValue'
54  ))));
55 
56  $renderedChildNodes = 'ChildNodes';
57 
58  $this->assertSame($renderedChildNodes, $this->viewHelper->render('someValue'));
59  }
60 
65  {
66  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(true));
67  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(array(array(
68  'break' => false,
69  'expression' => 'someValue'
70  ))));
71 
72  $this->viewHelperVariableContainer->expects($this->once())->method('addOrUpdate')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack', array(array(
73  'break' => true,
74  'expression' => 'someValue'
75  )));
76 
77  $this->viewHelper->render('someValue');
78  }
79 
84  {
85  $numericValue = 123;
86  $stringValue = '123';
87 
88  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(true));
89  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(array(array(
90  'break' => false,
91  'expression' => $numericValue
92  ))));
93 
94  $this->viewHelperVariableContainer->expects($this->once())->method('addOrUpdate')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack', array(array(
95  'break' => true,
96  'expression' => $numericValue
97  )));
98 
99  $this->viewHelper->render($stringValue);
100  }
101 
102 
107  {
108  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(true));
109  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(array(array(
110  'break' => false,
111  'expression' => 'someValue'
112  ))));
113 
114  $this->assertSame('', $this->viewHelper->render('someOtherValue'));
115  }
116 
121  {
122  $this->viewHelperVariableContainer->expects(
123  $this->atLeastOnce())
124  ->method('exists')
125  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
126  ->will($this->returnValue(true)
127  );
128  $this->viewHelperVariableContainer->expects(
129  $this->atLeastOnce())->method('get')
130  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
131  ->will($this->returnValue(array(array(
132  'break' => false,
133  'expression' => 'someExpression'
134  )))
135  );
136 
137  $renderedChildNodes = 'ChildNodes';
138  $this->viewHelper->expects($this->once())->method('buildRenderChildrenClosure')->will($this->returnValue(function () {
139  return 'ChildNodes';
140  }));
141 
142  $this->assertSame($renderedChildNodes, $this->viewHelper->render(null, true));
143  }
144 
150  {
151  $this->viewHelperVariableContainer->expects(
152  $this->atLeastOnce())
153  ->method('exists')
154  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
155  ->will($this->returnValue(true)
156  );
157  $this->viewHelperVariableContainer->expects($this->never())->method('get');
158 
159  $this->viewHelper->render(null, false);
160  }
161 
166  {
167  $this->viewHelperVariableContainer->expects(
168  $this->atLeastOnce())
169  ->method('exists')
170  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
171  ->will($this->returnValue(true)
172  );
173  $this->viewHelperVariableContainer->expects(
174  $this->atLeastOnce())->method('get')
175  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
176  ->will($this->returnValue(array(array(
177  'break' => false,
178  'expression' => 'someValue'
179  )))
180  );
181 
182  $renderedChildNodes = 'ChildNodes';
183 
184  $this->assertSame($renderedChildNodes, $this->viewHelper->render('someOtherValue', true));
185  }
186 }