Add a "profile" of simplexml's expected behaviour in the form of tests.

This will be expanded as issues arise and will be a formal definition
(in code) of simplexml's behaviour.
This commit is contained in:
Sterling Hughes 2004-01-16 20:50:29 +00:00
parent 69e6b296e0
commit 7f5b508f26
11 changed files with 227 additions and 0 deletions

View File

@ -0,0 +1,18 @@
--TEST--
SimpleXML [profile]: Accessing a simple node
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
$root = simplexml_load_string('<?xml version="1.0"?>
<root>
<child>Hello</child>
</root>
');
echo $root->child;
echo "\n---Done---\n";
?>
--EXPECT--
Hello
---Done---

View File

@ -0,0 +1,21 @@
--TEST--
SimpleXML [profile]: Accessing an array of subnodes
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
$root = simplexml_load_string('<?xml version="1.0"?>
<root>
<child>Hello</child>
<child>World</child>
</root>
');
foreach ($root->child as $child) {
echo "$child ";
}
echo "\n---Done---\n";
?>
--EXPECT--
Hello World
---Done---

View File

@ -0,0 +1,18 @@
--TEST--
SimpleXML [profile]: Accessing an attribute
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
$root = simplexml_load_string('<?xml version="1.0"?>
<root>
<child attribute="Sample" />
</root>
');
echo $root->child['attribute'];
echo "\n---Done---\n";
?>
--EXPECT--
Sample
---Done---

View File

@ -0,0 +1,18 @@
--TEST--
SimpleXML [profile]: Accessing a namespaced element
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns">
<reserved:child>Hello</reserved:child>
</root>
');
echo $root->reserved->child;
echo "\n---Done---\n";
?>
--EXPECT--
Hello
---Done---

View File

@ -0,0 +1,22 @@
--TEST--
SimpleXML [profile]: Accessing an aliased namespaced element
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
error_reporting(E_ALL & ~E_NOTICE);
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns">
<reserved:child>Hello</reserved:child>
</root>
');
$root->register_ns('myns', 'reserved-ns');
echo $root->myns->child;
echo $root->reserved->child;
echo "\n---Done---\n";
?>
--EXPECT--
Hello
---Done---

View File

@ -0,0 +1,19 @@
--TEST--
SimpleXML [profile]: Accessing a namespaced attribute
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
error_reporting(E_ALL & ~E_NOTICE);
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns">
<child reserved:attribute="Sample" />
</root>
');
echo $root->child['reserved:attribute'];
echo "\n---Done---\n";
?>
--EXPECT--
Sample
---Done---

View File

@ -0,0 +1,22 @@
--TEST--
SimpleXML [profile]: Accessing an aliased namespaced attribute
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
error_reporting(E_ALL & ~E_NOTICE);
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns">
<child reserved:attribute="Sample" />
</root>
');
$root->register_ns('myns', 'reserved-ns');
echo $root->child['reserved:attribute'];
echo $root->child['myns:attribute'];
echo "\n---Done---\n";
?>
--EXPECT--
Sample
---Done---

View File

@ -0,0 +1,19 @@
--TEST--
SimpleXML [profile]: Accessing a namespaced attribute without a namespace
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
error_reporting(E_ALL & ~E_NOTICE);
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns">
<child reserved:attribute="Sample" />
</root>
');
echo $root->child['attribute'];
echo "\n---Done---\n";
?>
--EXPECT--
---Done---

View File

@ -0,0 +1,19 @@
--TEST--
SimpleXML [profile]: Accessing a namespaced element without a namespace
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
error_reporting(E_ALL & ~E_NOTICE);
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns">
<reserved:child>Hello</reserved:child>
</root>
');
echo $root->child;
echo "\n---Done---\n";
?>
--EXPECT--
---Done---

View File

@ -0,0 +1,25 @@
--TEST--
SimpleXML [profile]: Accessing two attributes with the same name, but different namespaces
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
error_reporting(E_ALL & ~E_NOTICE);
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns" xmlns:special="special-ns">
<child reserved:attribute="Sample" special:attribute="Test" />
</root>
');
echo $root->child['reserved:attribute'];
echo "\n";
echo $root->child['special:attribute'];
foreach ($root->child['attribute'] as $attr) {
echo "$attr\n";
}
echo "\n---Done---\n";
?>
--EXPECT--
Sample
Test
---Done---

View File

@ -0,0 +1,26 @@
--TEST--
SimpleXML [profile]: Accessing two elements with the same name, but different namespaces
--SKIPIF--
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
--FILE--
<?php
error_reporting(E_ALL & ~E_NOTICE);
$root = simplexml_load_string('<?xml version="1.0"?>
<root xmlns:reserved="reserved-ns" xmlns:special="special-ns">
<reserved:child>Hello</reserved:child>
<special:child>World</special:child>
</root>
');
echo $root->reserved->child;
echo "\n";
echo $root->special->child;
foreach ($root->child as $child) {
echo "$child\n";
}
echo "\n---Done---\n";
?>
--EXPECT--
Hello
World
---Done---