mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Add test for serialization interaction
This commit is contained in:
parent
44485892df
commit
4ae3be379b
1 changed files with 53 additions and 0 deletions
53
ext/dom/tests/modern/common/namespace_sxe_interaction.phpt
Normal file
53
ext/dom/tests/modern/common/namespace_sxe_interaction.phpt
Normal file
|
@ -0,0 +1,53 @@
|
|||
--TEST--
|
||||
Serialization interaction between simplexml and dom for namespaces
|
||||
--EXTENSIONS--
|
||||
dom
|
||||
simplexml
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$dom = Dom\XMLDocument::createFromString('<root/>');
|
||||
$sxe = simplexml_import_dom($dom);
|
||||
|
||||
$sxe->addAttribute('a:attr', 'value', 'urn:a');
|
||||
$sxe->addChild('b:child', 'value', 'urn:b');
|
||||
$sxe->addChild('foo', 'value2');
|
||||
$dom->documentElement->firstElementChild->appendChild($dom->createElementNS('urn:c', 'c:child'));
|
||||
|
||||
echo "namespace c: ";
|
||||
var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('c'));
|
||||
echo "namespace b: ";
|
||||
var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('b'));
|
||||
echo "namespace a: ";
|
||||
var_dump($dom->documentElement->firstElementChild->firstElementChild->lookupNamespaceURI('a'));
|
||||
|
||||
echo "=== serialize SimpleXML ===\n";
|
||||
|
||||
echo $sxe->saveXML(), "\n";
|
||||
|
||||
echo "=== serialize DOM ===\n";
|
||||
|
||||
echo $dom->saveXML(), "\n\n";
|
||||
|
||||
echo "=== serialize imported DOM ===\n";
|
||||
|
||||
// Importing should yield the exact same document
|
||||
$new_dom = Dom\XMLDocument::createEmpty();
|
||||
$new_dom->append($new_dom->importNode($dom->documentElement, true));
|
||||
echo $new_dom->saveXML(), "\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
namespace c: string(5) "urn:c"
|
||||
namespace b: string(5) "urn:b"
|
||||
namespace a: NULL
|
||||
=== serialize SimpleXML ===
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child></root>
|
||||
=== serialize DOM ===
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child></root>
|
||||
|
||||
=== serialize imported DOM ===
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root xmlns:a="urn:a" a:attr="value"><b:child xmlns:b="urn:b">value<c:child xmlns:c="urn:c"/></b:child></root>
|
Loading…
Add table
Add a link
Reference in a new issue