1--TEST--
2Test DOM\Document::$body setter
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8echo "--- Replace body with itself ---\n";
9$dom = DOM\HTMLDocument::createFromString('<p>foo</p>', LIBXML_NOERROR);
10$dom->body = $dom->body;
11var_dump($dom->body?->nodeName);
12
13echo "--- Add body when there is no body yet ---\n";
14$dom = DOM\HTMLDocument::createFromString('<p>foo</p>', LIBXML_NOERROR);
15$dom->body->remove();
16$dom->body = $dom->createElementNS("http://www.w3.org/1999/xhtml", "prefix:body");
17var_dump($dom->body?->nodeName);
18
19echo "--- Replace old body with new body ---\n";
20$dom = DOM\HTMLDocument::createFromString('<p>foo</p>', LIBXML_NOERROR);
21$dom->body = $dom->createElementNS("http://www.w3.org/1999/xhtml", "prefix:body");
22var_dump($dom->body?->nodeName);
23
24echo "--- Replace old body with new body, while still having a reference to the old body ---\n";
25$dom = DOM\HTMLDocument::createFromString('<p>foo</p>', LIBXML_NOERROR);
26$old = $dom->body;
27$dom->body = $dom->createElementNS("http://www.w3.org/1999/xhtml", "prefix:body");
28var_dump($dom->body?->nodeName);
29var_dump($old->nodeName);
30
31echo "--- Special note from the DOM spec ---\n";
32$dom = DOM\XMLDocument::createFromString('<svg xmlns="http://www.w3.org/2000/svg"/>');
33$dom->body = $dom->createElementNS("http://www.w3.org/1999/xhtml", "body");
34var_dump($dom->body?->nodeName);
35
36?>
37--EXPECT--
38--- Replace body with itself ---
39string(4) "BODY"
40--- Add body when there is no body yet ---
41string(11) "PREFIX:BODY"
42--- Replace old body with new body ---
43string(11) "PREFIX:BODY"
44--- Replace old body with new body, while still having a reference to the old body ---
45string(11) "PREFIX:BODY"
46string(4) "BODY"
47--- Special note from the DOM spec ---
48NULL
49