bug32615.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. Bug #32615 (Replacing and inserting Fragments)
  3. --SKIPIF--
  4. <?php require_once('skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $dom = new DomDocument;
  8. $frag = $dom->createDocumentFragment();
  9. $frag->appendChild(new DOMElement('root'));
  10. $dom->appendChild($frag);
  11. $root = $dom->documentElement;
  12. $frag->appendChild(new DOMElement('first'));
  13. $root->appendChild($frag);
  14. $frag->appendChild(new DOMElement('second'));
  15. $root->appendChild($frag);
  16. $node = $dom->createElement('newfirst');
  17. $frag->appendChild($node);
  18. $root->replaceChild($frag, $root->firstChild);
  19. unset($frag);
  20. $frag = $dom->createDocumentFragment();
  21. $frag->appendChild(new DOMElement('newsecond'));
  22. $root->replaceChild($frag, $root->lastChild);
  23. $node = $frag->appendChild(new DOMElement('fourth'));
  24. $root->insertBefore($frag, NULL);
  25. $frag->appendChild(new DOMElement('third'));
  26. $node = $root->insertBefore($frag, $node);
  27. $frag->appendChild(new DOMElement('start'));
  28. $root->insertBefore($frag, $root->firstChild);
  29. $frag->appendChild(new DOMElement('newthird'));
  30. $root->replaceChild($frag, $node);
  31. $frag->appendChild(new DOMElement('newfourth'));
  32. $root->replaceChild($frag, $root->lastChild);
  33. $frag->appendChild(new DOMElement('first'));
  34. $root->replaceChild($frag, $root->firstChild->nextSibling);
  35. $root->removeChild($root->firstChild);
  36. echo $dom->saveXML()."\n";
  37. while ($root->hasChildNodes()) {
  38. $root->removeChild($root->firstChild);
  39. }
  40. $frag->appendChild(new DOMElement('first'));
  41. $root->insertBefore($frag, $root->firstChild);
  42. $node = $frag->appendChild(new DOMElement('fourth'));
  43. $root->appendChild($frag);
  44. $frag->appendChild(new DOMElement('second'));
  45. $frag->appendChild(new DOMElement('third'));
  46. $root->insertBefore($frag, $node);
  47. echo $dom->saveXML()."\n";
  48. $frag = $dom->createDocumentFragment();
  49. $root = $dom->documentElement;
  50. $root->replaceChild($frag, $root->firstChild);
  51. echo $dom->saveXML();
  52. ?>
  53. --EXPECT--
  54. <?xml version="1.0"?>
  55. <root><first/><newsecond/><newthird/><newfourth/></root>
  56. <?xml version="1.0"?>
  57. <root><first/><second/><third/><fourth/></root>
  58. <?xml version="1.0"?>
  59. <root><second/><third/><fourth/></root>