forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Debugging #22
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,141 @@ | ||
| --TEST-- | ||
| DOMDocument::adoptNode not implemented | ||
| Tests DOMDocument::adoptNode() | ||
| --EXTENSIONS-- | ||
| dom | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $dom = new DOMDocument(); | ||
| $dom->loadXML("<root />"); | ||
| $doc1 = new DOMDocument(); | ||
| $doc1->loadXML("<p><b>hi<i attrib=\"1\">x</i></b>world</p>"); | ||
| $doc2 = new DOMDocument(); | ||
| $doc2->loadXML("<div/>"); | ||
|
|
||
| $b_tag_element = $doc1->firstChild->firstChild; | ||
| $i_tag_element = $b_tag_element->lastChild; | ||
|
|
||
| echo "-- Owner document check before adopting --\n"; | ||
| var_dump($i_tag_element->ownerDocument === $doc1); | ||
| var_dump($i_tag_element->ownerDocument === $doc2); | ||
|
|
||
| echo "-- Trying to append child from other document --\n"; | ||
| try { | ||
| $dom->adoptNode($dom->documentElement); | ||
| } catch (\Error $e) { | ||
| echo $e->getMessage() . \PHP_EOL; | ||
| $doc2->firstChild->appendChild($b_tag_element); // Should fail because it's another document | ||
| } catch (\DOMException $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| echo "-- Adopting --\n"; | ||
| $adopted = $doc2->adoptNode($b_tag_element); | ||
| var_dump($adopted->textContent); | ||
| var_dump($doc1->saveXML()); | ||
| var_dump($doc2->saveXML()); | ||
|
|
||
| echo "-- Appending the adopted node --\n"; | ||
|
|
||
| $doc2->firstChild->appendChild($adopted); | ||
| var_dump($doc2->saveXML()); | ||
| var_dump($i_tag_element->ownerDocument === $doc1); | ||
| var_dump($i_tag_element->ownerDocument === $doc2); | ||
|
|
||
| echo "-- Adopt node to the original document --\n"; | ||
|
|
||
| $adopted = $doc1->adoptNode($doc1->firstChild->firstChild); | ||
| var_dump($adopted->textContent); | ||
| var_dump($doc1->saveXML()); | ||
|
|
||
| echo "-- Adopt a document --\n"; | ||
|
|
||
| try { | ||
| $doc1->adoptNode($doc1); | ||
| } catch (\DOMException $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| echo "-- Adopt an attribute --\n"; | ||
|
|
||
| $doc3 = new DOMDocument(); | ||
| $doc3->loadXML('<p align="center">hi</p>'); | ||
| $attribute = $doc3->firstChild->attributes->item(0); | ||
| var_dump($attribute->parentNode !== NULL); | ||
| $adopted = $doc3->adoptNode($attribute); | ||
| var_dump($adopted->parentNode === NULL); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ook ergens appenden en uitprinten |
||
|
|
||
| echo "-- Adopt an entity reference --\n"; | ||
|
|
||
| $doc4 = new DOMDocument(); | ||
| $doc4->loadXML(<<<'XML' | ||
| <?xml version='1.0' encoding='utf-8' ?> | ||
| <!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN" "http://www.docbook.org/xml/5.0/dtd/docbook.dtd" [ | ||
| <!ENTITY my_entity '<p>hi</p>'> ]> | ||
| <p/> | ||
| XML, LIBXML_NOENT); | ||
| $p_tag_element = $doc4->firstChild->nextSibling; | ||
| $entity_reference = $doc4->createEntityReference('my_entity'); | ||
| $p_tag_element->appendChild($entity_reference); | ||
| var_dump($doc4->saveXML()); | ||
| $doc3->adoptNode($entity_reference); | ||
| var_dump($doc4->saveXML()); | ||
| $doc3->firstChild->appendChild($entity_reference); | ||
| var_dump($doc3->saveXML()); | ||
|
|
||
| echo "-- Adopt a node and destroy the new document --\n"; | ||
| $doc1 = new DOMDocument(); | ||
| $doc1->appendChild($doc1->createElement('child')); | ||
| $doc2 = new DOMDocument(); | ||
| $doc2->appendChild($doc2->createElement('container')); | ||
| $doc2->documentElement->appendChild($child = $doc2->adoptNode($doc1->documentElement)); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ook docs uitprinten |
||
| unset($doc2); | ||
| var_dump($child->nodeName); | ||
| unset($doc1); | ||
| var_dump($child->nodeName); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Not yet implemented | ||
| -- Owner document check before adopting -- | ||
| bool(true) | ||
| bool(false) | ||
| -- Trying to append child from other document -- | ||
| Wrong Document Error | ||
| -- Adopting -- | ||
| string(3) "hix" | ||
| string(35) "<?xml version="1.0"?> | ||
| <p>world</p> | ||
| " | ||
| string(29) "<?xml version="1.0"?> | ||
| <div/> | ||
| " | ||
| -- Appending the adopted node -- | ||
| string(62) "<?xml version="1.0"?> | ||
| <div><b>hi<i attrib="1">x</i></b></div> | ||
| " | ||
| bool(false) | ||
| bool(true) | ||
| -- Adopt node to the original document -- | ||
| string(5) "world" | ||
| string(27) "<?xml version="1.0"?> | ||
| <p/> | ||
| " | ||
| -- Adopt a document -- | ||
| Not Supported Error | ||
| -- Adopt an attribute -- | ||
| bool(true) | ||
| bool(true) | ||
| -- Adopt an entity reference -- | ||
| string(202) "<?xml version="1.0" encoding="utf-8"?> | ||
| <!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN" "http://www.docbook.org/xml/5.0/dtd/docbook.dtd" [ | ||
| <!ENTITY my_entity "<p>hi</p>"> | ||
| ]> | ||
| <p>&my_entity;</p> | ||
| " | ||
| string(188) "<?xml version="1.0" encoding="utf-8"?> | ||
| <!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN" "http://www.docbook.org/xml/5.0/dtd/docbook.dtd" [ | ||
| <!ENTITY my_entity "<p>hi</p>"> | ||
| ]> | ||
| <p/> | ||
| " | ||
| string(43) "<?xml version="1.0"?> | ||
| <p>hi&my_entity;</p> | ||
| " | ||
| -- Adopt a node and destroy the new document -- | ||
| string(5) "child" | ||
| string(5) "child" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ws issue