diff options
Diffstat (limited to 'ext/simplexml')
| -rwxr-xr-x | ext/simplexml/tests/009b.phpt | 35 | ||||
| -rwxr-xr-x | ext/simplexml/tests/026.phpt | 40 | ||||
| -rwxr-xr-x | ext/simplexml/tests/027.phpt | 74 | ||||
| -rwxr-xr-x | ext/simplexml/tests/028.phpt | 42 | ||||
| -rwxr-xr-x | ext/simplexml/tests/029.phpt | 40 | ||||
| -rw-r--r-- | ext/simplexml/tests/030.phpt | 44 | ||||
| -rw-r--r-- | ext/simplexml/tests/031.phpt | 57 | ||||
| -rwxr-xr-x | ext/simplexml/tests/032.phpt | 45 | ||||
| -rwxr-xr-x | ext/simplexml/tests/033.phpt | 137 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug36611.phpt | 28 |
10 files changed, 542 insertions, 0 deletions
diff --git a/ext/simplexml/tests/009b.phpt b/ext/simplexml/tests/009b.phpt new file mode 100755 index 0000000000..dba300c72f --- /dev/null +++ b/ext/simplexml/tests/009b.phpt @@ -0,0 +1,35 @@ +--TEST-- +SimpleXML: foreach +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$sxe = simplexml_load_string(<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + Plain text. + <elem1 attr1='first'>Bla bla 1.<!-- comment --><elem2> + Here we have some text data. + </elem2></elem1> + <elem11 attr2='second'>Bla bla 2.</elem11> +</sxe> +EOF +); +var_dump($sxe->children()); +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(5) "elem1" + } + ["elem1"]=> + string(10) "Bla bla 1." + ["elem11"]=> + string(10) "Bla bla 2." +} +===DONE=== diff --git a/ext/simplexml/tests/026.phpt b/ext/simplexml/tests/026.phpt new file mode 100755 index 0000000000..d6de94be3d --- /dev/null +++ b/ext/simplexml/tests/026.phpt @@ -0,0 +1,40 @@ +--TEST-- +SimpleXML: getName() +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person>Jane</person> +</people> +EOF; + +function traverse_xml($xml, $pad = '') +{ + $name = $xml->getName(); + echo "$pad<$name"; + foreach($xml->attributes() as $attr => $value) + { + echo " $attr=\"$value\""; + } + echo ">" . trim($xml) . "\n"; + foreach($xml->children() as $node) + { + traverse_xml($node, $pad.' '); + } + echo $pad."</$name>\n"; +} + + +$people = simplexml_load_string($xml); +traverse_xml($people); + +?> +===DONE=== +--EXPECTF-- +<people> + <person>Jane + </person> +</people> +===DONE=== diff --git a/ext/simplexml/tests/027.phpt b/ext/simplexml/tests/027.phpt new file mode 100755 index 0000000000..f32786c7cc --- /dev/null +++ b/ext/simplexml/tests/027.phpt @@ -0,0 +1,74 @@ +--TEST-- +SimpleXML: Adding an elements +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people></people> +EOF; + +function traverse_xml($xml, $pad = '') +{ + $name = $xml->getName(); + echo "$pad<$name"; + foreach($xml->attributes() as $attr => $value) + { + echo " $attr=\"$value\""; + } + echo ">" . trim($xml) . "\n"; + foreach($xml->children() as $node) + { + traverse_xml($node, $pad.' '); + } + echo $pad."</$name>\n"; +} + + +$people = simplexml_load_string($xml); +traverse_xml($people); +$people->person = 'Joe'; +$people->person['gender'] = 'male'; +traverse_xml($people); +$people->person = 'Jane'; +traverse_xml($people); +$people->person['gender'] = 'female'; +$people->person[1] = 'Joe'; +$people->person[1]['gender'] = 'male'; +traverse_xml($people); +$people->person[3] = 'Minni-me'; +$people->person[2]['gender'] = 'male'; +traverse_xml($people); +$people->person[3]['gender'] = 'error'; + +?> +===DONE=== +--EXPECTF-- +<people> +</people> +<people> + <person gender="male">Joe + </person> +</people> +<people> + <person gender="male">Jane + </person> +</people> +<people> + <person gender="female">Jane + </person> + <person gender="male">Joe + </person> +</people> + +Warning: main(): Cannot add element person number 3 when only 2 such elements exist in %s027.php on line %d +<people> + <person gender="female">Jane + </person> + <person gender="male">Joe + </person> + <person gender="male">Minni-me + </person> +</people> + +Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %s027.php on line %d diff --git a/ext/simplexml/tests/028.phpt b/ext/simplexml/tests/028.phpt new file mode 100755 index 0000000000..753056b9ad --- /dev/null +++ b/ext/simplexml/tests/028.phpt @@ -0,0 +1,42 @@ +--TEST-- +SimpleXML: Adding an elements without text +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people></people> +EOF; + +function traverse_xml($xml, $pad = '') +{ + $name = $xml->getName(); + echo "$pad<$name"; + foreach($xml->attributes() as $attr => $value) + { + echo " $attr=\"$value\""; + } + echo ">" . trim($xml) . "\n"; + foreach($xml->children() as $node) + { + traverse_xml($node, $pad.' '); + } + echo $pad."</$name>\n"; +} + + +$people = simplexml_load_string($xml); +traverse_xml($people); +$people->person['name'] = 'John'; +traverse_xml($people); + +?> +===DONE=== +--EXPECTF-- +<people> +</people> +<people> + <person name="John"> + </person> +</people> +===DONE=== diff --git a/ext/simplexml/tests/029.phpt b/ext/simplexml/tests/029.phpt new file mode 100755 index 0000000000..86a4f308e3 --- /dev/null +++ b/ext/simplexml/tests/029.phpt @@ -0,0 +1,40 @@ +--TEST-- +SimpleXML: foreach and count +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"/> + <person name="John"> + <children> + <person name="Joe"/> + </children> + </person> + <person name="Jane"/> +</people> +EOF; + +$people = simplexml_load_string($xml); + +foreach($people as $person) +{ + var_dump((string)$person['name']); + var_dump(count($people)); + var_dump(count($person)); +} + +?> +===DONE=== +--EXPECTF-- +string(3) "Joe" +int(3) +int(0) +string(4) "John" +int(3) +int(1) +string(4) "Jane" +int(3) +int(0) +===DONE=== diff --git a/ext/simplexml/tests/030.phpt b/ext/simplexml/tests/030.phpt new file mode 100644 index 0000000000..774a5f1459 --- /dev/null +++ b/ext/simplexml/tests/030.phpt @@ -0,0 +1,44 @@ +--TEST-- +SimpleXML: isset and unset by offset +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<root s:att1="b" att1="a" + xmlns:s="urn::test" xmlns:t="urn::test-t"> + <child1>test</child1> + <child1>test 2</child1> + <s:child3 /> +</root> +EOF; + +$sxe = simplexml_load_string($xml); + +echo $sxe->child1[0]."\n"; +echo $sxe->child1[1]."\n\n"; + +var_dump(isset($sxe->child1[1])); +unset($sxe->child1[1]); +var_dump(isset($sxe->child1[1])); +echo "\n"; + +$atts = $sxe->attributes("urn::test"); +var_dump(isset($atts[0])); +unset($atts[0]); +var_dump(isset($atts[0])); +var_dump(isset($atts[TRUE])); + +?> +===DONE=== +--EXPECT-- +test +test 2 + +bool(true) +bool(false) + +bool(true) +bool(false) +bool(false) +===DONE=== diff --git a/ext/simplexml/tests/031.phpt b/ext/simplexml/tests/031.phpt new file mode 100644 index 0000000000..cd2d266ba1 --- /dev/null +++ b/ext/simplexml/tests/031.phpt @@ -0,0 +1,57 @@ +--TEST-- +SimpleXML: addChild and addAttribute +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<root s:att1="b" att1="a" + xmlns:s="urn::test" xmlns:t="urn::test-t"> + <child1>test</child1> + <child1>test 2</child1> + <s:child3 /> +</root> +EOF; + +$sxe = simplexml_load_string($xml); + +/* Add new attribute in a new namespace */ +$sxe->addAttribute('v:att11', 'xxx', 'urn::test-v'); + +/* Try to add attribute again -> display warning as method is for new Attr only */ +$sxe->addAttribute('v:att11', 'xxx', 'urn::test-v'); + +/* Add new attribute w/o namespace */ +$sxe->addAttribute('att2', 'no-ns'); + +$d = $sxe->attributes(); +/* Try to add element to attribute -> display warning and do not add */ +$d->addChild('m:test', 'myval', 'urn::test'); + + +/* Test adding elements in various configurations */ +$sxe->addChild('m:test1', 'myval', 'urn::test'); + +/* New namespace test */ +$n = $sxe->addChild('m:test2', 'myval', 'urn::testnew'); + +$sxe->addChild('test3', 'myval', 'urn::testnew'); +$sxe->addChild('test4', 'myval'); + +/* Does not add prefix here although name is valid (but discouraged) - change behavior? */ +$sxe->addChild('s:test5', 'myval'); + +echo $sxe->asXML(); +?> +===DONE=== +--EXPECTF-- +Warning: SimpleXMLElement::addAttribute(): Attribute already exists in %s031.php on line %d + +Warning: SimpleXMLElement::addChild(): Cannot add element to attributes in %s031.php on line %d +<?xml version="1.0"?> +<root xmlns:s="urn::test" xmlns:t="urn::test-t" xmlns:v="urn::test-v" s:att1="b" att1="a" v:att11="xxx" att2="no-ns"> + <child1>test</child1> + <child1>test 2</child1> + <s:child3/> +<s:test1>myval</s:test1><m:test2 xmlns:m="urn::testnew">myval</m:test2><test3 xmlns="urn::testnew">myval</test3><test4>myval</test4><test5>myval</test5></root> +===DONE=== diff --git a/ext/simplexml/tests/032.phpt b/ext/simplexml/tests/032.phpt new file mode 100755 index 0000000000..5c2225146a --- /dev/null +++ b/ext/simplexml/tests/032.phpt @@ -0,0 +1,45 @@ +--TEST-- +SimpleXML: comparing instances +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"/> + <person name="John"> + <children> + <person name="Joe"/> + </children> + </person> + <person name="Jane"/> +</people> +EOF; + +$xml1 =<<<EOF +<people> + <person name="John"> + <children> + <person name="Joe"/> + </children> + </person> + <person name="Jane"/> +</people> +EOF; + + +$people = simplexml_load_string($xml); +$people1 = simplexml_load_string($xml); +$people2 = simplexml_load_string($xml1); + +var_dump($people1 == $people); +var_dump($people2 == $people); +var_dump($people2 == $people1); + +?> +===DONE=== +--EXPECTF-- +bool(true) +bool(false) +bool(false) +===DONE=== diff --git a/ext/simplexml/tests/033.phpt b/ext/simplexml/tests/033.phpt new file mode 100755 index 0000000000..ba01b21555 --- /dev/null +++ b/ext/simplexml/tests/033.phpt @@ -0,0 +1,137 @@ +--TEST-- +SimpleXML: casting instances +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<people> +test + <person name="Joe"/> + <person name="John"> + <children> + <person name="Joe"/> + </children> + </person> + <person name="Jane"/> +</people> +EOF; + +$foo = simplexml_load_string( "<foo />" ); +$people = simplexml_load_string($xml); + +var_dump((bool)$foo); +var_dump((bool)$people); +var_dump((int)$foo); +var_dump((int)$people); +var_dump((double)$foo); +var_dump((double)$people); +var_dump((string)$foo); +var_dump((string)$people); +var_dump((array)$foo); +var_dump((array)$people); +var_dump((object)$foo); +var_dump((object)$people); + +?> +===DONE=== +--EXPECTF-- +bool(false) +bool(true) +int(0) +int(0) +float(0) +float(0) +string(0) "" +string(15) " +test + + + +" +array(0) { +} +array(1) { + ["person"]=> + array(3) { + [0]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["name"]=> + string(3) "Joe" + } + } + [1]=> + object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["name"]=> + string(4) "John" + } + ["children"]=> + object(SimpleXMLElement)#%d (1) { + ["person"]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["name"]=> + string(3) "Joe" + } + } + } + } + [2]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["name"]=> + string(4) "Jane" + } + } + } +} +object(SimpleXMLElement)#%d (0) { +} +object(SimpleXMLElement)#%d (1) { + ["person"]=> + array(3) { + [0]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["name"]=> + string(3) "Joe" + } + } + [1]=> + object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["name"]=> + string(4) "John" + } + ["children"]=> + object(SimpleXMLElement)#%d (1) { + ["person"]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["name"]=> + string(3) "Joe" + } + } + } + } + [2]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["name"]=> + string(4) "Jane" + } + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/bug36611.phpt b/ext/simplexml/tests/bug36611.phpt new file mode 100644 index 0000000000..fdfed0d019 --- /dev/null +++ b/ext/simplexml/tests/bug36611.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #36611 (assignment to SimpleXML object attribute changes argument type to string) +--FILE-- +<?php + +$xml_str = <<<EOD +<?xml version="1.0" encoding="ISO-8859-1" ?> +<c_fpobel > + <pos > + <pos/> + </pos> +</c_fpobel> +EOD; + +$xml = simplexml_load_string ($xml_str) ; + +$val = 1; + +var_dump($val); +$obj->pos["act_idx"] = $val; +var_dump($val) ; + +echo "Done\n"; +?> +--EXPECT-- +int(1) +int(1) +Done |
