| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 require_once('limb/wact/tests/cases/compiler/compile_tree_node/WactCompileTreeNodeTest.class.php'); 11 12 if(!class_exists('WactCompilerTagTest')) 13 { 14 15 class MyTagClass1CompilerTest extends WactCompilerTag{} 16 17 class MyTagClass2CompilerTest extends WactCompilerTag{} 18 19 class WactCompilerTagTest extends WactCompileTreeNodeTest 20 { 21 protected $tag_info; 22 protected $source_location; 23 24 function setUp() 25 { 26 $this->tag_info = new WactTagInfo('CompilerTag', 'whatever'); 27 $this->source_location = new WactSourceLocation('my_file', 10); 28 29 parent :: setUp(); 30 } 31 32 protected function _createNode() 33 { 34 return new WactCompilerTag($this->source_location, 'my_tag', $this->tag_info); 35 } 36 37 function testGetClientId() 38 { 39 $this->component->setAttribute('id', 'TestId'); 40 $this->assertEqual($this->component->getClientId(), 'TestId'); 41 } 42 43 function testGetClientIdUnset() 44 { 45 $this->assertNull($this->component->getClientId()); 46 } 47 48 function testGetServerIdFromId() 49 { 50 $this->component->setAttribute('id', 'TestId'); 51 $this->assertEqual($this->component->getServerId(), 'TestId'); 52 } 53 54 function testGetServerIdFromWactId() 55 { 56 $this->component->setAttribute('wact:id', 'TestId'); 57 $this->assertEqual($this->component->getServerId(), 'TestId'); 58 } 59 60 function testGetAttribute() 61 { 62 $this->component->setAttribute('foo', 'bar'); 63 $this->assertEqual($this->component->getAttribute('foo'), 'bar'); 64 $this->assertEqual($this->component->getAttribute('FOO'), 'bar'); 65 } 66 67 function testGetAttributeUnset() 68 { 69 $this->assertNull($this->component->getAttribute('foo')); 70 } 71 72 function testHasAttribute() 73 { 74 $this->component->setAttribute('foo', 'bar'); 75 $this->component->setAttribute('tricky', NULL); 76 $this->assertTrue( $this->component->hasAttribute('foo')); 77 $this->assertTrue( $this->component->hasAttribute('tricky')); 78 $this->assertFalse( $this->component->hasAttribute('missing')); 79 $this->assertTrue( $this->component->hasAttribute('FOO')); 80 $this->assertTrue( $this->component->hasAttribute('TRICKY')); 81 $this->assertFalse( $this->component->hasAttribute('MISSING')); 82 } 83 84 function testDuplicateAttribute() 85 { 86 // Once set, attributes at compile time are immutable. 87 $this->component->setAttribute('SAME', 'value 1'); 88 try 89 { 90 $this->component->setAttribute('same', 'value 2'); 91 $this->assertTrue(false); 92 } 93 catch(WactException $e) 94 { 95 $this->assertWantedPattern('/Duplicate attribute/', $e->getMessage()); 96 $this->assertEqual($e->getParam('attribute'), 'same'); 97 } 98 } 99 100 function testRemoveAttribute() 101 { 102 $this->component->setAttribute('foo', 'bar'); 103 $this->component->setAttribute('untouched', 'value'); 104 $this->assertTrue( $this->component->hasAttribute('foo')); 105 $this->component->removeAttribute('FOO'); 106 $this->assertFalse( $this->component->hasAttribute('foo')); 107 } 108 109 function testBooleanAttribute() 110 { 111 //true cases 112 $this->component->setAttribute('A', NULL); 113 $this->assertTrue( $this->component->getBoolAttribute('A')); 114 115 $this->component->setAttribute('B', 'True'); 116 $this->assertTrue( $this->component->getBoolAttribute('B')); 117 118 $this->component->setAttribute('C', 'Something'); 119 $this->assertTrue( $this->component->getBoolAttribute('C')); 120 121 //false cases 122 $this->component->setAttribute('D', 'False'); 123 $this->assertFalse( $this->component->getBoolAttribute('D')); 124 125 $this->assertFalse( $this->component->getBoolAttribute('E')); 126 127 $this->component->setAttribute('F', 'n'); 128 $this->assertFalse( $this->component->getBoolAttribute('F')); 129 130 $this->component->setAttribute('G', 'No'); 131 $this->assertFalse( $this->component->getBoolAttribute('G')); 132 133 $this->component->setAttribute('H', 'none'); 134 $this->assertFalse( $this->component->getBoolAttribute('H')); 135 136 $this->component->setAttribute('I', '0'); 137 $this->assertFalse( $this->component->getBoolAttribute('I')); 138 } 139 140 function testAddChildAttribute() 141 { 142 $attrib = new WactAttribute('Foo', 'bar'); 143 $this->component->addChildAttribute($attrib); 144 $this->assertEqual($this->component->getAttribute('FOO'), 'bar'); 145 } 146 147 function testGetAttributesAsArray() 148 { 149 $this->component->setAttribute('foo', 'bar'); 150 $this->component->setAttribute('tricky', NULL); 151 $this->assertIdentical($this->component->getAttributesAsArray(array('tricky')), array('foo' => 'bar')); 152 } 153 154 function testPreparseAndCheckForRequiredConstantAttributes() 155 { 156 $this->tag_info->setRequiredConstantAttributes(array('bar')); 157 $this->component->setAttribute('bar', 'value'); 158 $this->component->preParse(); 159 } 160 161 function testPreparseAndCheckForRequiredAttributes() 162 { 163 $this->tag_info->setRequiredAttributes(array('bar')); 164 $this->component->setAttribute('bar', null); 165 $this->component->preParse(); 166 } 167 168 function testPreparseAndCheckForMissedRequiredConstantAttributes() 169 { 170 $this->tag_info->setRequiredConstantAttributes(array('bar')); 171 try 172 { 173 $this->component->preParse(); 174 $this->assertTrue(false); 175 } 176 catch(WactException $e) 177 { 178 $this->assertWantedPattern('/Missing required attribute/', $e->getMessage()); 179 $this->assertEqual($e->getParam('attribute'), 'bar'); 180 } 181 } 182 183 function testPreparseAndCheckForMissedRequiredAttributes() 184 { 185 $this->tag_info->setRequiredAttributes(array('bar')); 186 187 try 188 { 189 $this->component->preParse(); 190 $this->assertTrue(false); 191 } 192 catch(WactException $e) 193 { 194 $this->assertWantedPattern('/Missing required attribute/', $e->getMessage()); 195 $this->assertEqual($e->getParam('attribute'), 'bar'); 196 } 197 } 198 199 function testRestrictSelfNesting() 200 { 201 $tag_info = new WactTagInfo('CompilerTag', 'whatever'); 202 $tag_info->setRestrictSelfNesting(true); 203 204 $component = new WactCompilerTag(new WactSourceLocation('my_file', 13), 'whatever', $tag_info); 205 206 $parent = new WactCompilerTag(new WactSourceLocation('my_file', 10), 'whatEver', $tag_info); 207 $component->parent = $parent; 208 209 try 210 { 211 $component->preParse(); 212 $this->assertTrue(false); 213 } 214 catch(WactException $e) 215 { 216 $this->assertWantedPattern('/Tag cannot be nested within the same tag/', $e->getMessage()); 217 $this->assertEqual($e->getParam('same_tag_file'), 'my_file'); 218 $this->assertEqual($e->getParam('same_tag_line'), 10); 219 } 220 } 221 222 function testCheckParentTagClassOk() 223 { 224 $this->tag_info->setParentTagClass('MyTagClass1CompilerTest'); 225 226 $parent = new MyTagClass1CompilerTest(null, null, null); 227 $this->component->parent = $parent; 228 229 $this->component->preParse(); 230 } 231 232 function testCheckParentTagClassException() 233 { 234 $this->tag_info->setParentTagClass('MyTagClass1CompilerTest'); 235 236 $parent = new MyTagClass2CompilerTest(null, null, null); 237 $this->component->parent = $parent; 238 239 try 240 { 241 $this->component->preParse(); 242 $this->assertTrue(false); 243 } 244 catch(WactException $e) 245 { 246 $this->assertWantedPattern('/Tag must be enclosed by a proper parent tag/', $e->getMessage()); 247 $this->assertEqual($e->getParam('required_parent_tag_class'), 'MyTagClass1CompilerTest'); 248 $this->assertEqual($e->getParam('file'), $this->source_location->getFile()); 249 $this->assertEqual($e->getParam('line'), $this->source_location->getLine()); 250 } 251 } 252 } 253 254 } 255 256 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Oct 14 04:47:40 2008 | Cross-referenced by PHPXref 0.7 |