|
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 /** 00024 * Testcase for TagBuilder 00025 * 00026 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00027 */ 00028 class Tx_Fluid_Tests_Unit_Core_ViewHelper_TagBuilderTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00029 00030 /** 00031 * @test 00032 * @author Bastian Waidelich <bastian@typo3.org> 00033 */ 00034 public function constructorSetsTagName() { 00035 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('someTagName'); 00036 $this->assertEquals('someTagName', $tagBuilder->getTagName()); 00037 } 00038 00039 /** 00040 * @test 00041 * @author Bastian Waidelich <bastian@typo3.org> 00042 */ 00043 public function constructorSetsTagContent() { 00044 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('', '<some text>'); 00045 $this->assertEquals('<some text>', $tagBuilder->getContent()); 00046 } 00047 00048 /** 00049 * @test 00050 * @author Bastian Waidelich <bastian@typo3.org> 00051 */ 00052 public function setContentDoesNotEscapeValue() { 00053 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder(); 00054 $tagBuilder->setContent('<to be escaped>', FALSE); 00055 $this->assertEquals('<to be escaped>', $tagBuilder->getContent()); 00056 } 00057 00058 /** 00059 * @test 00060 * @author Bastian Waidelich <bastian@typo3.org> 00061 */ 00062 public function hasContentReturnsTrueIfTagContainsText() { 00063 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('', 'foo'); 00064 $this->assertTrue($tagBuilder->hasContent()); 00065 } 00066 00067 /** 00068 * @test 00069 * @author Bastian Waidelich <bastian@typo3.org> 00070 */ 00071 public function hasContentReturnsFalseIfContentIsNull() { 00072 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder(); 00073 $tagBuilder->setContent(NULL); 00074 $this->assertFalse($tagBuilder->hasContent()); 00075 } 00076 00077 /** 00078 * @test 00079 * @author Bastian Waidelich <bastian@typo3.org> 00080 */ 00081 public function hasContentReturnsFalseIfContentIsAnEmptyString() { 00082 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder(); 00083 $tagBuilder->setContent(''); 00084 $this->assertFalse($tagBuilder->hasContent()); 00085 } 00086 00087 /** 00088 * @test 00089 * @author Bastian Waidelich <bastian@typo3.org> 00090 */ 00091 public function renderReturnsEmptyStringByDefault() { 00092 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder(); 00093 $this->assertEquals('', $tagBuilder->render()); 00094 } 00095 00096 /** 00097 * @test 00098 * @author Bastian Waidelich <bastian@typo3.org> 00099 */ 00100 public function renderReturnsSelfClosingTagIfNoContentIsSpecified() { 00101 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('tag'); 00102 $this->assertEquals('<tag />', $tagBuilder->render()); 00103 } 00104 00105 /** 00106 * @test 00107 * @author Bastian Waidelich <bastian@typo3.org> 00108 */ 00109 public function contentCanBeRemoved() { 00110 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('tag', 'some content'); 00111 $tagBuilder->setContent(NULL); 00112 $this->assertEquals('<tag />', $tagBuilder->render()); 00113 } 00114 00115 /** 00116 * @test 00117 * @author Bastian Waidelich <bastian@typo3.org> 00118 */ 00119 public function renderReturnsOpeningAndClosingTagIfNoContentIsSpecifiedButForceClosingTagIsTrue() { 00120 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('tag'); 00121 $tagBuilder->forceClosingTag(TRUE); 00122 $this->assertEquals('<tag></tag>', $tagBuilder->render()); 00123 } 00124 00125 /** 00126 * @test 00127 * @author Bastian Waidelich <bastian@typo3.org> 00128 */ 00129 public function attributesAreProperlyRendered() { 00130 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('tag'); 00131 $tagBuilder->addAttribute('attribute1', 'attribute1value'); 00132 $tagBuilder->addAttribute('attribute2', 'attribute2value'); 00133 $tagBuilder->addAttribute('attribute3', 'attribute3value'); 00134 $this->assertEquals('<tag attribute1="attribute1value" attribute2="attribute2value" attribute3="attribute3value" />', $tagBuilder->render()); 00135 } 00136 00137 /** 00138 * @test 00139 * @author Bastian Waidelich <bastian@typo3.org> 00140 */ 00141 public function attributeValuesAreEscapedByDefault() { 00142 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('tag'); 00143 $tagBuilder->addAttribute('foo', '<to be escaped>'); 00144 $this->assertEquals('<tag foo="<to be escaped>" />', $tagBuilder->render()); 00145 } 00146 00147 /** 00148 * @test 00149 * @author Bastian Waidelich <bastian@typo3.org> 00150 */ 00151 public function attributeValuesAreNotEscapedIfDisabled() { 00152 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('tag'); 00153 $tagBuilder->addAttribute('foo', '<not to be escaped>', FALSE); 00154 $this->assertEquals('<tag foo="<not to be escaped>" />', $tagBuilder->render()); 00155 } 00156 00157 /** 00158 * @test 00159 * @author Bastian Waidelich <bastian@typo3.org> 00160 */ 00161 public function attributesCanBeRemoved() { 00162 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('tag'); 00163 $tagBuilder->addAttribute('attribute1', 'attribute1value'); 00164 $tagBuilder->addAttribute('attribute2', 'attribute2value'); 00165 $tagBuilder->addAttribute('attribute3', 'attribute3value'); 00166 $tagBuilder->removeAttribute('attribute2'); 00167 $this->assertEquals('<tag attribute1="attribute1value" attribute3="attribute3value" />', $tagBuilder->render()); 00168 } 00169 00170 /** 00171 * @test 00172 * @author Bastian Waidelich <bastian@typo3.org> 00173 */ 00174 public function resetResetsTagBuilder() { 00175 $tagBuilder = $this->getAccessibleMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('dummy')); 00176 $tagBuilder->setTagName('tagName'); 00177 $tagBuilder->setContent('some content'); 00178 $tagBuilder->forceClosingTag(TRUE); 00179 $tagBuilder->addAttribute('attribute1', 'attribute1value'); 00180 $tagBuilder->addAttribute('attribute2', 'attribute2value'); 00181 $tagBuilder->reset(); 00182 00183 $this->assertEquals('', $tagBuilder->_get('tagName')); 00184 $this->assertEquals('', $tagBuilder->_get('content')); 00185 $this->assertEquals(array(), $tagBuilder->_get('attributes')); 00186 $this->assertFalse($tagBuilder->_get('forceClosingTag')); 00187 } 00188 00189 /** 00190 * @test 00191 * @author Bastian Waidelich <bastian@typo3.org> 00192 */ 00193 public function tagNameCanBeOverridden() { 00194 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('foo'); 00195 $tagBuilder->setTagName('bar'); 00196 $this->assertEquals('<bar />', $tagBuilder->render()); 00197 } 00198 00199 /** 00200 * @test 00201 * @author Bastian Waidelich <bastian@typo3.org> 00202 */ 00203 public function tagContentCanBeOverridden() { 00204 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('foo', 'some content'); 00205 $tagBuilder->setContent(''); 00206 $this->assertEquals('<foo />', $tagBuilder->render()); 00207 } 00208 00209 /** 00210 * @test 00211 * @author Bastian Waidelich <bastian@typo3.org> 00212 */ 00213 public function tagIsNotRenderedIfTagNameIsEmpty() { 00214 $tagBuilder = new Tx_Fluid_Core_ViewHelper_TagBuilder('foo'); 00215 $tagBuilder->setTagName(''); 00216 $this->assertEquals('', $tagBuilder->render()); 00217 } 00218 } 00219 00220 ?>
1.8.0