1--TEST--
2Test 1: Creating Elements with and without Namespaces
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8print " 1 DOMDocument::createElement('valid')\n";
9try {
10    $dom = new domDocument;
11    $dom->createElement('valid');
12    print "valid\n";
13} catch (Exception $e) {
14    print $e->getMessage() . "\n";
15}
16
17print " 2 DOMDocument::createElement('-invalid')\n";
18try {
19    $dom = new domDocument;
20    $dom->createElement('-invalid');
21    print "valid\n";
22} catch (Exception $e) {
23    print $e->getMessage() . "\n";
24}
25
26print " 3 DOMDocument::createElement(' ')\n";
27try {
28    $dom = new domDocument;
29    $dom->createElement(' ');
30    print "valid\n";
31} catch (Exception $e) {
32    print $e->getMessage() . "\n";
33}
34
35print " 4 DOMDocument::createElement('prefix:valid')\n";
36try {
37    $dom = new domDocument;
38    $dom->createElement('prefix:valid');
39    print "valid\n";
40} catch (Exception $e) {
41    print $e->getMessage() . "\n";
42}
43
44print " 5 DOMDocument::createElementNS('http://valid.com', 'valid')\n";
45try {
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
53print " 6 DOMDocument::createElementNS('http://valid.com', 'prefix:valid')\n";
54try {
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
62print " 7 DOMDocument::createElementNS('http://valid.com', '-invalid')\n";
63try {
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
71print " 8 DOMDocument::createElementNS('http://valid.com', 'prefix:-invalid')\n";
72try {
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
80print " 9 DOMDocument::createElementNS('', 'prefix:invalid')\n";
81try {
82    $dom = new domDocument;
83    $dom->createElementNS('', 'prefix:invalid');
84    print "valid\n";
85} catch (Exception $e) {
86    print $e->getMessage() . "\n";
87}
88
89print "10 DOMDocument::createElementNS('http://valid.com', 'prefix:valid:invalid')\n";
90try {
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
98print "11 DOMDocument::createElementNS('http://valid.com', '-prefix:valid')\n";
99try {
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
107print "12 DOMDocument::createElementNS('-', 'prefix:valid')\n";
108try {
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
117print "13 DOMElement::__construct('valid')\n";
118try {
119    $element = new DomElement('valid');
120    print "valid\n";
121} catch (Exception $e) {
122    print $e->getMessage() . "\n";
123}
124
125print "14 DOMElement::__construct('-invalid')\n";
126try {
127    $element = new DomElement('-invalid');
128    print "valid\n";
129} catch (Exception $e) {
130    print $e->getMessage() . "\n";
131}
132
133print "15 DOMElement::__construct(' ')\n";
134try {
135    $element = new DomElement(' ');
136    print "valid\n";
137} catch (Exception $e) {
138    print $e->getMessage() . "\n";
139}
140
141print "16 DOMElement::__construct('prefix:valid')\n";
142try {
143    $element = new DomElement('prefix:valid');
144    print "valid\n";
145} catch (Exception $e) {
146    print $e->getMessage() . "\n";
147}
148
149print "17 DOMElement::__construct('valid', '', 'http://valid.com')\n";
150try {
151    $element = new DomElement('valid', '', 'http://valid.com');
152    print "valid\n";
153} catch (Exception $e) {
154    print $e->getMessage() . "\n";
155}
156
157print "18 DOMElement::__construct('prefix:valid', '', 'http://valid.com')\n";
158try {
159    $element = new DomElement('prefix:valid', '', 'http://valid.com');
160    print "valid\n";
161} catch (Exception $e) {
162    print $e->getMessage() . "\n";
163}
164
165print "19 DOMElement::__construct('-invalid', '', 'http://valid.com')\n";
166try {
167    $element = new DomElement('-invalid', '', 'http://valid.com');
168    print "valid\n";
169} catch (Exception $e) {
170    print $e->getMessage() . "\n";
171}
172
173print "20 DOMElement::__construct('prefix:-invalid', '', 'http://valid.com')\n";
174try {
175    $element = new DomElement('prefix:-invalid', '', 'http://valid.com');
176    print "valid\n";
177} catch (Exception $e) {
178    print $e->getMessage() . "\n";
179}
180
181print "21 DOMElement::__construct('prefix:invalid', '', '')\n";
182try {
183    $element = new DomElement('prefix:invalid', '', '');
184    print "valid\n";
185} catch (Exception $e) {
186    print $e->getMessage() . "\n";
187}
188
189print "22 DOMElement::__construct('prefix:valid:invalid', '', 'http://valid.com')\n";
190try {
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
197print "23 DOMElement::__construct('-prefix:valid', '', 'http://valid.com')\n";
198try {
199    $element = new DomElement('-prefix:valid', '', 'http://valid.com');
200    print "valid\n";
201} catch (Exception $e) {
202    print $e->getMessage() . "\n";
203}
204
205print "24 DOMElement::__construct('prefix:valid', '', '-')\n";
206try {
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
215print "25 DOMDocument::createElementNS('', 'prefix:valid')\n";
216try {
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
227print "26 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xml:valid')\n";
228try {
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
236print "27 DOMElement::__construct('xml:valid', '', 'http://wrong.namespaceURI.com')\n";
237try {
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 */
245print "28 DOMDocument::createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid')\n";
246try {
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/* There used to be a 29 here that tested DOMElement::__construct('xml:valid', '', 'http://www.w3.org/XML/1998/namespace').
255 * In libxml2 version 2.12 or prior this didn't work because the xml namespace isn't there and you can't create it without
256 * a document. Starting from libxml2 version 2.13 it does actually work because the XML namespace is statically defined.
257 * The behaviour from version 2.13 is actually the desired behaviour anyway. */
258
259
260/* the qualifiedName or its prefix is "xmlns" and the  namespaceURI is
261   different from  "http://www.w3.org/2000/xmlns/" */
262
263print "30 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid')\n";
264try {
265    $dom = new domDocument;
266    $dom->createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid');
267    print "valid\n";
268} catch (Exception $e) {
269    print $e->getMessage() . "\n";
270}
271
272print "31 DOMElement::__construct('xmlns:valid', '', 'http://wrong.namespaceURI.com')\n";
273try {
274    $element = new DomElement('xmlns:valid', '', 'http://wrong.namespaceURI.com');
275    print "valid\n";
276} catch (Exception $e) {
277    print $e->getMessage() . "\n";
278}
279
280print "32 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid')\n";
281try {
282    $dom = new domDocument;
283    $dom->createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid');
284    print "valid\n";
285} catch (Exception $e) {
286    print $e->getMessage() . "\n";
287}
288
289print "33 DOMElement::__construct('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/')\n";
290try {
291    $element = new DomElement('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/');
292    print "valid\n";
293} catch (Exception $e) {
294    print $e->getMessage() . "\n";
295}
296
297/* the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the
298   qualifiedName nor its prefix is "xmlns". */
299
300print "34 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid')\n";
301try {
302    $dom = new domDocument;
303    $dom->createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid');
304    print "valid\n";
305} catch (Exception $e) {
306    print $e->getMessage() . "\n";
307}
308
309print "35 DOMElement::__construct('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/')\n";
310try {
311    $element = new DomElement('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/');
312    print "valid\n";
313} catch (Exception $e) {
314    print $e->getMessage() . "\n";
315}
316
317
318
319?>
320--EXPECT--
321 1 DOMDocument::createElement('valid')
322valid
323 2 DOMDocument::createElement('-invalid')
324Invalid Character Error
325 3 DOMDocument::createElement(' ')
326Invalid Character Error
327 4 DOMDocument::createElement('prefix:valid')
328valid
329 5 DOMDocument::createElementNS('http://valid.com', 'valid')
330valid
331 6 DOMDocument::createElementNS('http://valid.com', 'prefix:valid')
332valid
333 7 DOMDocument::createElementNS('http://valid.com', '-invalid')
334Namespace Error
335 8 DOMDocument::createElementNS('http://valid.com', 'prefix:-invalid')
336Namespace Error
337 9 DOMDocument::createElementNS('', 'prefix:invalid')
338Namespace Error
33910 DOMDocument::createElementNS('http://valid.com', 'prefix:valid:invalid')
340Namespace Error
34111 DOMDocument::createElementNS('http://valid.com', '-prefix:valid')
342Namespace Error
34312 DOMDocument::createElementNS('-', 'prefix:valid')
344valid
34513 DOMElement::__construct('valid')
346valid
34714 DOMElement::__construct('-invalid')
348Invalid Character Error
34915 DOMElement::__construct(' ')
350Invalid Character Error
35116 DOMElement::__construct('prefix:valid')
352Namespace Error
35317 DOMElement::__construct('valid', '', 'http://valid.com')
354valid
35518 DOMElement::__construct('prefix:valid', '', 'http://valid.com')
356valid
35719 DOMElement::__construct('-invalid', '', 'http://valid.com')
358Invalid Character Error
35920 DOMElement::__construct('prefix:-invalid', '', 'http://valid.com')
360Namespace Error
36121 DOMElement::__construct('prefix:invalid', '', '')
362Namespace Error
36322 DOMElement::__construct('prefix:valid:invalid', '', 'http://valid.com')
364Namespace Error
36523 DOMElement::__construct('-prefix:valid', '', 'http://valid.com')
366Invalid Character Error
36724 DOMElement::__construct('prefix:valid', '', '-')
368valid
36925 DOMDocument::createElementNS('', 'prefix:valid')
370Namespace Error
37126 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xml:valid')
372Namespace Error
37327 DOMElement::__construct('xml:valid', '', 'http://wrong.namespaceURI.com')
374Namespace Error
37528 DOMDocument::createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid')
376valid
37730 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid')
378Namespace Error
37931 DOMElement::__construct('xmlns:valid', '', 'http://wrong.namespaceURI.com')
380Namespace Error
38132 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid')
382valid
38333 DOMElement::__construct('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/')
384valid
38534 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid')
386Namespace Error
38735 DOMElement::__construct('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/')
388Namespace Error
389