--TEST-- Bug #47530 (Importing objects into document fragments creates bogus "default" namespace) --EXTENSIONS-- dom --FILE-- '); $root = $doc->documentElement; $frag = $doc->createDocumentFragment(); $frag->appendChild($doc->importNode($root->firstChild)); $root->appendChild($frag); echo $doc->saveXml(), "\n"; } function test_document_fragment_without_import() { $doc = Dom\XMLDocument::createFromString(''); $frag = $doc->createDocumentFragment(); $frag->appendChild($doc->createElementNS('https://php.net/bar', 'bar')); $frag->appendChild($doc->createElementNS('', 'bar')); $element = $doc->documentElement->firstChild; $element->appendChild($frag); unset($frag); // Free fragment, should not break getting the namespaceURI below echo $doc->saveXml(), "\n"; unset($doc); var_dump($element->firstChild->tagName); var_dump($element->firstChild->namespaceURI); var_dump($element->firstChild->nextSibling->tagName); var_dump($element->firstChild->nextSibling->namespaceURI); } function test_document_import() { $xml = <<

Test-Text

XML; $dom = Dom\XMLDocument::createFromString($xml); $dom2 = Dom\XMLDocument::createEmpty(); $importedNode = $dom2->importNode($dom->documentElement, true); $dom2->appendChild($importedNode); echo $dom2->saveXml(), "\n"; } function test_partial_document_import() { $xml = <<

Test-Text

More test text Even more test text
XML; $dom = Dom\XMLDocument::createFromString($xml); $dom2 = Dom\XMLDocument::createFromString(''); $importedNode = $dom2->importNode($dom->documentElement, true); $dom2->documentElement->appendChild($importedNode); // Freeing the original document shouldn't break the other document unset($importedNode); unset($dom); echo $dom2->saveXml(), "\n"; } function test_document_import_with_attributes() { $dom = Dom\XMLDocument::createFromString('

'); $dom2 = Dom\XMLDocument::createFromString('
'); $dom2->documentElement->appendChild($dom2->importNode($dom->documentElement->firstChild)); echo $dom2->saveXml(), "\n"; $dom2->documentElement->firstChild->appendChild($dom2->importNode($dom->documentElement->firstChild->nextSibling)); echo $dom2->saveXml(), "\n"; } function test_appendChild_with_shadowing() { $dom = Dom\XMLDocument::createFromString(''); $a = $dom->documentElement->firstElementChild; $b = $a->nextSibling; $b->remove(); $a->appendChild($b); echo $dom->saveXml(), "\n"; } echo "-- Test document fragment with import --\n"; test_document_fragment_with_import(); echo "-- Test document fragment without import --\n"; test_document_fragment_without_import(); echo "-- Test document import --\n"; test_document_import(); echo "-- Test partial document import --\n"; test_partial_document_import(); echo "-- Test document import with attributes --\n"; test_document_import_with_attributes(); echo "-- Test appendChild with shadowing --\n"; test_appendChild_with_shadowing(); ?> --EXPECT-- -- Test document fragment with import -- -- Test document fragment without import -- string(3) "bar" string(19) "https://php.net/bar" string(3) "bar" NULL -- Test document import --

Test-Text

-- Test partial document import --

Test-Text

More test text Even more test text
-- Test document import with attributes --

-- Test appendChild with shadowing --