|
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__) . '/../../ViewHelpers/ViewHelperBaseTestcase.php'); 00024 00025 /** 00026 * Testcase for Condition ViewHelper 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_Core_ViewHelper_AbstractConditionViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase { 00031 00032 /** 00033 * var Tx_Fluid_Core_ViewHelper_AbstractConditionViewHelper 00034 */ 00035 protected $viewHelper; 00036 00037 /** 00038 * var Tx_Fluid_Core_ViewHelper_Arguments 00039 */ 00040 protected $mockArguments; 00041 00042 public function setUp() { 00043 parent::setUp(); 00044 $this->viewHelper = $this->getAccessibleMock('Tx_Fluid_Core_ViewHelper_AbstractConditionViewHelper', array('getRenderingContext', 'renderChildren')); 00045 $this->viewHelper->expects($this->any())->method('getRenderingContext')->will($this->returnValue($this->renderingContext)); 00046 $this->injectDependenciesIntoViewHelper($this->viewHelper); 00047 } 00048 00049 /** 00050 * @test 00051 * @author Bastian Waidelich <bastian@typo3.org> 00052 * @author Sebastian Kurfürst <sebastian@typo3.org> 00053 */ 00054 public function renderThenChildReturnsAllChildrenIfNoThenViewHelperChildExists() { 00055 $this->viewHelper->expects($this->at(0))->method('renderChildren')->will($this->returnValue('foo')); 00056 00057 $actualResult = $this->viewHelper->_call('renderThenChild'); 00058 $this->assertEquals('foo', $actualResult); 00059 } 00060 00061 /** 00062 * @test 00063 * @author Bastian Waidelich <bastian@typo3.org> 00064 * @author Sebastian Kurfürst <sebastian@typo3.org> 00065 */ 00066 public function renderThenChildReturnsThenViewHelperChildIfConditionIsTrueAndThenViewHelperChildExists() { 00067 $mockThenViewHelperNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode', array('getViewHelperClassName', 'evaluate'), array(), '', FALSE); 00068 $mockThenViewHelperNode->expects($this->at(0))->method('getViewHelperClassName')->will($this->returnValue('Tx_Fluid_ViewHelpers_ThenViewHelper')); 00069 $mockThenViewHelperNode->expects($this->at(1))->method('evaluate')->with($this->renderingContext)->will($this->returnValue('ThenViewHelperResults')); 00070 00071 $this->viewHelper->setChildNodes(array($mockThenViewHelperNode)); 00072 $actualResult = $this->viewHelper->_call('renderThenChild'); 00073 $this->assertEquals('ThenViewHelperResults', $actualResult); 00074 } 00075 00076 /** 00077 * @test 00078 * @author Bastian Waidelich <bastian@typo3.org> 00079 */ 00080 public function renderElseChildReturnsEmptyStringIfConditionIsFalseAndNoElseViewHelperChildExists() { 00081 $actualResult = $this->viewHelper->_call('renderElseChild'); 00082 $this->assertEquals('', $actualResult); 00083 } 00084 00085 /** 00086 * @test 00087 * @author Bastian Waidelich <bastian@typo3.org> 00088 */ 00089 public function renderElseChildRendersElseViewHelperChildIfConditionIsFalseAndNoThenViewHelperChildExists() { 00090 $mockElseViewHelperNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode', array('getViewHelperClassName', 'evaluate', 'setRenderingContext'), array(), '', FALSE); 00091 $mockElseViewHelperNode->expects($this->at(0))->method('getViewHelperClassName')->will($this->returnValue('Tx_Fluid_ViewHelpers_ElseViewHelper')); 00092 $mockElseViewHelperNode->expects($this->at(1))->method('evaluate')->with($this->renderingContext)->will($this->returnValue('ElseViewHelperResults')); 00093 00094 $this->viewHelper->setChildNodes(array($mockElseViewHelperNode)); 00095 $actualResult = $this->viewHelper->_call('renderElseChild'); 00096 $this->assertEquals('ElseViewHelperResults', $actualResult); 00097 } 00098 00099 /** 00100 * @test 00101 * @author Bastian Waidelich <bastian@typo3.org> 00102 */ 00103 public function renderThenChildReturnsValueOfThenArgumentIfConditionIsTrue() { 00104 $this->arguments->expects($this->atLeastOnce())->method('hasArgument')->with('then')->will($this->returnValue(TRUE)); 00105 $this->arguments->expects($this->atLeastOnce())->method('offsetGet')->with('then')->will($this->returnValue('ThenArgument')); 00106 00107 $actualResult = $this->viewHelper->_call('renderThenChild'); 00108 $this->assertEquals('ThenArgument', $actualResult); 00109 } 00110 00111 /** 00112 * @test 00113 * @author Bastian Waidelich <bastian@typo3.org> 00114 */ 00115 public function thenArgumentHasPriorityOverChildNodesIfConditionIsTrue() { 00116 $mockRenderingContext = $this->getMock('Tx_Fluid_Core_Rendering_RenderingContextInterface'); 00117 00118 $mockThenViewHelperNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode', array('getViewHelperClassName', 'evaluate', 'setRenderingContext'), array(), '', FALSE); 00119 $mockThenViewHelperNode->expects($this->never())->method('evaluate'); 00120 00121 $this->viewHelper->setChildNodes(array($mockThenViewHelperNode)); 00122 $this->viewHelper->setRenderingContext($mockRenderingContext); 00123 00124 $this->arguments->expects($this->atLeastOnce())->method('hasArgument')->with('then')->will($this->returnValue(TRUE)); 00125 $this->arguments->expects($this->atLeastOnce())->method('offsetGet')->with('then')->will($this->returnValue('ThenArgument')); 00126 00127 $actualResult = $this->viewHelper->_call('renderThenChild'); 00128 $this->assertEquals('ThenArgument', $actualResult); 00129 } 00130 00131 /** 00132 * @test 00133 * @author Bastian Waidelich <bastian@typo3.org> 00134 */ 00135 public function renderReturnsValueOfElseArgumentIfConditionIsFalse() { 00136 $this->arguments->expects($this->atLeastOnce())->method('hasArgument')->with('else')->will($this->returnValue(TRUE)); 00137 $this->arguments->expects($this->atLeastOnce())->method('offsetGet')->with('else')->will($this->returnValue('ElseArgument')); 00138 00139 $actualResult = $this->viewHelper->_call('renderElseChild'); 00140 $this->assertEquals('ElseArgument', $actualResult); 00141 } 00142 00143 /** 00144 * @test 00145 * @author Bastian Waidelich <bastian@typo3.org> 00146 */ 00147 public function elseArgumentHasPriorityOverChildNodesIfConditionIsFalse() { 00148 $mockRenderingContext = $this->getMock('Tx_Fluid_Core_Rendering_RenderingContextInterface'); 00149 00150 $mockElseViewHelperNode = $this->getMock('Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode', array('getViewHelperClassName', 'evaluate', 'setRenderingContext'), array(), '', FALSE); 00151 $mockElseViewHelperNode->expects($this->never())->method('evaluate'); 00152 00153 $this->viewHelper->setChildNodes(array($mockElseViewHelperNode)); 00154 $this->viewHelper->setRenderingContext($mockRenderingContext); 00155 00156 $this->arguments->expects($this->atLeastOnce())->method('hasArgument')->with('else')->will($this->returnValue(TRUE)); 00157 $this->arguments->expects($this->atLeastOnce())->method('offsetGet')->with('else')->will($this->returnValue('ElseArgument')); 00158 00159 $actualResult = $this->viewHelper->_call('renderElseChild'); 00160 $this->assertEquals('ElseArgument', $actualResult); 00161 } 00162 00163 } 00164 00165 ?>
1.8.0