| [ 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/parser/WactBaseParsingStateTestCase.class.php'); 11 12 Mock :: generate('WactTreeBuilder', 'MockWactTreeBuilder'); 13 Mock :: generate('WactTagDictionary', 'MockWactTagDictionary'); 14 15 class WactComponentParsingStateTest extends WactBaseParsingStateTestCase 16 { 17 protected $tree_builder; 18 protected $tag_dictionary; 19 protected $cursor_node; 20 protected $parser; 21 protected $state; 22 23 function setUp() 24 { 25 $this->parser = new MockWactSourceFileParser(); 26 27 $this->cursor_node = new WactCompileTreeNode(); 28 $this->tag_dictionary = new MockWactTagDictionary(); 29 30 $this->tree_builder = new MockWactTreeBuilder(); 31 $this->tree_builder->setReturnValue('getCursor', $this->cursor_node); 32 33 $this->state = new WactComponentParsingState($this->parser, $this->tree_builder, $this->tag_dictionary); 34 } 35 36 function testStartTagPlain() 37 { 38 $tag = 'test'; 39 $location = new WactSourceLocation('my_file', 10); 40 41 $this->tree_builder->expectOnce('pushExpectedPlainTag', array($tag, $location)); 42 $this->tree_builder->expectOnce('addContent', array('<test foo="bar">', $location)); 43 44 $this->state->startTag($tag, $attrs = array('foo'=>'bar'), $location); 45 } 46 47 function testStartTagIsWactTag() 48 { 49 $tag = 'test'; 50 $attrs = array('foo'=>'bar'); 51 52 $info = new WactTagInfo($tag, $tag_class = 'SomeTagClass'); 53 $this->tag_dictionary->setReturnValue('findTagInfo', $info, array($tag, $attrs, FALSE, new ReferenceExpectation($this->cursor_node))); 54 55 $location = new WactSourceLocation('my_file', 10); 56 57 $this->tree_builder->expectOnce('buildTagNode', array($info, $tag, $location, $attrs)); 58 $this->tree_builder->expectOnce('pushExpectedWactTag', array($tag, $location)); 59 60 $this->parser->expectNever('changeToLiteralParsingState'); 61 62 $this->state->startTag($tag, $attrs, $location); 63 } 64 65 function testStartTagIsWactTagWithForbidParseTagContentProperty() 66 { 67 $tag = 'test'; 68 $attrs = array('foo'=>'bar'); 69 70 $info = new WactTagInfo($tag, $tag_class = 'SomeTagClass'); 71 $info->setForbidParsing(true); 72 73 $this->tag_dictionary->setReturnValue('findTagInfo', $info, array($tag, $attrs, FALSE, new ReferenceExpectation($this->cursor_node))); 74 75 $location = new WactSourceLocation('my_file', 10); 76 77 $this->tree_builder->expectOnce('buildTagNode', array($info, $tag, $location, $attrs)); 78 $tag_node = new WactCompilerTag($location, $tag, $info); 79 $this->tree_builder->setReturnValue('buildTagNode', $tag_node); 80 $this->tree_builder->expectOnce('pushExpectedWactTag', array($tag, $location)); 81 $this->tree_builder->expectOnce('pushNode', array($tag_node)); 82 83 $this->parser->expectOnce('changeToLiteralParsingState', array($tag)); 84 85 $this->state->startTag($tag, $attrs, $location); 86 } 87 88 function testStartTagIsWactTagWithForbidParseContentResultFromPushNode() 89 { 90 $tag = 'test'; 91 $attrs = array('foo'=>'bar'); 92 93 $info = new WactTagInfo($tag, $tag_class = 'SomeTagClass'); 94 95 $this->tag_dictionary->setReturnValue('findTagInfo', $info, array($tag, $attrs, FALSE, new ReferenceExpectation($this->cursor_node))); 96 97 $location = new WactSourceLocation('my_file', 10); 98 99 $this->tree_builder->expectOnce('buildTagNode', array($info, $tag, $location, $attrs)); 100 $tag_node = new WactCompilerTag($location, $tag, $info); 101 $this->tree_builder->setReturnValue('buildTagNode', $tag_node); 102 $this->tree_builder->expectOnce('pushExpectedWactTag', array($tag, $location)); 103 $this->tree_builder->expectOnce('pushNode', array($tag_node)); 104 $this->tree_builder->setReturnValue('pushNode', WACT_PARSER_FORBID_PARSING); 105 106 $this->parser->expectOnce('changeToLiteralParsingState', array($tag)); 107 108 $this->state->startTag($tag, $attrs, $location); 109 } 110 111 function testStartTagIsWactTagWithForbidEndTag() 112 { 113 $tag = 'test'; 114 $attrs = array('foo'=>'bar'); 115 116 $info = new WactTagInfo($tag, $tag_class = 'SomeTagClass'); 117 $info->setForbidEndTag(true); 118 119 $this->tag_dictionary->setReturnValue('findTagInfo', $info, array($tag, $attrs, FALSE, new ReferenceExpectation($this->cursor_node))); 120 121 $location = new WactSourceLocation('my_file', 10); 122 123 $this->tree_builder->expectOnce('buildTagNode', array($info, $tag, $location, $attrs, FALSE, FALSE)); 124 $this->tree_builder->expectNever('pushExpectedWactTag'); 125 $this->tree_builder->expectOnce('pushNode'); 126 $this->tree_builder->expectOnce('popNode'); 127 128 $this->state->startTag($tag, $attrs, $location); 129 } 130 131 function testStartTagWithIllegalRunatAttributeValue() 132 { 133 $tag = 'test'; 134 $attrs = array('runat'=>'{$hello}'); 135 136 $location = new WactSourceLocation('my_file', 10); 137 138 try 139 { 140 $this->state->startTag($tag, $attrs, $location); 141 $this->assertTrue(false); 142 } 143 catch(WactException $e) 144 { 145 $this->assertWantedPattern('/Illegal use of variable reference/', $e->getMessage()); 146 $this->assertEqual($e->getParam('expression'), '{$hello}'); 147 $this->assertEqual($e->getParam('file'), 'my_file'); 148 $this->assertEqual($e->getParam('line'), 10); 149 } 150 } 151 152 function testEndTagIsPlain() 153 { 154 $tag = 'test'; 155 156 $location = new WactSourceLocation('my_file', 10); 157 158 $this->tree_builder->expectOnce('popExpectedPlainTag', array($tag, $location)); 159 $this->tree_builder->setReturnValue('popExpectedPlainTag', WACT_EXPECTED_PLAIN_TAG); 160 $this->tree_builder->expectNever('popNode'); 161 $this->tree_builder->expectOnce('addWactTextNode', array('</' . $tag . '>')); 162 163 $this->state->endTag($tag, $location); 164 } 165 166 function testEndTagIsWactTagAndRunAtServer() 167 { 168 $tag = 'test'; 169 $info = new WactTagInfo($tag, 'test'); 170 $info->setRunat('server'); 171 172 $this->tag_dictionary->setReturnReference('getWactTagInfo', $info); 173 174 $location = new WactSourceLocation('my_file', 10); 175 176 $this->tree_builder->expectOnce('popExpectedWactTag', array($tag, $location)); 177 $this->tree_builder->setReturnValue('popExpectedWactTag', WACT_EXPECTED_WACT_TAG); 178 $this->tree_builder->expectOnce('popNode'); 179 180 $this->state->endTag($tag, $location); 181 } 182 183 function testEndTagIsPlainSinceRunAtClient() 184 { 185 $tag = 'test'; 186 $info = new WactTagInfo($tag, 'test'); 187 $info->setRunat('client'); 188 189 $this->tag_dictionary->setReturnReference('getWactTagInfo', $info); 190 191 $location = new WactSourceLocation('my_file', 10); 192 193 $this->tree_builder->expectOnce('popExpectedPlainTag', array($tag, $location)); 194 $this->tree_builder->expectNever('popNode'); 195 $this->tree_builder->expectOnce('addWactTextNode', array('</' . $tag . '>')); 196 197 $this->state->endTag($tag, $location); 198 } 199 200 function testEndTagIsPlainSinceRunAtClientButPopExpectedPlainTagReturnMatchToWactTag() 201 { 202 $tag = 'test'; 203 $info = new WactTagInfo($tag, 'test'); 204 $info->setRunat('client'); 205 206 $this->tag_dictionary->setReturnReference('getWactTagInfo', $info); 207 208 $location = new WactSourceLocation('my_file', 10); 209 210 $this->tree_builder->expectOnce('popExpectedPlainTag', array($tag, $location)); 211 $this->tree_builder->setReturnValue('popExpectedPlainTag', WACT_EXPECTED_WACT_TAG); 212 $this->tree_builder->expectOnce('popNode'); 213 214 $this->state->endTag($tag, $location); 215 } 216 217 function testEmptyTagIsPlain() 218 { 219 $tag = 'test'; 220 $attrs = array('foo' => 'bar'); 221 222 $this->tag_dictionary->expectOnce('findTagInfo'); 223 $this->tag_dictionary->setReturnValue('findTagInfo', NULL); 224 225 $location = new WactSourceLocation('my_file', 10); 226 227 $this->tree_builder->expectNever('pushExpectedWactTag'); 228 $this->tree_builder->expectNever('pushExpectedPlainTag'); 229 $this->tree_builder->expectNever('pushNode'); 230 $this->tree_builder->expectOnce('addContent', array('<test foo="bar" />', $location)); 231 232 $this->state->emptyTag($tag, $attrs, $location); 233 } 234 235 function testEmptyTagIsWactTag() 236 { 237 $tag = 'test'; 238 $attrs = array('foo'=>'bar'); 239 240 $info = new WactTagInfo($tag, 'test'); 241 $this->tag_dictionary->setReturnReference('findTagInfo', $info); 242 243 $location = new WactSourceLocation('my_file', 10); 244 245 $this->tree_builder->expectOnce('buildTagNode', array($info, $tag, $location, $attrs, TRUE, false )); 246 $tag_node = new WactCompilerTag($location, $tag, $info); 247 $this->tree_builder->setReturnValue('buildTagNode', $tag_node); 248 249 $this->tree_builder->expectNever('addNode'); 250 $this->tree_builder->expectOnce('pushNode', array($tag_node)); 251 $this->tree_builder->expectOnce('popNode'); 252 $this->tree_builder->expectNever('pushExpectedWactTag'); 253 $this->tree_builder->expectNever('pushExpectedPlainTag'); 254 255 $this->state->emptyTag($tag, $attrs, $location); 256 } 257 258 function testCharacters() 259 { 260 $text = 'test'; 261 $location = new WactSourceLocation('my_file', 10); 262 $this->tree_builder->expectOnce('addContent', array($text, $location)); 263 $this->state->characters($text, $location); 264 } 265 266 function testProcessingInstruction() 267 { 268 $target = 'test'; 269 $instruction = 'doit'; 270 $location = new WactSourceLocation('my_file', 10); 271 $this->tree_builder->expectOnce('addProcessingInstruction', array($target, $instruction, $location)); 272 $this->state->instruction($target, $instruction, $location); 273 } 274 275 /* 276 function testStartElementForTagWithEndTagForbiddenThrowsExceptionInStrictMode() 277 { 278 $tag = 'test'; 279 $attrs = array('foo'=>'bar'); 280 281 $info = new WactTagInfo($tag, 'test'); 282 $info->setForbidEndTag(); 283 $this->tag_dictionary->setReturnReference('findTagInfo', $info); 284 285 $this->locator->expectOnce('getCurrentLocation'); 286 $this->locator->setReturnValue('getCurrentLocation', $location = new WactSourceLocation('my_file', 10)); 287 288 $this->tree_builder->expectNever('popNode'); 289 $this->tree_builder->expectNever('pushExpectedTag'); 290 291 $this->parser->expectNever('changeToComponentParsingState'); 292 293 try 294 { 295 $this->state->startTag($tag, $attrs); 296 $this->assertTrue(false); 297 } 298 catch(WactException $e) 299 { 300 $this->assertWantedPattern('/Closing tag is forbidden for this tag\. Use self closing notation/', $e->getMessage()); 301 $this->assertEqual($e->getParam('tag'), 'test'); 302 $this->assertEqual($e->getParam('file'), 'my_file'); 303 $this->assertEqual($e->getParam('line'), 10); 304 } 305 } 306 307 function testEndElementForbidden() 308 { 309 $tag = 'test'; 310 311 $this->locator->expectOnce('getCurrentLocation'); 312 $this->locator->setReturnValue('getCurrentLocation', $location = new WactSourceLocation('my_file', 10)); 313 314 $this->component->tag = 'test'; 315 316 $info = new WactTagInfo($tag, 'test'); 317 $info->setForbidEndTag(); 318 $this->tag_dictionary->setReturnReference('getWactTagInfo', $info); 319 320 try 321 { 322 $this->state->endTag($tag); 323 $this->assertTrue(false); 324 } 325 catch(WactException $e) 326 { 327 $this->assertWantedPattern('/Closing tag forbidden/', $e->getMessage()); 328 $this->assertEqual($e->getParam('tag'), $tag); 329 $this->assertEqual($e->getParam('file'), 'my_file'); 330 $this->assertEqual($e->getParam('line'), 10); 331 } 332 } 333 */ 334 } 335 ?>