1--TEST--
2DOMNode::normalize()
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8/* Create an XML document
9 * with structure
10 * <book>
11 *  <author></author>
12 *  <title>This is the title</title>
13 * </book>
14 * Calculate the number of title text nodes (1).
15 * Add another text node to title. Calculate the number of title text nodes (2).
16 * Normalize author. Calculate the number of title text nodes (2).
17 * Normalize title. Calculate the number of title text nodes (1).
18*/
19
20$doc = new DOMDocument();
21
22$root = $doc->createElement('book');
23$doc->appendChild($root);
24
25$title = $doc->createElement('title');
26$root->appendChild($title);
27
28$author = $doc->createElement('author');
29$root->appendChild($author);
30
31$text = $doc->createTextNode('This is the first title');
32$title->appendChild($text);
33
34echo "Number of child nodes of title = ";
35var_dump($title->childNodes->length);
36
37// add a second text node to title
38$text = $doc->createTextNode('This is the second title');
39$title->appendChild($text);
40
41echo "Number of child nodes of title after adding second title = ";
42var_dump($title->childNodes->length);
43
44// should do nothing
45$author->normalize();
46
47echo "Number of child nodes of title after normalizing author = ";
48var_dump($title->childNodes->length);
49
50
51// should concatenate first and second title text nodes
52$title->normalize();
53
54echo "Number of child nodes of title after normalizing title = ";
55var_dump($title->childNodes->length);
56
57?>
58--EXPECT--
59Number of child nodes of title = int(1)
60Number of child nodes of title after adding second title = int(2)
61Number of child nodes of title after normalizing author = int(2)
62Number of child nodes of title after normalizing title = int(1)
63