|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* * 00004 * This script belongs to the FLOW3 package "Fluid". * 00005 * * 00006 * It is free software; you can redistribute it and/or modify it under * 00007 * the terms of the GNU Lesser General Public License as published by the * 00008 * Free Software Foundation, either version 3 of the License, or (at your * 00009 * option) any later version. * 00010 * * 00011 * This script is distributed in the hope that it will be useful, but * 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * 00013 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the script. * 00018 * If not, see http://www.gnu.org/licenses/lgpl.html * 00019 * * 00020 * The TYPO3 project - inspiring people to share! * 00021 * */ 00022 00023 require_once(dirname(__FILE__) . '/ViewHelperBaseTestcase.php'); 00024 00025 /** 00026 * Testcase for CycleViewHelper 00027 * 00028 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00029 */ 00030 class Tx_Fluid_Tests_Unit_ViewHelpers_CycleViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase { 00031 00032 /** 00033 * var Tx_Fluid_ViewHelpers_CycleViewHelper 00034 */ 00035 protected $viewHelper; 00036 00037 public function setUp() { 00038 parent::setUp(); 00039 $this->viewHelper = $this->getMock('Tx_Fluid_ViewHelpers_CycleViewHelper', array('renderChildren')); 00040 $this->injectDependenciesIntoViewHelper($this->viewHelper); 00041 $this->viewHelper->initializeArguments(); 00042 } 00043 00044 /** 00045 * @test 00046 * @author Bastian Waidelich <bastian@typo3.org> 00047 */ 00048 public function renderAddsCurrentValueToTemplateVariableContainerAndRemovesItAfterRendering() { 00049 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'bar'); 00050 $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('innerVariable'); 00051 00052 $values = array('bar', 'Fluid'); 00053 $this->viewHelper->render($values, 'innerVariable'); 00054 } 00055 00056 /** 00057 * @test 00058 * @author Bastian Waidelich <bastian@typo3.org> 00059 */ 00060 public function renderAddsFirstValueToTemplateVariableContainerAfterLastValue() { 00061 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'bar'); 00062 $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('innerVariable'); 00063 $this->templateVariableContainer->expects($this->at(2))->method('add')->with('innerVariable', 'Fluid'); 00064 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('innerVariable'); 00065 $this->templateVariableContainer->expects($this->at(4))->method('add')->with('innerVariable', 'bar'); 00066 $this->templateVariableContainer->expects($this->at(5))->method('remove')->with('innerVariable'); 00067 00068 $values = array('bar', 'Fluid'); 00069 $this->viewHelper->render($values, 'innerVariable'); 00070 $this->viewHelper->render($values, 'innerVariable'); 00071 $this->viewHelper->render($values, 'innerVariable'); 00072 } 00073 00074 /** 00075 * @test 00076 * @author Bastian Waidelich <bastian@typo3.org> 00077 */ 00078 public function viewHelperSupportsAssociativeArrays() { 00079 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'FLOW3'); 00080 $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('innerVariable'); 00081 $this->templateVariableContainer->expects($this->at(2))->method('add')->with('innerVariable', 'Fluid'); 00082 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('innerVariable'); 00083 $this->templateVariableContainer->expects($this->at(4))->method('add')->with('innerVariable', 'FLOW3'); 00084 $this->templateVariableContainer->expects($this->at(5))->method('remove')->with('innerVariable'); 00085 00086 $values = array('foo' => 'FLOW3', 'bar' => 'Fluid'); 00087 $this->viewHelper->render($values, 'innerVariable'); 00088 $this->viewHelper->render($values, 'innerVariable'); 00089 $this->viewHelper->render($values, 'innerVariable'); 00090 } 00091 00092 /** 00093 * @test 00094 * @expectedException Tx_Fluid_Core_ViewHelper_Exception 00095 * @author Bastian Waidelich <bastian@typo3.org> 00096 */ 00097 public function renderThrowsExceptionWhenPassingObjectsToValuesThatAreNotTraversable() { 00098 $object = new stdClass(); 00099 00100 $this->viewHelper->render($object, 'innerVariable'); 00101 } 00102 00103 /** 00104 * @test 00105 * @author Bastian Waidelich <bastian@typo3.org> 00106 */ 00107 public function renderReturnsChildNodesIfValuesIsNull() { 00108 $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Child nodes')); 00109 00110 $this->assertEquals('Child nodes', $this->viewHelper->render(NULL, 'foo')); 00111 } 00112 00113 /** 00114 * @test 00115 * @author Bastian Waidelich <bastian@typo3.org> 00116 */ 00117 public function renderReturnsChildNodesIfValuesIsAnEmptyArray() { 00118 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('foo', NULL); 00119 $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('foo'); 00120 00121 $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Child nodes')); 00122 00123 $this->assertEquals('Child nodes', $this->viewHelper->render(array(), 'foo')); 00124 } 00125 00126 /** 00127 * @test 00128 * @author Bastian Waidelich <bastian@typo3.org> 00129 */ 00130 public function renderIteratesThroughElementsOfTraversableObjects() { 00131 $this->templateVariableContainer->expects($this->at(0))->method('add')->with('innerVariable', 'value1'); 00132 $this->templateVariableContainer->expects($this->at(1))->method('remove')->with('innerVariable'); 00133 $this->templateVariableContainer->expects($this->at(2))->method('add')->with('innerVariable', 'value2'); 00134 $this->templateVariableContainer->expects($this->at(3))->method('remove')->with('innerVariable'); 00135 $this->templateVariableContainer->expects($this->at(4))->method('add')->with('innerVariable', 'value1'); 00136 $this->templateVariableContainer->expects($this->at(5))->method('remove')->with('innerVariable'); 00137 00138 $traversableObject = new ArrayObject(array('key1' => 'value1', 'key2' => 'value2')); 00139 $this->viewHelper->render($traversableObject, 'innerVariable'); 00140 $this->viewHelper->render($traversableObject, 'innerVariable'); 00141 $this->viewHelper->render($traversableObject, 'innerVariable'); 00142 } 00143 } 00144 00145 ?>
1.8.0