Annotation of embedaddon/php/ext/dom/tests/dom_create_element.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test 1: Creating Elements with and without Namespaces
! 3: --SKIPIF--
! 4: <?php require_once('skipif.inc'); ?>
! 5: --FILE--
! 6: <?php
! 7:
! 8: print " 1 DOMDocument::createElement('valid')\n";
! 9: try {
! 10: $dom = new domDocument;
! 11: $dom->createElement('valid');
! 12: print "valid\n";
! 13: } catch (Exception $e) {
! 14: print $e->getMessage() . "\n";
! 15: }
! 16:
! 17: print " 2 DOMDocument::createElement('-invalid')\n";
! 18: try {
! 19: $dom = new domDocument;
! 20: $dom->createElement('-invalid');
! 21: print "valid\n";
! 22: } catch (Exception $e) {
! 23: print $e->getMessage() . "\n";
! 24: }
! 25:
! 26: print " 3 DOMDocument::createElement(' ')\n";
! 27: try {
! 28: $dom = new domDocument;
! 29: $dom->createElement(' ');
! 30: print "valid\n";
! 31: } catch (Exception $e) {
! 32: print $e->getMessage() . "\n";
! 33: }
! 34:
! 35: print " 4 DOMDocument::createElement('prefix:valid')\n";
! 36: try {
! 37: $dom = new domDocument;
! 38: $dom->createElement('prefix:valid');
! 39: print "valid\n";
! 40: } catch (Exception $e) {
! 41: print $e->getMessage() . "\n";
! 42: }
! 43:
! 44: print " 5 DOMDocument::createElementNS('http://valid.com', 'valid')\n";
! 45: try {
! 46: $dom = new domDocument;
! 47: $dom->createElementNS('http://valid.com', 'valid');
! 48: print "valid\n";
! 49: } catch (Exception $e) {
! 50: print $e->getMessage() . "\n";
! 51: }
! 52:
! 53: print " 6 DOMDocument::createElementNS('http://valid.com', 'prefix:valid')\n";
! 54: try {
! 55: $dom = new domDocument;
! 56: $dom->createElementNS('http://valid.com', 'prefix:valid');
! 57: print "valid\n";
! 58: } catch (Exception $e) {
! 59: print $e->getMessage() . "\n";
! 60: }
! 61:
! 62: print " 7 DOMDocument::createElementNS('http://valid.com', '-invalid')\n";
! 63: try {
! 64: $dom = new domDocument;
! 65: $dom->createElementNS('http://valid.com', '-invalid');
! 66: print "valid\n";
! 67: } catch (Exception $e) {
! 68: print $e->getMessage() . "\n";
! 69: }
! 70:
! 71: print " 8 DOMDocument::createElementNS('http://valid.com', 'prefix:-invalid')\n";
! 72: try {
! 73: $dom = new domDocument;
! 74: $dom->createElementNS('http://valid.com', 'prefix:-invalid');
! 75: print "valid\n";
! 76: } catch (Exception $e) {
! 77: print $e->getMessage() . "\n";
! 78: }
! 79:
! 80: print " 9 DOMDocument::createElementNS('', 'prefix:invalid')\n";
! 81: try {
! 82: $dom = new domDocument;
! 83: $dom->createElementNS('', 'prefix:invalid');
! 84: print "valid\n";
! 85: } catch (Exception $e) {
! 86: print $e->getMessage() . "\n";
! 87: }
! 88:
! 89: print "10 DOMDocument::createElementNS('http://valid.com', 'prefix:valid:invalid')\n";
! 90: try {
! 91: $dom = new domDocument;
! 92: $dom->createElementNS('http://valid.com', 'prefix:valid:invalid');
! 93: print "valid\n";
! 94: } catch (Exception $e) {
! 95: print $e->getMessage() . "\n";
! 96: }
! 97:
! 98: print "11 DOMDocument::createElementNS('http://valid.com', '-prefix:valid')\n";
! 99: try {
! 100: $dom = new domDocument;
! 101: $dom->createElementNS('http://valid.com', '-prefix:valid');
! 102: print "valid\n";
! 103: } catch (Exception $e) {
! 104: print $e->getMessage() . "\n";
! 105: }
! 106:
! 107: print "12 DOMDocument::createElementNS('-', 'prefix:valid')\n";
! 108: try {
! 109: $dom = new domDocument;
! 110: $dom->createElementNS('-', 'prefix:valid');
! 111: print "valid\n";
! 112: } catch (Exception $e) {
! 113: print $e->getMessage() . "\n";
! 114: }
! 115:
! 116:
! 117: print "13 DOMElement::__construct('valid')\n";
! 118: try {
! 119: $element = new DomElement('valid');
! 120: print "valid\n";
! 121: } catch (Exception $e) {
! 122: print $e->getMessage() . "\n";
! 123: }
! 124:
! 125: print "14 DOMElement::__construct('-invalid')\n";
! 126: try {
! 127: $element = new DomElement('-invalid');
! 128: print "valid\n";
! 129: } catch (Exception $e) {
! 130: print $e->getMessage() . "\n";
! 131: }
! 132:
! 133: print "15 DOMElement::__construct(' ')\n";
! 134: try {
! 135: $element = new DomElement(' ');
! 136: print "valid\n";
! 137: } catch (Exception $e) {
! 138: print $e->getMessage() . "\n";
! 139: }
! 140:
! 141: print "16 DOMElement::__construct('prefix:valid')\n";
! 142: try {
! 143: $element = new DomElement('prefix:valid');
! 144: print "valid\n";
! 145: } catch (Exception $e) {
! 146: print $e->getMessage() . "\n";
! 147: }
! 148:
! 149: print "17 DOMElement::__construct('valid', '', 'http://valid.com')\n";
! 150: try {
! 151: $element = new DomElement('valid', '', 'http://valid.com');
! 152: print "valid\n";
! 153: } catch (Exception $e) {
! 154: print $e->getMessage() . "\n";
! 155: }
! 156:
! 157: print "18 DOMElement::__construct('prefix:valid', '', 'http://valid.com')\n";
! 158: try {
! 159: $element = new DomElement('prefix:valid', '', 'http://valid.com');
! 160: print "valid\n";
! 161: } catch (Exception $e) {
! 162: print $e->getMessage() . "\n";
! 163: }
! 164:
! 165: print "19 DOMElement::__construct('-invalid', '', 'http://valid.com')\n";
! 166: try {
! 167: $element = new DomElement('-invalid', '', 'http://valid.com');
! 168: print "valid\n";
! 169: } catch (Exception $e) {
! 170: print $e->getMessage() . "\n";
! 171: }
! 172:
! 173: print "20 DOMElement::__construct('prefix:-invalid', '', 'http://valid.com')\n";
! 174: try {
! 175: $element = new DomElement('prefix:-invalid', '', 'http://valid.com');
! 176: print "valid\n";
! 177: } catch (Exception $e) {
! 178: print $e->getMessage() . "\n";
! 179: }
! 180:
! 181: print "21 DOMElement::__construct('prefix:invalid', '', '')\n";
! 182: try {
! 183: $element = new DomElement('prefix:invalid', '', '');
! 184: print "valid\n";
! 185: } catch (Exception $e) {
! 186: print $e->getMessage() . "\n";
! 187: }
! 188:
! 189: print "22 DOMElement::__construct('prefix:valid:invalid', '', 'http://valid.com')\n";
! 190: try {
! 191: $element = new DomElement('prefix:valid:invalid', '', 'http://valid.com');
! 192: print "valid\n";
! 193: } catch (Exception $e) {
! 194: print $e->getMessage() . "\n";
! 195: }
! 196:
! 197: print "23 DOMElement::__construct('-prefix:valid', '', 'http://valid.com')\n";
! 198: try {
! 199: $element = new DomElement('-prefix:valid', '', 'http://valid.com');
! 200: print "valid\n";
! 201: } catch (Exception $e) {
! 202: print $e->getMessage() . "\n";
! 203: }
! 204:
! 205: print "24 DOMElement::__construct('prefix:valid', '', '-')\n";
! 206: try {
! 207: $element = new DomElement('prefix:valid', '', '-');
! 208: print "valid\n";
! 209: } catch (Exception $e) {
! 210: print $e->getMessage() . "\n";
! 211: }
! 212:
! 213: /* the qualifiedName has a prefix and the namespaceURI is null */
! 214:
! 215: print "25 DOMDocument::createElementNS('', 'prefix:valid')\n";
! 216: try {
! 217: $dom = new domDocument;
! 218: $dom->createElementNS('', 'prefix:valid');
! 219: print "valid\n";
! 220: } catch (Exception $e) {
! 221: print $e->getMessage() . "\n";
! 222: }
! 223:
! 224: /* the qualifiedName has a prefix that is "xml" and the namespaceURI
! 225: is different from "http://www.w3.org/XML/1998/namespace" [XML Namespaces] */
! 226:
! 227: print "26 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xml:valid')\n";
! 228: try {
! 229: $dom = new domDocument;
! 230: $dom->createElementNS('http://wrong.namespaceURI.com', 'xml:valid');
! 231: print "valid\n";
! 232: } catch (Exception $e) {
! 233: print $e->getMessage() . "\n";
! 234: }
! 235:
! 236: print "27 DOMElement::__construct('xml:valid', '', 'http://wrong.namespaceURI.com')\n";
! 237: try {
! 238: $element = new DomElement('xml:valid', '', 'http://wrong.namespaceURI.com');
! 239: print "valid\n";
! 240: } catch (Exception $e) {
! 241: print $e->getMessage() . "\n";
! 242: }
! 243:
! 244: /* This is okay because we reuse the xml namespace from the document */
! 245: print "28 DOMDocument::createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid')\n";
! 246: try {
! 247: $dom = new domDocument;
! 248: $dom->createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid');
! 249: print "valid\n";
! 250: } catch (Exception $e) {
! 251: print $e->getMessage() . "\n";
! 252: }
! 253:
! 254: /* This isn't because the xml namespace isn't there and we can't create it */
! 255: print "29 DOMElement::__construct('xml:valid', '', 'http://www.w3.org/XML/1998/namespace')\n";
! 256: try {
! 257: $element = new DomElement('xml:valid', '', 'http://www.w3.org/XML/1998/namespace');
! 258: print "valid\n";
! 259: } catch (Exception $e) {
! 260: print $e->getMessage() . "\n";
! 261: }
! 262:
! 263:
! 264: /* the qualifiedName or its prefix is "xmlns" and the namespaceURI is
! 265: different from "http://www.w3.org/2000/xmlns/" */
! 266:
! 267: print "30 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid')\n";
! 268: try {
! 269: $dom = new domDocument;
! 270: $dom->createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid');
! 271: print "valid\n";
! 272: } catch (Exception $e) {
! 273: print $e->getMessage() . "\n";
! 274: }
! 275:
! 276: print "31 DOMElement::__construct('xmlns:valid', '', 'http://wrong.namespaceURI.com')\n";
! 277: try {
! 278: $element = new DomElement('xmlns:valid', '', 'http://wrong.namespaceURI.com');
! 279: print "valid\n";
! 280: } catch (Exception $e) {
! 281: print $e->getMessage() . "\n";
! 282: }
! 283:
! 284: print "32 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid')\n";
! 285: try {
! 286: $dom = new domDocument;
! 287: $dom->createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid');
! 288: print "valid\n";
! 289: } catch (Exception $e) {
! 290: print $e->getMessage() . "\n";
! 291: }
! 292:
! 293: print "33 DOMElement::__construct('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/')\n";
! 294: try {
! 295: $element = new DomElement('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/');
! 296: print "valid\n";
! 297: } catch (Exception $e) {
! 298: print $e->getMessage() . "\n";
! 299: }
! 300:
! 301: /* the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the
! 302: qualifiedName nor its prefix is "xmlns". */
! 303:
! 304: print "34 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid')\n";
! 305: try {
! 306: $dom = new domDocument;
! 307: $dom->createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid');
! 308: print "valid\n";
! 309: } catch (Exception $e) {
! 310: print $e->getMessage() . "\n";
! 311: }
! 312:
! 313: print "35 DOMElement::__construct('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/')\n";
! 314: try {
! 315: $element = new DomElement('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/');
! 316: print "valid\n";
! 317: } catch (Exception $e) {
! 318: print $e->getMessage() . "\n";
! 319: }
! 320:
! 321:
! 322:
! 323: ?>
! 324: --EXPECT--
! 325: 1 DOMDocument::createElement('valid')
! 326: valid
! 327: 2 DOMDocument::createElement('-invalid')
! 328: Invalid Character Error
! 329: 3 DOMDocument::createElement(' ')
! 330: Invalid Character Error
! 331: 4 DOMDocument::createElement('prefix:valid')
! 332: valid
! 333: 5 DOMDocument::createElementNS('http://valid.com', 'valid')
! 334: valid
! 335: 6 DOMDocument::createElementNS('http://valid.com', 'prefix:valid')
! 336: valid
! 337: 7 DOMDocument::createElementNS('http://valid.com', '-invalid')
! 338: Namespace Error
! 339: 8 DOMDocument::createElementNS('http://valid.com', 'prefix:-invalid')
! 340: Namespace Error
! 341: 9 DOMDocument::createElementNS('', 'prefix:invalid')
! 342: Namespace Error
! 343: 10 DOMDocument::createElementNS('http://valid.com', 'prefix:valid:invalid')
! 344: Namespace Error
! 345: 11 DOMDocument::createElementNS('http://valid.com', '-prefix:valid')
! 346: Namespace Error
! 347: 12 DOMDocument::createElementNS('-', 'prefix:valid')
! 348: valid
! 349: 13 DOMElement::__construct('valid')
! 350: valid
! 351: 14 DOMElement::__construct('-invalid')
! 352: Invalid Character Error
! 353: 15 DOMElement::__construct(' ')
! 354: Invalid Character Error
! 355: 16 DOMElement::__construct('prefix:valid')
! 356: Namespace Error
! 357: 17 DOMElement::__construct('valid', '', 'http://valid.com')
! 358: valid
! 359: 18 DOMElement::__construct('prefix:valid', '', 'http://valid.com')
! 360: valid
! 361: 19 DOMElement::__construct('-invalid', '', 'http://valid.com')
! 362: Invalid Character Error
! 363: 20 DOMElement::__construct('prefix:-invalid', '', 'http://valid.com')
! 364: Namespace Error
! 365: 21 DOMElement::__construct('prefix:invalid', '', '')
! 366: Namespace Error
! 367: 22 DOMElement::__construct('prefix:valid:invalid', '', 'http://valid.com')
! 368: Namespace Error
! 369: 23 DOMElement::__construct('-prefix:valid', '', 'http://valid.com')
! 370: Invalid Character Error
! 371: 24 DOMElement::__construct('prefix:valid', '', '-')
! 372: valid
! 373: 25 DOMDocument::createElementNS('', 'prefix:valid')
! 374: Namespace Error
! 375: 26 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xml:valid')
! 376: Namespace Error
! 377: 27 DOMElement::__construct('xml:valid', '', 'http://wrong.namespaceURI.com')
! 378: Namespace Error
! 379: 28 DOMDocument::createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid')
! 380: valid
! 381: 29 DOMElement::__construct('xml:valid', '', 'http://www.w3.org/XML/1998/namespace')
! 382: Namespace Error
! 383: 30 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid')
! 384: Namespace Error
! 385: 31 DOMElement::__construct('xmlns:valid', '', 'http://wrong.namespaceURI.com')
! 386: Namespace Error
! 387: 32 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid')
! 388: valid
! 389: 33 DOMElement::__construct('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/')
! 390: valid
! 391: 34 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid')
! 392: Namespace Error
! 393: 35 DOMElement::__construct('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/')
! 394: Namespace Error
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>