TYPO3 CMS  TYPO3_7-6
CaseViewHelperTest.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 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, ['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([[
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([[
68  'break' => false,
69  'expression' => 'someValue'
70  ]]));
71 
72  $this->viewHelperVariableContainer->expects($this->once())->method('addOrUpdate')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack', [[
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([[
90  'break' => false,
91  'expression' => $numericValue
92  ]]));
93 
94  $this->viewHelperVariableContainer->expects($this->once())->method('addOrUpdate')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack', [[
95  'break' => true,
96  'expression' => $numericValue
97  ]]);
98 
99  $this->viewHelper->render($stringValue);
100  }
101 
106  {
107  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue(true));
108  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')->will($this->returnValue([[
109  'break' => false,
110  'expression' => 'someValue'
111  ]]));
112 
113  $this->assertSame('', $this->viewHelper->render('someOtherValue'));
114  }
115 
120  {
121  $this->viewHelperVariableContainer->expects(
122  $this->atLeastOnce())
123  ->method('exists')
124  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
125  ->will($this->returnValue(true)
126  );
127  $this->viewHelperVariableContainer->expects(
128  $this->atLeastOnce())->method('get')
129  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
130  ->will($this->returnValue([[
131  'break' => false,
132  'expression' => 'someExpression'
133  ]])
134  );
135 
136  $renderedChildNodes = 'ChildNodes';
137  $this->viewHelper->expects($this->once())->method('buildRenderChildrenClosure')->will($this->returnValue(function () {
138  return 'ChildNodes';
139  }));
140 
141  $this->assertSame($renderedChildNodes, $this->viewHelper->render(null, true));
142  }
143 
149  {
150  $this->viewHelperVariableContainer->expects(
151  $this->atLeastOnce())
152  ->method('exists')
153  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
154  ->will($this->returnValue(true)
155  );
156  $this->viewHelperVariableContainer->expects($this->never())->method('get');
157 
158  $this->viewHelper->render(null, false);
159  }
160 
165  {
166  $this->viewHelperVariableContainer->expects(
167  $this->atLeastOnce())
168  ->method('exists')
169  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
170  ->will($this->returnValue(true)
171  );
172  $this->viewHelperVariableContainer->expects(
173  $this->atLeastOnce())->method('get')
174  ->with(\TYPO3\CMS\Fluid\ViewHelpers\SwitchViewHelper::class, 'stateStack')
175  ->will($this->returnValue([[
176  'break' => false,
177  'expression' => 'someValue'
178  ]])
179  );
180 
181  $renderedChildNodes = 'ChildNodes';
182 
183  $this->assertSame($renderedChildNodes, $this->viewHelper->render('someOtherValue', true));
184  }
185 }
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)