123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- --TEST--
- Bug #28721 (appendChild() and insertBefore() unset DOMText)
- --EXTENSIONS--
- dom
- --FILE--
- <?php
- function print_node(DomNode $node) {
- echo "name (value): " . $node->nodeName . " (" . $node->nodeValue . ")\n";
- }
- function print_node_r(DomNode $node) {
- static $indent = "";
- echo "\n" . $indent;
- print_node($node);
- echo $indent . "parent: ";
- if ( $node->parentNode )
- print_node($node->parentNode);
- else
- echo "NULL\n";
- echo $indent . "previousSibling: ";
- if ( $node->previousSibling )
- print_node($node->previousSibling);
- else
- echo "NULL\n";
- echo $indent . "nextSibling: ";
- if ( $node->nextSibling )
- print_node($node->nextSibling);
- else
- echo "NULL\n";
- if ( !$node->hasChildNodes() )
- return;
- foreach ($node->childNodes as $child) {
- $old_indent = $indent;
- $indent .= " ";
- print_node_r($child);
- $indent = $old_indent;
- }
- }
- function err_handler($errno, $errstr, $errfile, $errline) {
- echo "Error ($errno) on line $errline: $errstr\n";
- }
- // Record 'DocumentFragment is empty' warnings
- set_error_handler("err_handler", E_WARNING);
- $xml = new DomDocument();
- $p = $xml->createElement("p");
- $p->appendChild($t1 = $xml->createTextNode(" t1 "));
- $p->appendChild($b = $xml->createElement("b"));
- $b->appendChild($xml->createTextNode("X"));
- $p->appendChild($t2 = $xml->createTextNode(" t2 "));
- $p->appendChild($xml->createTextNode(" xxx "));
- print_node_r($p);
- echo "\nAppend t1 to p:\n";
- $ret = $p->appendChild($t1);
- print_node_r($p);
- echo "\n";
- echo "t1 == ret: ";
- var_dump( $t1 === $ret );
- $d = $xml->createElement("div");
- $d->appendChild($t3 = $xml->createTextNode(" t3 "));
- $d->appendChild($b = $xml->createElement("b"));
- $b->appendChild($xml->createElement("X"));
- $d->appendChild($t4 = $xml->createTextNode(" t4 "));
- $d->appendChild($xml->createTextNode(" xxx "));
- echo "\ndiv:\n";
- print_node_r($d);
- echo "\nInsert t4 before t3:\n";
- $ret = $d->insertBefore($t4, $t3);
- print_node_r($d);
- echo "\n";
- $frag = $xml->createDocumentFragment();
- $t5 = $frag->appendChild($xml->createTextNode(" t5 "));
- $frag->appendChild($i = $xml->createElement("i"));
- $i->appendChild($xml->createTextNode(" frob "));
- $frag->appendChild($xml->createTextNOde(" t6 "));
- echo "\np:\n";
- print_node_r($p);
- echo "\nFragment:\n";
- print_node_r($frag);
- echo "\nAppending fragment to p:\n";
- $p->appendChild($frag);
- print_node_r($p);
- echo "\nFragment:\n";
- print_node_r($frag);
- echo "\ndiv:\n";
- print_node_r($d);
- echo "\nInserting fragment before t4\n";
- $d->insertBefore($frag, $t4);
- print_node_r($d);
- echo "\np:\n";
- print_node_r($p);
- ?>
- --EXPECT--
- name (value): p ( t1 X t2 xxx )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t1 )
- parent: name (value): p ( t1 X t2 xxx )
- previousSibling: NULL
- nextSibling: name (value): b (X)
- name (value): b (X)
- parent: name (value): p ( t1 X t2 xxx )
- previousSibling: name (value): #text ( t1 )
- nextSibling: name (value): #text ( t2 )
- name (value): #text (X)
- parent: name (value): b (X)
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t2 )
- parent: name (value): p ( t1 X t2 xxx )
- previousSibling: name (value): b (X)
- nextSibling: name (value): #text ( xxx )
- name (value): #text ( xxx )
- parent: name (value): p ( t1 X t2 xxx )
- previousSibling: name (value): #text ( t2 )
- nextSibling: NULL
- Append t1 to p:
- name (value): p (X t2 xxx t1 )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): b (X)
- parent: name (value): p (X t2 xxx t1 )
- previousSibling: NULL
- nextSibling: name (value): #text ( t2 )
- name (value): #text (X)
- parent: name (value): b (X)
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t2 )
- parent: name (value): p (X t2 xxx t1 )
- previousSibling: name (value): b (X)
- nextSibling: name (value): #text ( xxx )
- name (value): #text ( xxx )
- parent: name (value): p (X t2 xxx t1 )
- previousSibling: name (value): #text ( t2 )
- nextSibling: name (value): #text ( t1 )
- name (value): #text ( t1 )
- parent: name (value): p (X t2 xxx t1 )
- previousSibling: name (value): #text ( xxx )
- nextSibling: NULL
- t1 == ret: bool(true)
- div:
- name (value): div ( t3 t4 xxx )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t3 )
- parent: name (value): div ( t3 t4 xxx )
- previousSibling: NULL
- nextSibling: name (value): b ()
- name (value): b ()
- parent: name (value): div ( t3 t4 xxx )
- previousSibling: name (value): #text ( t3 )
- nextSibling: name (value): #text ( t4 )
- name (value): X ()
- parent: name (value): b ()
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t4 )
- parent: name (value): div ( t3 t4 xxx )
- previousSibling: name (value): b ()
- nextSibling: name (value): #text ( xxx )
- name (value): #text ( xxx )
- parent: name (value): div ( t3 t4 xxx )
- previousSibling: name (value): #text ( t4 )
- nextSibling: NULL
- Insert t4 before t3:
- name (value): div ( t4 t3 xxx )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t4 )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: NULL
- nextSibling: name (value): #text ( t3 )
- name (value): #text ( t3 )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): #text ( t4 )
- nextSibling: name (value): b ()
- name (value): b ()
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): #text ( t3 )
- nextSibling: name (value): #text ( xxx )
- name (value): X ()
- parent: name (value): b ()
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( xxx )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): b ()
- nextSibling: NULL
- p:
- name (value): p (X t2 xxx t1 )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): b (X)
- parent: name (value): p (X t2 xxx t1 )
- previousSibling: NULL
- nextSibling: name (value): #text ( t2 )
- name (value): #text (X)
- parent: name (value): b (X)
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t2 )
- parent: name (value): p (X t2 xxx t1 )
- previousSibling: name (value): b (X)
- nextSibling: name (value): #text ( xxx )
- name (value): #text ( xxx )
- parent: name (value): p (X t2 xxx t1 )
- previousSibling: name (value): #text ( t2 )
- nextSibling: name (value): #text ( t1 )
- name (value): #text ( t1 )
- parent: name (value): p (X t2 xxx t1 )
- previousSibling: name (value): #text ( xxx )
- nextSibling: NULL
- Fragment:
- name (value): #document-fragment ()
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t5 )
- parent: name (value): #document-fragment ()
- previousSibling: NULL
- nextSibling: name (value): i ( frob )
- name (value): i ( frob )
- parent: name (value): #document-fragment ()
- previousSibling: name (value): #text ( t5 )
- nextSibling: name (value): #text ( t6 )
- name (value): #text ( frob )
- parent: name (value): i ( frob )
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t6 )
- parent: name (value): #document-fragment ()
- previousSibling: name (value): i ( frob )
- nextSibling: NULL
- Appending fragment to p:
- name (value): p (X t2 xxx t1 t5 frob t6 )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): b (X)
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: NULL
- nextSibling: name (value): #text ( t2 )
- name (value): #text (X)
- parent: name (value): b (X)
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t2 )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): b (X)
- nextSibling: name (value): #text ( xxx )
- name (value): #text ( xxx )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): #text ( t2 )
- nextSibling: name (value): #text ( t1 )
- name (value): #text ( t1 )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): #text ( xxx )
- nextSibling: name (value): #text ( t5 )
- name (value): #text ( t5 )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): #text ( t1 )
- nextSibling: name (value): i ( frob )
- name (value): i ( frob )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): #text ( t5 )
- nextSibling: name (value): #text ( t6 )
- name (value): #text ( frob )
- parent: name (value): i ( frob )
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t6 )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): i ( frob )
- nextSibling: NULL
- Fragment:
- name (value): #document-fragment ()
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- div:
- name (value): div ( t4 t3 xxx )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t4 )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: NULL
- nextSibling: name (value): #text ( t3 )
- name (value): #text ( t3 )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): #text ( t4 )
- nextSibling: name (value): b ()
- name (value): b ()
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): #text ( t3 )
- nextSibling: name (value): #text ( xxx )
- name (value): X ()
- parent: name (value): b ()
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( xxx )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): b ()
- nextSibling: NULL
- Inserting fragment before t4
- Error (2) on line 109: DOMNode::insertBefore(): Document Fragment is empty
- name (value): div ( t4 t3 xxx )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t4 )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: NULL
- nextSibling: name (value): #text ( t3 )
- name (value): #text ( t3 )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): #text ( t4 )
- nextSibling: name (value): b ()
- name (value): b ()
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): #text ( t3 )
- nextSibling: name (value): #text ( xxx )
- name (value): X ()
- parent: name (value): b ()
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( xxx )
- parent: name (value): div ( t4 t3 xxx )
- previousSibling: name (value): b ()
- nextSibling: NULL
- p:
- name (value): p (X t2 xxx t1 t5 frob t6 )
- parent: NULL
- previousSibling: NULL
- nextSibling: NULL
- name (value): b (X)
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: NULL
- nextSibling: name (value): #text ( t2 )
- name (value): #text (X)
- parent: name (value): b (X)
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t2 )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): b (X)
- nextSibling: name (value): #text ( xxx )
- name (value): #text ( xxx )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): #text ( t2 )
- nextSibling: name (value): #text ( t1 )
- name (value): #text ( t1 )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): #text ( xxx )
- nextSibling: name (value): #text ( t5 )
- name (value): #text ( t5 )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): #text ( t1 )
- nextSibling: name (value): i ( frob )
- name (value): i ( frob )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): #text ( t5 )
- nextSibling: name (value): #text ( t6 )
- name (value): #text ( frob )
- parent: name (value): i ( frob )
- previousSibling: NULL
- nextSibling: NULL
- name (value): #text ( t6 )
- parent: name (value): p (X t2 xxx t1 t5 frob t6 )
- previousSibling: name (value): i ( frob )
- nextSibling: NULL
|