TYPO3 CMS  TYPO3_7-6
CycleViewHelperTest.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 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 
18 {
22  protected $viewHelper;
23 
24  protected function setUp()
25  {
26  parent::setUp();
27  $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\CycleViewHelper::class, ['renderChildren']);
28  $this->injectDependenciesIntoViewHelper($this->viewHelper);
29  $this->viewHelper->initializeArguments();
30  }
31 
36  {
37  $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'bar');
38  $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('innerVariable');
39 
40  $values = ['bar', 'Fluid'];
41  $this->viewHelper->render($values, 'innerVariable');
42  }
43 
48  {
49  $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'bar');
50  $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('innerVariable');
51  $this->templateVariableContainer->expects($this->at(2))->method('add')->with('innerVariable', 'Fluid');
52  $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('innerVariable');
53  $this->templateVariableContainer->expects($this->at(4))->method('add')->with('innerVariable', 'bar');
54  $this->templateVariableContainer->expects($this->at(5))->method('remove')->with('innerVariable');
55 
56  $values = ['bar', 'Fluid'];
57  $this->viewHelper->render($values, 'innerVariable');
58  $this->viewHelper->render($values, 'innerVariable');
59  $this->viewHelper->render($values, 'innerVariable');
60  }
61 
66  {
67  $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'FLOW3');
68  $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('innerVariable');
69  $this->templateVariableContainer->expects($this->at(2))->method('add')->with('innerVariable', 'Fluid');
70  $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('innerVariable');
71  $this->templateVariableContainer->expects($this->at(4))->method('add')->with('innerVariable', 'FLOW3');
72  $this->templateVariableContainer->expects($this->at(5))->method('remove')->with('innerVariable');
73 
74  $values = ['foo' => 'FLOW3', 'bar' => 'Fluid'];
75  $this->viewHelper->render($values, 'innerVariable');
76  $this->viewHelper->render($values, 'innerVariable');
77  $this->viewHelper->render($values, 'innerVariable');
78  }
79 
85  {
86  $object = new \stdClass();
87 
88  $this->viewHelper->render($object, 'innerVariable');
89  }
90 
95  {
96  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Child nodes'));
97 
98  $this->assertEquals('Child nodes', $this->viewHelper->render(null, 'foo'));
99  }
100 
105  {
106  $this->templateVariableContainer->expects($this->at(0))->method('add')->with('foo', null);
107  $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('foo');
108 
109  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Child nodes'));
110 
111  $this->assertEquals('Child nodes', $this->viewHelper->render([], 'foo'));
112  }
113 
118  {
119  $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'value1');
120  $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('innerVariable');
121  $this->templateVariableContainer->expects($this->at(2))->method('add')->with('innerVariable', 'value2');
122  $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('innerVariable');
123  $this->templateVariableContainer->expects($this->at(4))->method('add')->with('innerVariable', 'value1');
124  $this->templateVariableContainer->expects($this->at(5))->method('remove')->with('innerVariable');
125 
126  $traversableObject = new \ArrayObject(['key1' => 'value1', 'key2' => 'value2']);
127  $this->viewHelper->render($traversableObject, 'innerVariable');
128  $this->viewHelper->render($traversableObject, 'innerVariable');
129  $this->viewHelper->render($traversableObject, 'innerVariable');
130  }
131 }
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)