DOMNode_normalize_basic.phpt 1.6 KB

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