bug28721.phpt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. --TEST--
  2. Bug #28721 (appendChild() and insertBefore() unset DOMText)
  3. --EXTENSIONS--
  4. dom
  5. --FILE--
  6. <?php
  7. function print_node(DomNode $node) {
  8. echo "name (value): " . $node->nodeName . " (" . $node->nodeValue . ")\n";
  9. }
  10. function print_node_r(DomNode $node) {
  11. static $indent = "";
  12. echo "\n" . $indent;
  13. print_node($node);
  14. echo $indent . "parent: ";
  15. if ( $node->parentNode )
  16. print_node($node->parentNode);
  17. else
  18. echo "NULL\n";
  19. echo $indent . "previousSibling: ";
  20. if ( $node->previousSibling )
  21. print_node($node->previousSibling);
  22. else
  23. echo "NULL\n";
  24. echo $indent . "nextSibling: ";
  25. if ( $node->nextSibling )
  26. print_node($node->nextSibling);
  27. else
  28. echo "NULL\n";
  29. if ( !$node->hasChildNodes() )
  30. return;
  31. foreach ($node->childNodes as $child) {
  32. $old_indent = $indent;
  33. $indent .= " ";
  34. print_node_r($child);
  35. $indent = $old_indent;
  36. }
  37. }
  38. function err_handler($errno, $errstr, $errfile, $errline) {
  39. echo "Error ($errno) on line $errline: $errstr\n";
  40. }
  41. // Record 'DocumentFragment is empty' warnings
  42. set_error_handler("err_handler", E_WARNING);
  43. $xml = new DomDocument();
  44. $p = $xml->createElement("p");
  45. $p->appendChild($t1 = $xml->createTextNode(" t1 "));
  46. $p->appendChild($b = $xml->createElement("b"));
  47. $b->appendChild($xml->createTextNode("X"));
  48. $p->appendChild($t2 = $xml->createTextNode(" t2 "));
  49. $p->appendChild($xml->createTextNode(" xxx "));
  50. print_node_r($p);
  51. echo "\nAppend t1 to p:\n";
  52. $ret = $p->appendChild($t1);
  53. print_node_r($p);
  54. echo "\n";
  55. echo "t1 == ret: ";
  56. var_dump( $t1 === $ret );
  57. $d = $xml->createElement("div");
  58. $d->appendChild($t3 = $xml->createTextNode(" t3 "));
  59. $d->appendChild($b = $xml->createElement("b"));
  60. $b->appendChild($xml->createElement("X"));
  61. $d->appendChild($t4 = $xml->createTextNode(" t4 "));
  62. $d->appendChild($xml->createTextNode(" xxx "));
  63. echo "\ndiv:\n";
  64. print_node_r($d);
  65. echo "\nInsert t4 before t3:\n";
  66. $ret = $d->insertBefore($t4, $t3);
  67. print_node_r($d);
  68. echo "\n";
  69. $frag = $xml->createDocumentFragment();
  70. $t5 = $frag->appendChild($xml->createTextNode(" t5 "));
  71. $frag->appendChild($i = $xml->createElement("i"));
  72. $i->appendChild($xml->createTextNode(" frob "));
  73. $frag->appendChild($xml->createTextNOde(" t6 "));
  74. echo "\np:\n";
  75. print_node_r($p);
  76. echo "\nFragment:\n";
  77. print_node_r($frag);
  78. echo "\nAppending fragment to p:\n";
  79. $p->appendChild($frag);
  80. print_node_r($p);
  81. echo "\nFragment:\n";
  82. print_node_r($frag);
  83. echo "\ndiv:\n";
  84. print_node_r($d);
  85. echo "\nInserting fragment before t4\n";
  86. $d->insertBefore($frag, $t4);
  87. print_node_r($d);
  88. echo "\np:\n";
  89. print_node_r($p);
  90. ?>
  91. --EXPECT--
  92. name (value): p ( t1 X t2 xxx )
  93. parent: NULL
  94. previousSibling: NULL
  95. nextSibling: NULL
  96. name (value): #text ( t1 )
  97. parent: name (value): p ( t1 X t2 xxx )
  98. previousSibling: NULL
  99. nextSibling: name (value): b (X)
  100. name (value): b (X)
  101. parent: name (value): p ( t1 X t2 xxx )
  102. previousSibling: name (value): #text ( t1 )
  103. nextSibling: name (value): #text ( t2 )
  104. name (value): #text (X)
  105. parent: name (value): b (X)
  106. previousSibling: NULL
  107. nextSibling: NULL
  108. name (value): #text ( t2 )
  109. parent: name (value): p ( t1 X t2 xxx )
  110. previousSibling: name (value): b (X)
  111. nextSibling: name (value): #text ( xxx )
  112. name (value): #text ( xxx )
  113. parent: name (value): p ( t1 X t2 xxx )
  114. previousSibling: name (value): #text ( t2 )
  115. nextSibling: NULL
  116. Append t1 to p:
  117. name (value): p (X t2 xxx t1 )
  118. parent: NULL
  119. previousSibling: NULL
  120. nextSibling: NULL
  121. name (value): b (X)
  122. parent: name (value): p (X t2 xxx t1 )
  123. previousSibling: NULL
  124. nextSibling: name (value): #text ( t2 )
  125. name (value): #text (X)
  126. parent: name (value): b (X)
  127. previousSibling: NULL
  128. nextSibling: NULL
  129. name (value): #text ( t2 )
  130. parent: name (value): p (X t2 xxx t1 )
  131. previousSibling: name (value): b (X)
  132. nextSibling: name (value): #text ( xxx )
  133. name (value): #text ( xxx )
  134. parent: name (value): p (X t2 xxx t1 )
  135. previousSibling: name (value): #text ( t2 )
  136. nextSibling: name (value): #text ( t1 )
  137. name (value): #text ( t1 )
  138. parent: name (value): p (X t2 xxx t1 )
  139. previousSibling: name (value): #text ( xxx )
  140. nextSibling: NULL
  141. t1 == ret: bool(true)
  142. div:
  143. name (value): div ( t3 t4 xxx )
  144. parent: NULL
  145. previousSibling: NULL
  146. nextSibling: NULL
  147. name (value): #text ( t3 )
  148. parent: name (value): div ( t3 t4 xxx )
  149. previousSibling: NULL
  150. nextSibling: name (value): b ()
  151. name (value): b ()
  152. parent: name (value): div ( t3 t4 xxx )
  153. previousSibling: name (value): #text ( t3 )
  154. nextSibling: name (value): #text ( t4 )
  155. name (value): X ()
  156. parent: name (value): b ()
  157. previousSibling: NULL
  158. nextSibling: NULL
  159. name (value): #text ( t4 )
  160. parent: name (value): div ( t3 t4 xxx )
  161. previousSibling: name (value): b ()
  162. nextSibling: name (value): #text ( xxx )
  163. name (value): #text ( xxx )
  164. parent: name (value): div ( t3 t4 xxx )
  165. previousSibling: name (value): #text ( t4 )
  166. nextSibling: NULL
  167. Insert t4 before t3:
  168. name (value): div ( t4 t3 xxx )
  169. parent: NULL
  170. previousSibling: NULL
  171. nextSibling: NULL
  172. name (value): #text ( t4 )
  173. parent: name (value): div ( t4 t3 xxx )
  174. previousSibling: NULL
  175. nextSibling: name (value): #text ( t3 )
  176. name (value): #text ( t3 )
  177. parent: name (value): div ( t4 t3 xxx )
  178. previousSibling: name (value): #text ( t4 )
  179. nextSibling: name (value): b ()
  180. name (value): b ()
  181. parent: name (value): div ( t4 t3 xxx )
  182. previousSibling: name (value): #text ( t3 )
  183. nextSibling: name (value): #text ( xxx )
  184. name (value): X ()
  185. parent: name (value): b ()
  186. previousSibling: NULL
  187. nextSibling: NULL
  188. name (value): #text ( xxx )
  189. parent: name (value): div ( t4 t3 xxx )
  190. previousSibling: name (value): b ()
  191. nextSibling: NULL
  192. p:
  193. name (value): p (X t2 xxx t1 )
  194. parent: NULL
  195. previousSibling: NULL
  196. nextSibling: NULL
  197. name (value): b (X)
  198. parent: name (value): p (X t2 xxx t1 )
  199. previousSibling: NULL
  200. nextSibling: name (value): #text ( t2 )
  201. name (value): #text (X)
  202. parent: name (value): b (X)
  203. previousSibling: NULL
  204. nextSibling: NULL
  205. name (value): #text ( t2 )
  206. parent: name (value): p (X t2 xxx t1 )
  207. previousSibling: name (value): b (X)
  208. nextSibling: name (value): #text ( xxx )
  209. name (value): #text ( xxx )
  210. parent: name (value): p (X t2 xxx t1 )
  211. previousSibling: name (value): #text ( t2 )
  212. nextSibling: name (value): #text ( t1 )
  213. name (value): #text ( t1 )
  214. parent: name (value): p (X t2 xxx t1 )
  215. previousSibling: name (value): #text ( xxx )
  216. nextSibling: NULL
  217. Fragment:
  218. name (value): #document-fragment ()
  219. parent: NULL
  220. previousSibling: NULL
  221. nextSibling: NULL
  222. name (value): #text ( t5 )
  223. parent: name (value): #document-fragment ()
  224. previousSibling: NULL
  225. nextSibling: name (value): i ( frob )
  226. name (value): i ( frob )
  227. parent: name (value): #document-fragment ()
  228. previousSibling: name (value): #text ( t5 )
  229. nextSibling: name (value): #text ( t6 )
  230. name (value): #text ( frob )
  231. parent: name (value): i ( frob )
  232. previousSibling: NULL
  233. nextSibling: NULL
  234. name (value): #text ( t6 )
  235. parent: name (value): #document-fragment ()
  236. previousSibling: name (value): i ( frob )
  237. nextSibling: NULL
  238. Appending fragment to p:
  239. name (value): p (X t2 xxx t1 t5 frob t6 )
  240. parent: NULL
  241. previousSibling: NULL
  242. nextSibling: NULL
  243. name (value): b (X)
  244. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  245. previousSibling: NULL
  246. nextSibling: name (value): #text ( t2 )
  247. name (value): #text (X)
  248. parent: name (value): b (X)
  249. previousSibling: NULL
  250. nextSibling: NULL
  251. name (value): #text ( t2 )
  252. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  253. previousSibling: name (value): b (X)
  254. nextSibling: name (value): #text ( xxx )
  255. name (value): #text ( xxx )
  256. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  257. previousSibling: name (value): #text ( t2 )
  258. nextSibling: name (value): #text ( t1 )
  259. name (value): #text ( t1 )
  260. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  261. previousSibling: name (value): #text ( xxx )
  262. nextSibling: name (value): #text ( t5 )
  263. name (value): #text ( t5 )
  264. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  265. previousSibling: name (value): #text ( t1 )
  266. nextSibling: name (value): i ( frob )
  267. name (value): i ( frob )
  268. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  269. previousSibling: name (value): #text ( t5 )
  270. nextSibling: name (value): #text ( t6 )
  271. name (value): #text ( frob )
  272. parent: name (value): i ( frob )
  273. previousSibling: NULL
  274. nextSibling: NULL
  275. name (value): #text ( t6 )
  276. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  277. previousSibling: name (value): i ( frob )
  278. nextSibling: NULL
  279. Fragment:
  280. name (value): #document-fragment ()
  281. parent: NULL
  282. previousSibling: NULL
  283. nextSibling: NULL
  284. div:
  285. name (value): div ( t4 t3 xxx )
  286. parent: NULL
  287. previousSibling: NULL
  288. nextSibling: NULL
  289. name (value): #text ( t4 )
  290. parent: name (value): div ( t4 t3 xxx )
  291. previousSibling: NULL
  292. nextSibling: name (value): #text ( t3 )
  293. name (value): #text ( t3 )
  294. parent: name (value): div ( t4 t3 xxx )
  295. previousSibling: name (value): #text ( t4 )
  296. nextSibling: name (value): b ()
  297. name (value): b ()
  298. parent: name (value): div ( t4 t3 xxx )
  299. previousSibling: name (value): #text ( t3 )
  300. nextSibling: name (value): #text ( xxx )
  301. name (value): X ()
  302. parent: name (value): b ()
  303. previousSibling: NULL
  304. nextSibling: NULL
  305. name (value): #text ( xxx )
  306. parent: name (value): div ( t4 t3 xxx )
  307. previousSibling: name (value): b ()
  308. nextSibling: NULL
  309. Inserting fragment before t4
  310. Error (2) on line 109: DOMNode::insertBefore(): Document Fragment is empty
  311. name (value): div ( t4 t3 xxx )
  312. parent: NULL
  313. previousSibling: NULL
  314. nextSibling: NULL
  315. name (value): #text ( t4 )
  316. parent: name (value): div ( t4 t3 xxx )
  317. previousSibling: NULL
  318. nextSibling: name (value): #text ( t3 )
  319. name (value): #text ( t3 )
  320. parent: name (value): div ( t4 t3 xxx )
  321. previousSibling: name (value): #text ( t4 )
  322. nextSibling: name (value): b ()
  323. name (value): b ()
  324. parent: name (value): div ( t4 t3 xxx )
  325. previousSibling: name (value): #text ( t3 )
  326. nextSibling: name (value): #text ( xxx )
  327. name (value): X ()
  328. parent: name (value): b ()
  329. previousSibling: NULL
  330. nextSibling: NULL
  331. name (value): #text ( xxx )
  332. parent: name (value): div ( t4 t3 xxx )
  333. previousSibling: name (value): b ()
  334. nextSibling: NULL
  335. p:
  336. name (value): p (X t2 xxx t1 t5 frob t6 )
  337. parent: NULL
  338. previousSibling: NULL
  339. nextSibling: NULL
  340. name (value): b (X)
  341. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  342. previousSibling: NULL
  343. nextSibling: name (value): #text ( t2 )
  344. name (value): #text (X)
  345. parent: name (value): b (X)
  346. previousSibling: NULL
  347. nextSibling: NULL
  348. name (value): #text ( t2 )
  349. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  350. previousSibling: name (value): b (X)
  351. nextSibling: name (value): #text ( xxx )
  352. name (value): #text ( xxx )
  353. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  354. previousSibling: name (value): #text ( t2 )
  355. nextSibling: name (value): #text ( t1 )
  356. name (value): #text ( t1 )
  357. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  358. previousSibling: name (value): #text ( xxx )
  359. nextSibling: name (value): #text ( t5 )
  360. name (value): #text ( t5 )
  361. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  362. previousSibling: name (value): #text ( t1 )
  363. nextSibling: name (value): i ( frob )
  364. name (value): i ( frob )
  365. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  366. previousSibling: name (value): #text ( t5 )
  367. nextSibling: name (value): #text ( t6 )
  368. name (value): #text ( frob )
  369. parent: name (value): i ( frob )
  370. previousSibling: NULL
  371. nextSibling: NULL
  372. name (value): #text ( t6 )
  373. parent: name (value): p (X t2 xxx t1 t5 frob t6 )
  374. previousSibling: name (value): i ( frob )
  375. nextSibling: NULL