/** * @test * @author Bastian Waidelich <*****@*****.**> */ public function iterationDataIsAddedToTemplateVariableContainerIfIterationArgumentIsSet() { $viewHelper = new Tx_Fluid_ViewHelpers_ForViewHelper(); $mockViewHelperNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode', array('evaluateChildNodes'), array(), '', FALSE); $mockViewHelperNode->expects($this->any())->method('evaluateChildNodes')->will($this->returnValue('foo')); $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'bar'); $this->templateVariableContainer->expects($this->at(1))->method('add')->with('iteration', array('index' => 0, 'cycle' => 1, 'total' => 3, 'isFirst' => TRUE, 'isLast' => FALSE, 'isEven' => FALSE, 'isOdd' => TRUE)); $this->templateVariableContainer->expects($this->at(2))->method('remove')->with('innerVariable'); $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('iteration'); $this->templateVariableContainer->expects($this->at(4))->method('add')->with('innerVariable', 'Fluid'); $this->templateVariableContainer->expects($this->at(5))->method('add')->with('iteration', array('index' => 1, 'cycle' => 2, 'total' => 3, 'isFirst' => FALSE, 'isLast' => FALSE, 'isEven' => TRUE, 'isOdd' => FALSE)); $this->templateVariableContainer->expects($this->at(6))->method('remove')->with('innerVariable'); $this->templateVariableContainer->expects($this->at(7))->method('remove')->with('iteration'); $this->templateVariableContainer->expects($this->at(8))->method('add')->with('innerVariable', 'rocks'); $this->templateVariableContainer->expects($this->at(9))->method('add')->with('iteration', array('index' => 2, 'cycle' => 3, 'total' => 3, 'isFirst' => FALSE, 'isLast' => TRUE, 'isEven' => FALSE, 'isOdd' => TRUE)); $this->templateVariableContainer->expects($this->at(10))->method('remove')->with('innerVariable'); $this->templateVariableContainer->expects($this->at(11))->method('remove')->with('iteration'); $viewHelper->setTemplateVariableContainer($this->templateVariableContainer); $viewHelper->setRenderingContext($this->renderingContext); $viewHelper->setViewHelperNode($mockViewHelperNode); $viewHelper->render(array('foo' => 'bar', 'FLOW3' => 'Fluid', 'TYPO3' => 'rocks'), 'innerVariable', '', FALSE, 'iteration'); }
/** * @test * @author Bastian Waidelich <*****@*****.**> */ public function keyContainsTheNumericalIndexWhenIteratingThroughElementsOfObjectsOfTyeSplObjectStorage() { $viewHelper = new Tx_Fluid_ViewHelpers_ForViewHelper(); $variableContainer = new Tx_Fluid_Core_ViewHelper_TemplateVariableContainer(array()); $viewHelperNode = new Tx_Fluid_ViewHelpers_Fixtures_ConstraintSyntaxTreeNode($variableContainer); $viewHelper->setTemplateVariableContainer($variableContainer); $viewHelper->setViewHelperNode($viewHelperNode); $splObjectStorageObject = new SplObjectStorage(); $object1 = new stdClass(); $splObjectStorageObject->attach($object1); $object2 = new stdClass(); $splObjectStorageObject->attach($object2); $object3 = new stdClass(); $splObjectStorageObject->attach($object3); $viewHelper->render($splObjectStorageObject, 'innerVariable', 'someKey'); $expectedCallProtocol = array(array('innerVariable' => $object1, 'someKey' => 0), array('innerVariable' => $object2, 'someKey' => 1), array('innerVariable' => $object3, 'someKey' => 2)); $this->assertSame($expectedCallProtocol, $viewHelperNode->callProtocol, 'The call protocol differs -> The for loop does not work as it should!'); }