21 $this->templateVariableContainer = new \TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer(array());
22 $this->renderingContext->injectTemplateVariableContainer($this->templateVariableContainer);
24 $this->arguments[
'reverse'] = NULL;
25 $this->arguments[
'key'] =
'';
26 $this->arguments[
'iteration'] = NULL;
33 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
35 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
36 $this->arguments[
'each'] = array(0, 1, 2, 3);
37 $this->arguments[
'as'] =
'innerVariable';
40 $viewHelper->setViewHelperNode($viewHelperNode);
41 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as']);
43 $expectedCallProtocol = array(
44 array(
'innerVariable' => 0),
45 array(
'innerVariable' => 1),
46 array(
'innerVariable' => 2),
47 array(
'innerVariable' => 3)
49 $this->assertEquals($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
56 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
58 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
60 $this->arguments[
'each'] = array(
'key1' =>
'value1',
'key2' =>
'value2');
61 $this->arguments[
'as'] =
'innerVariable';
62 $this->arguments[
'key'] =
'someKey';
65 $viewHelper->setViewHelperNode($viewHelperNode);
66 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key']);
68 $expectedCallProtocol = array(
70 'innerVariable' =>
'value1',
74 'innerVariable' =>
'value2',
78 $this->assertEquals($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
85 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
87 $this->arguments[
'each'] = NULL;
88 $this->arguments[
'as'] =
'foo';
92 $this->assertEquals(
'', $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as']));
99 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
101 $this->arguments[
'each'] = array();
102 $this->arguments[
'as'] =
'foo';
106 $this->assertEquals(
'', $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as']));
113 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
115 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
117 $this->arguments[
'each'] = array(0, 1, 2, 3);
118 $this->arguments[
'as'] =
'innerVariable';
119 $this->arguments[
'reverse'] = TRUE;
122 $viewHelper->setViewHelperNode($viewHelperNode);
123 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key'], $this->arguments[
'reverse']);
125 $expectedCallProtocol = array(
126 array(
'innerVariable' => 3),
127 array(
'innerVariable' => 2),
128 array(
'innerVariable' => 1),
129 array(
'innerVariable' => 0)
131 $this->assertEquals($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
138 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
140 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
142 $this->arguments[
'each'] = array(
'key1' =>
'value1',
'key2' =>
'value2');
143 $this->arguments[
'as'] =
'innerVariable';
144 $this->arguments[
'key'] =
'someKey';
145 $this->arguments[
'reverse'] = TRUE;
148 $viewHelper->setViewHelperNode($viewHelperNode);
149 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key'], $this->arguments[
'reverse']);
151 $expectedCallProtocol = array(
153 'innerVariable' =>
'value2',
157 'innerVariable' =>
'value1',
161 $this->assertEquals($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
168 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
170 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
172 $this->arguments[
'each'] = array(
'foo',
'bar',
'baz');
173 $this->arguments[
'as'] =
'innerVariable';
174 $this->arguments[
'key'] =
'someKey';
177 $viewHelper->setViewHelperNode($viewHelperNode);
178 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key']);
180 $expectedCallProtocol = array(
182 'innerVariable' =>
'foo',
186 'innerVariable' =>
'bar',
190 'innerVariable' =>
'baz',
194 $this->assertSame($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
201 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
203 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
205 $this->arguments[
'each'] = array(
'foo',
'bar',
'baz');
206 $this->arguments[
'as'] =
'innerVariable';
207 $this->arguments[
'key'] =
'someKey';
208 $this->arguments[
'reverse'] = TRUE;
211 $viewHelper->setViewHelperNode($viewHelperNode);
212 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key'], $this->arguments[
'reverse']);
214 $expectedCallProtocol = array(
216 'innerVariable' =>
'baz',
220 'innerVariable' =>
'bar',
224 'innerVariable' =>
'foo',
228 $this->assertSame($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
236 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
237 $object = new \stdClass();
239 $this->arguments[
'each'] = $object;
240 $this->arguments[
'as'] =
'innerVariable';
241 $this->arguments[
'key'] =
'someKey';
242 $this->arguments[
'reverse'] = TRUE;
245 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key']);
253 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
255 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
257 $this->arguments[
'each'] = new \ArrayObject(array(
'key1' =>
'value1',
'key2' =>
'value2'));
258 $this->arguments[
'as'] =
'innerVariable';
261 $viewHelper->setViewHelperNode($viewHelperNode);
262 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as']);
264 $expectedCallProtocol = array(
265 array(
'innerVariable' =>
'value1'),
266 array(
'innerVariable' =>
'value2')
268 $this->assertEquals($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
275 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
277 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
279 $this->arguments[
'each'] = new \ArrayIterator(array(
'key1' =>
'value1',
'key2' =>
'value2'));
280 $this->arguments[
'as'] =
'innerVariable';
281 $this->arguments[
'key'] =
'someKey';
284 $viewHelper->setViewHelperNode($viewHelperNode);
285 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key']);
287 $expectedCallProtocol = array(
289 'innerVariable' =>
'value1',
293 'innerVariable' =>
'value2',
297 $this->assertEquals($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
304 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
306 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
308 $splObjectStorageObject = new \SplObjectStorage();
309 $object1 = new \stdClass();
310 $splObjectStorageObject->attach($object1);
311 $object2 = new \stdClass();
312 $splObjectStorageObject->attach($object2,
'foo');
313 $object3 = new \stdClass();
314 $splObjectStorageObject->attach($object3,
'bar');
316 $this->arguments[
'each'] = $splObjectStorageObject;
317 $this->arguments[
'as'] =
'innerVariable';
318 $this->arguments[
'key'] =
'someKey';
321 $viewHelper->setViewHelperNode($viewHelperNode);
322 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key']);
324 $expectedCallProtocol = array(
326 'innerVariable' => $object1,
330 'innerVariable' => $object2,
334 'innerVariable' => $object3,
338 $this->assertSame($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
345 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
347 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
349 $this->arguments[
'each'] = array(
'foo' =>
'bar',
'FLOW3' =>
'Fluid',
'TYPO3' =>
'rocks');
350 $this->arguments[
'as'] =
'innerVariable';
351 $this->arguments[
'iteration'] =
'iteration';
354 $viewHelper->setViewHelperNode($viewHelperNode);
355 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as'], $this->arguments[
'key'], $this->arguments[
'reverse'], $this->arguments[
'iteration']);
357 $expectedCallProtocol = array(
359 'innerVariable' =>
'bar',
360 'iteration' => array(
371 'innerVariable' =>
'Fluid',
372 'iteration' => array(
383 'innerVariable' =>
'rocks',
384 'iteration' => array(
395 $this->assertSame($expectedCallProtocol, $viewHelperNode->callProtocol,
'The call protocol differs -> The for loop does not work as it should!');
402 $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper();
404 $viewHelperNode = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\ConstraintSyntaxTreeNode($this->templateVariableContainer);
406 $mockItems = $this->getMock(
'ArrayObject', array(
'count'), array(),
'', FALSE);
407 $mockItems->expects($this->never())->method(
'count');
408 $this->arguments[
'each'] = $mockItems;
409 $this->arguments[
'as'] =
'innerVariable';
412 $viewHelper->setViewHelperNode($viewHelperNode);
413 $viewHelper->render($this->arguments[
'each'], $this->arguments[
'as']);
renderIteratesElementsInReverseOrderIfReverseIsTrue()
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)
keyContainsTheNumericalIndexWhenIteratingThroughElementsOfObjectsOfTyeSplObjectStorage()
iterationDataIsAddedToTemplateVariableContainerIfIterationArgumentIsSet()
renderPreservesKeysIfReverseIsTrue()
renderReturnsEmptyStringIfObjectIsNull()
iteratedItemsAreNotCountedIfIterationArgumentIsNotSet()
renderPreservesKeyWhenIteratingThroughElementsOfObjectsThatImplementIteratorInterface()
renderReturnsEmptyStringIfObjectIsEmptyArray()
keyContainsNumericalIndexIfTheGivenArrayDoesNotHaveAKey()
renderExecutesTheLoopCorrectly()
renderIteratesThroughElementsOfTraversableObjects()
renderThrowsExceptionWhenPassingObjectsToEachThatAreNotTraversable()
keyContainsNumericalIndexInAscendingOrderEvenIfReverseIsTrueIfTheGivenArrayDoesNotHaveAKey()