1--TEST-- 2Document::createElementNS() 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8require __DIR__ . "/element_dump.inc"; 9require __DIR__ . "/create_element_util.inc"; 10 11echo "--- Normal cases ---\n"; 12 13$dom = Dom\HTMLDocument::createEmpty(); 14$elements = []; 15 16$elements[] = createElementNS($dom, NULL, "qname", "&hello"); 17$elements[] = createElementNS($dom, "urn:foo", "foo:bar", "&hello"); 18$elements[] = createElementNS($dom, "urn:foo", "bar:BAR", "&hello"); 19$elements[] = createElementNS($dom, "urn:foo", "bar:BAR", "&hello"); 20$elements[] = createElementNS($dom, "http://www.w3.org/2000/xmlns/", "xmlns", "&hello"); 21$elements[] = createElementNS($dom, "http://www.w3.org/XML/1998/namespace", "xml", "&hello"); 22 23foreach ($elements as $element) { 24 dumpElement($element); 25} 26 27echo "--- Error cases ---\n"; 28 29function testError($dom, $namespaceURI, $qualifiedName) 30{ 31 $ns_readable = is_null($namespaceURI) ? "NULL" : "\"$namespaceURI\""; 32 echo "($ns_readable, \"$qualifiedName\"): "; 33 try { 34 $dom->createElementNS($namespaceURI, $qualifiedName); 35 } catch (DOMException $e) { 36 echo $e->getMessage(), "\n"; 37 } 38} 39 40testError($dom, NULL, "prefix:name"); 41testError($dom, "", "prefix:name"); 42testError($dom, "urn:foo", "@"); 43testError($dom, "http://www.w3.org/2000/xmlns/", "svg"); 44testError($dom, "urn:foo", "xml:xml"); 45 46?> 47--EXPECT-- 48--- Normal cases --- 49tagName: string(5) "qname" 50nodeName: string(5) "qname" 51textContent: string(6) "&hello" 52prefix: NULL 53namespaceURI: NULL 54<qname>&hello</qname> 55 56tagName: string(7) "foo:bar" 57nodeName: string(7) "foo:bar" 58textContent: string(6) "&hello" 59prefix: string(3) "foo" 60namespaceURI: string(7) "urn:foo" 61<foo:bar>&hello</foo:bar> 62 63tagName: string(7) "bar:BAR" 64nodeName: string(7) "bar:BAR" 65textContent: string(6) "&hello" 66prefix: string(3) "bar" 67namespaceURI: string(7) "urn:foo" 68<bar:BAR>&hello</bar:BAR> 69 70tagName: string(7) "bar:BAR" 71nodeName: string(7) "bar:BAR" 72textContent: string(6) "&hello" 73prefix: string(3) "bar" 74namespaceURI: string(7) "urn:foo" 75<bar:BAR>&hello</bar:BAR> 76 77tagName: string(5) "xmlns" 78nodeName: string(5) "xmlns" 79textContent: string(6) "&hello" 80prefix: NULL 81namespaceURI: string(29) "http://www.w3.org/2000/xmlns/" 82<xmlns>&hello</xmlns> 83 84tagName: string(3) "xml" 85nodeName: string(3) "xml" 86textContent: string(6) "&hello" 87prefix: NULL 88namespaceURI: string(36) "http://www.w3.org/XML/1998/namespace" 89<xml>&hello</xml> 90 91--- Error cases --- 92(NULL, "prefix:name"): Namespace Error 93("", "prefix:name"): Namespace Error 94("urn:foo", "@"): Invalid Character Error 95("http://www.w3.org/2000/xmlns/", "svg"): Namespace Error 96("urn:foo", "xml:xml"): Namespace Error 97