diff options
Diffstat (limited to 'ext/simplexml/tests')
104 files changed, 4630 insertions, 0 deletions
diff --git a/ext/simplexml/tests/000.phpt b/ext/simplexml/tests/000.phpt new file mode 100644 index 0000000..51dbe3b --- /dev/null +++ b/ext/simplexml/tests/000.phpt @@ -0,0 +1,254 @@ +--TEST-- +SimpleXML: var_dump() +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$sxe = simplexml_load_file(dirname(__FILE__).'/000.xml'); + +function test($what) +{ + global $sxe; + echo "===$what\n"; + eval("var_dump(isset(\$$what));"); + eval("var_dump((bool)\$$what);"); + eval("var_dump(count(\$$what));"); + eval("var_dump(\$$what);"); +} + +test('sxe'); +test('sxe->elem1'); +test('sxe->elem1[0]'); +test('sxe->elem1[0]->elem2'); +test('sxe->elem1[0]->elem2->bla'); +if (!ini_get("unicode_semantics")) test('sxe->elem1[0]["attr1"]'); +test('sxe->elem1[0]->attr1'); +test('sxe->elem1[1]'); +test('sxe->elem1[2]'); +test('sxe->elem11'); +test('sxe->elem11->elem111'); +test('sxe->elem11->elem111->elem1111'); +test('sxe->elem22'); +test('sxe->elem22->elem222'); +test('sxe->elem22->attr22'); +test('sxe->elem22["attr22"]'); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +===sxe +bool(true) +bool(true) +int(3) +object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(3) "123" + } + ["elem1"]=> + array(2) { + [0]=> + string(36) "There is some text.Here is some more" + [1]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(2) { + ["attr1"]=> + string(2) "11" + ["attr2"]=> + string(2) "12" + } + } + } + ["elem11"]=> + object(SimpleXMLElement)#%d (1) { + ["elem111"]=> + object(SimpleXMLElement)#%d (1) { + ["elem1111"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } +} +===sxe->elem1 +bool(true) +bool(true) +int(2) +object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(2) { + ["attr1"]=> + string(5) "first" + ["attr2"]=> + string(6) "second" + } + ["comment"]=> + object(SimpleXMLElement)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(2) { + ["att25"]=> + string(2) "25" + ["att42"]=> + string(2) "42" + } + ["elem3"]=> + object(SimpleXMLElement)#%d (1) { + ["elem4"]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } + } +} +===sxe->elem1[0] +bool(true) +bool(true) +int(1) +object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(2) { + ["attr1"]=> + string(5) "first" + ["attr2"]=> + string(6) "second" + } + ["comment"]=> + object(SimpleXMLElement)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(2) { + ["att25"]=> + string(2) "25" + ["att42"]=> + string(2) "42" + } + ["elem3"]=> + object(SimpleXMLElement)#%d (1) { + ["elem4"]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } + } +} +===sxe->elem1[0]->elem2 +bool(true) +bool(true) +int(1) +object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(2) { + ["att25"]=> + string(2) "25" + ["att42"]=> + string(2) "42" + } + ["elem3"]=> + object(SimpleXMLElement)#%d (1) { + ["elem4"]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } +} +===sxe->elem1[0]->elem2->bla +bool(false) +bool(false) +int(0) +object(SimpleXMLElement)#%d (0) { +} +===sxe->elem1[0]["attr1"] +bool(true) +bool(true) +int(0) +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "first" +} +===sxe->elem1[0]->attr1 +bool(false) +bool(false) +int(0) +object(SimpleXMLElement)#%d (0) { +} +===sxe->elem1[1] +bool(true) +bool(true) +int(0) +object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(2) { + ["attr1"]=> + string(2) "11" + ["attr2"]=> + string(2) "12" + } +} +===sxe->elem1[2] +bool(false) +bool(false) +int(0) +NULL +===sxe->elem11 +bool(true) +bool(true) +int(1) +object(SimpleXMLElement)#%d (1) { + ["elem111"]=> + object(SimpleXMLElement)#%d (1) { + ["elem1111"]=> + object(SimpleXMLElement)#%d (0) { + } + } +} +===sxe->elem11->elem111 +bool(true) +bool(true) +int(1) +object(SimpleXMLElement)#%d (1) { + ["elem1111"]=> + object(SimpleXMLElement)#%d (0) { + } +} +===sxe->elem11->elem111->elem1111 +bool(true) +bool(true) +int(1) +object(SimpleXMLElement)#%d (0) { +} +===sxe->elem22 +bool(false) +bool(false) +int(0) +object(SimpleXMLElement)#%d (0) { +} +===sxe->elem22->elem222 +bool(false) +bool(false) +int(0) +NULL +===sxe->elem22->attr22 +bool(false) +bool(false) +int(0) +NULL +===sxe->elem22["attr22"] +bool(false) +bool(false) +int(0) +NULL +===DONE=== diff --git a/ext/simplexml/tests/000.xml b/ext/simplexml/tests/000.xml new file mode 100755 index 0000000..b0f2785 --- /dev/null +++ b/ext/simplexml/tests/000.xml @@ -0,0 +1,16 @@ +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "sxe.dtd" [ +<!ENTITY % incent SYSTEM "sxe.ent"> +%incent; +]> +<sxe id="123"> + <elem1 attr1='first' attr2='second'>There is some text.<!-- comment --><elem2 att25='25' att42='42'> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2>Here is some more</elem1> + <elem1 attr1='11' attr2='12'/> + <elem11><elem111><elem1111/></elem111></elem11> +</sxe>
\ No newline at end of file diff --git a/ext/simplexml/tests/001.phpt b/ext/simplexml/tests/001.phpt new file mode 100644 index 0000000..0be7771 --- /dev/null +++ b/ext/simplexml/tests/001.phpt @@ -0,0 +1,43 @@ +--TEST-- +SimpleXML: Simple document +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +var_dump(simplexml_load_file(dirname(__FILE__).'/sxe.xml')); + +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(5) "elem1" + } + ["elem1"]=> + object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(5) "first" + } + ["comment"]=> + object(SimpleXMLElement)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLElement)#%d (1) { + ["elem3"]=> + object(SimpleXMLElement)#%d (1) { + ["elem4"]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/002.phpt b/ext/simplexml/tests/002.phpt new file mode 100644 index 0000000..4f1f6b6 --- /dev/null +++ b/ext/simplexml/tests/002.phpt @@ -0,0 +1,64 @@ +--TEST-- +SimpleXML: clone +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + <elem1 attr1='first'> + <!-- comment --> + <elem2> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF; + +$sxe = simplexml_load_string($xml); + +$copy = clone $sxe; + +var_dump($copy); + +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(5) "elem1" + } + ["elem1"]=> + object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(5) "first" + } + ["comment"]=> + object(SimpleXMLElement)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLElement)#%d (1) { + ["elem3"]=> + object(SimpleXMLElement)#%d (1) { + ["elem4"]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/003.phpt b/ext/simplexml/tests/003.phpt new file mode 100644 index 0000000..105f616 --- /dev/null +++ b/ext/simplexml/tests/003.phpt @@ -0,0 +1,69 @@ +--TEST-- +SimpleXML: Entities +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd" [ +<!ENTITY included-entity "This is text included from an entity"> +]> +<sxe id="elem1"> + Plain text. + <elem1 attr1='first'> + <!-- comment --> + <elem2> + <elem3> + &included-entity; + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF; + +var_dump(simplexml_load_string($xml)); + +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(5) "elem1" + } + ["elem1"]=> + object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(5) "first" + } + ["comment"]=> + object(SimpleXMLElement)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLElement)#%d (1) { + ["elem3"]=> + object(SimpleXMLElement)#%d (2) { + ["included-entity"]=> + object(SimpleXMLElement)#%d (1) { + ["included-entity"]=> + string(36) "This is text included from an entity" + } + ["elem4"]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/004.phpt b/ext/simplexml/tests/004.phpt new file mode 100644 index 0000000..21cb546 --- /dev/null +++ b/ext/simplexml/tests/004.phpt @@ -0,0 +1,68 @@ +--TEST-- +SimpleXML: CDATA +--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'> + <!-- comment --> + <elem2> + <![CDATA[CDATA block]]> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF +); + +var_dump($sxe); + +$elem1 = $sxe->elem1; +$elem2 = $elem1->elem2; +var_dump(trim((string)$elem2)); + +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(5) "elem1" + } + ["elem1"]=> + object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(5) "first" + } + ["comment"]=> + object(SimpleXMLElement)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLElement)#%d (1) { + ["elem3"]=> + object(SimpleXMLElement)#%d (1) { + ["elem4"]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } + } + } +} +string(11) "CDATA block" +===DONE=== diff --git a/ext/simplexml/tests/005.phpt b/ext/simplexml/tests/005.phpt new file mode 100644 index 0000000..1411065 --- /dev/null +++ b/ext/simplexml/tests/005.phpt @@ -0,0 +1,40 @@ +--TEST-- +SimpleXML: Text data +--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'> + <!-- comment --> + <elem2> + Here we have some text data. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF +); + +var_dump(trim($sxe->elem1->elem2)); +var_dump(trim($sxe->elem1->elem2->elem3)); +var_dump(trim($sxe->elem1->elem2->elem3->elem4)); + +echo "---Done---\n"; + +?> +--EXPECT-- +string(28) "Here we have some text data." +string(19) "And here some more." +string(15) "Wow once again." +---Done--- diff --git a/ext/simplexml/tests/006.phpt b/ext/simplexml/tests/006.phpt new file mode 100644 index 0000000..72ad0c8 --- /dev/null +++ b/ext/simplexml/tests/006.phpt @@ -0,0 +1,80 @@ +--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. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + <elem111> + Foo Bar + </elem111> + </elem11> +</sxe> +EOF +); + +foreach($sxe as $name => $data) { + var_dump($name); + var_dump(trim($data)); +} + +echo "===CLONE===\n"; + +foreach(clone $sxe as $name => $data) { + var_dump($name); + var_dump(trim($data)); +} + +echo "===ELEMENT===\n"; + +foreach($sxe->elem11 as $name => $data) { + var_dump($name); + var_dump(trim($data)); +} + +echo "===COMMENT===\n"; + +foreach($sxe->elem1 as $name => $data) { + var_dump($name); + var_dump(trim($data)); +} + +?> +===DONE=== +--EXPECT-- +string(5) "elem1" +string(10) "Bla bla 1." +string(6) "elem11" +string(10) "Bla bla 2." +===CLONE=== +string(5) "elem1" +string(10) "Bla bla 1." +string(6) "elem11" +string(10) "Bla bla 2." +===ELEMENT=== +string(6) "elem11" +string(10) "Bla bla 2." +===COMMENT=== +string(5) "elem1" +string(10) "Bla bla 1." +===DONE=== diff --git a/ext/simplexml/tests/007.phpt b/ext/simplexml/tests/007.phpt new file mode 100644 index 0000000..51d7a84 --- /dev/null +++ b/ext/simplexml/tests/007.phpt @@ -0,0 +1,97 @@ +--TEST-- +SimpleXML: Attributes +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + <elem1 attr1='first'> + <!-- comment --> + <elem2> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF; + +$sxe = simplexml_load_string($xml); + +echo "===Property===\n"; +var_dump($sxe->elem1); +echo "===Array===\n"; +var_dump($sxe['id']); +var_dump($sxe->elem1['attr1']); +echo "===Set===\n"; +$sxe['id'] = "Changed1"; +var_dump($sxe['id']); +$sxe->elem1['attr1'] = 12; +var_dump($sxe->elem1['attr1']); +echo "===Unset===\n"; +unset($sxe['id']); +var_dump($sxe['id']); +unset($sxe->elem1['attr1']); +var_dump($sxe->elem1['attr1']); +echo "===Misc.===\n"; +$a = 4; +var_dump($a); +$dummy = $sxe->elem1[$a]; +var_dump($a); +?> +===Done=== +--EXPECTF-- +===Property=== +object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(5) "first" + } + ["comment"]=> + object(SimpleXMLElement)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLElement)#%d (1) { + ["elem3"]=> + object(SimpleXMLElement)#%d (1) { + ["elem4"]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } + } + } +} +===Array=== +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "elem1" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "first" +} +===Set=== +object(SimpleXMLElement)#%d (1) { + [0]=> + string(8) "Changed1" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) "12" +} +===Unset=== +NULL +NULL +===Misc.=== +int(4) +int(4) +===Done=== diff --git a/ext/simplexml/tests/008.phpt b/ext/simplexml/tests/008.phpt new file mode 100644 index 0000000..8734ba4 --- /dev/null +++ b/ext/simplexml/tests/008.phpt @@ -0,0 +1,48 @@ +--TEST-- +SimpleXML: XPath +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + <elem1 attr1='first'> + <!-- comment --> + <elem2> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF; + +$sxe = simplexml_load_string($xml); + +var_dump($sxe->xpath("elem1/elem2/elem3/elem4")); +//valid expression +var_dump($sxe->xpath("***")); +//invalid expression +var_dump($sxe->xpath("**")); +?> +--EXPECTF-- +array(1) { + [0]=> + object(SimpleXMLElement)#%d (1) { + ["test"]=> + object(SimpleXMLElement)#%d (0) { + } + } +} +array(0) { +} + +Warning: SimpleXMLElement::xpath(): Invalid expression in %s on line %d + +Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in %s on line %d +bool(false) diff --git a/ext/simplexml/tests/009.phpt b/ext/simplexml/tests/009.phpt new file mode 100644 index 0000000..a76f3d1 --- /dev/null +++ b/ext/simplexml/tests/009.phpt @@ -0,0 +1,45 @@ +--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. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + </elem11> +</sxe> +EOF +); +foreach($sxe->children() as $name=>$val) { + var_dump($name); + var_dump(get_class($val)); + var_dump(trim($val)); +} +?> +===DONE=== +--EXPECT-- +string(5) "elem1" +string(16) "SimpleXMLElement" +string(10) "Bla bla 1." +string(6) "elem11" +string(16) "SimpleXMLElement" +string(10) "Bla bla 2." +===DONE=== diff --git a/ext/simplexml/tests/009b.phpt b/ext/simplexml/tests/009b.phpt new file mode 100644 index 0000000..dba300c --- /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/010.phpt b/ext/simplexml/tests/010.phpt new file mode 100644 index 0000000..2677809 --- /dev/null +++ b/ext/simplexml/tests/010.phpt @@ -0,0 +1,64 @@ +--TEST-- +SimpleXML: Simple Inheritance +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +class simplexml_inherited extends SimpleXMLElement +{ +} + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + <elem1 attr1='first'> + <!-- comment --> + <elem2> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF; + +var_dump(simplexml_load_string($xml, 'simplexml_inherited')); + +?> +===DONE=== +--EXPECTF-- +object(simplexml_inherited)#%d (2) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(5) "elem1" + } + ["elem1"]=> + object(simplexml_inherited)#%d (3) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(5) "first" + } + ["comment"]=> + object(simplexml_inherited)#%d (0) { + } + ["elem2"]=> + object(simplexml_inherited)#%d (1) { + ["elem3"]=> + object(simplexml_inherited)#%d (1) { + ["elem4"]=> + object(simplexml_inherited)#%d (1) { + ["test"]=> + object(simplexml_inherited)#%d (0) { + } + } + } + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/011.phpt b/ext/simplexml/tests/011.phpt new file mode 100644 index 0000000..74ea470 --- /dev/null +++ b/ext/simplexml/tests/011.phpt @@ -0,0 +1,47 @@ +--TEST-- +SimpleXML: echo/print +--SKIPIF-- +<?php + if (!extension_loaded('simplexml')) print 'skip'; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version="1.0" encoding="ISO-8859-1" ?> +<foo> + <bar>bar</bar> + <baz>baz1</baz> + <baz>baz2</baz> +</foo> +EOF; + +$sxe = simplexml_load_string($xml); + +echo "===BAR===\n"; +echo $sxe->bar; +echo "\n"; + +echo "===BAZ===\n"; +echo $sxe->baz; +echo "\n"; + +echo "===BAZ0===\n"; +echo $sxe->baz[0]; +echo "\n"; + +echo "===BAZ1===\n"; +print $sxe->baz[1]; +echo "\n"; +?> +===DONE=== +--EXPECT-- +===BAR=== +bar +===BAZ=== +baz1 +===BAZ0=== +baz1 +===BAZ1=== +baz2 +===DONE=== diff --git a/ext/simplexml/tests/012.phpt b/ext/simplexml/tests/012.phpt new file mode 100644 index 0000000..2fc9bec --- /dev/null +++ b/ext/simplexml/tests/012.phpt @@ -0,0 +1,40 @@ +--TEST-- +SimpleXML: Attribute creation +--SKIPIF-- +<?php + if (!extension_loaded('simplexml')) print 'skip'; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version="1.0" encoding="ISO-8859-1" ?> +<foo/> +EOF; + +$sxe = simplexml_load_string($xml); + + +$sxe[""] = "warning"; +$sxe["attr"] = "value"; + +echo $sxe->asXML(); + +$sxe["attr"] = "new value"; + +echo $sxe->asXML(); + +$sxe[] = "error"; + +__HALT_COMPILER(); +?> +===DONE=== +--EXPECTF-- + +Warning: main(): Cannot write or create unnamed attribute in %s012.php on line %d +<?xml version="1.0" encoding="ISO-8859-1"?> +<foo attr="value"/> +<?xml version="1.0" encoding="ISO-8859-1"?> +<foo attr="new value"/> + +Fatal error: main(): Cannot create unnamed attribute in %s012.php on line %d diff --git a/ext/simplexml/tests/013.phpt b/ext/simplexml/tests/013.phpt new file mode 100644 index 0000000..56c57df --- /dev/null +++ b/ext/simplexml/tests/013.phpt @@ -0,0 +1,23 @@ +--TEST-- +SimpleXML: Split text content +--SKIPIF-- +<?php + if (!extension_loaded('simplexml')) print 'skip'; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version="1.0" encoding="ISO-8859-1" ?> +<foo>bar<baz/>bar</foo> +EOF; + +$sxe = simplexml_load_string($xml); + +var_dump((string)$sxe); + +?> +===DONE=== +--EXPECT-- +string(6) "barbar" +===DONE=== diff --git a/ext/simplexml/tests/014.phpt b/ext/simplexml/tests/014.phpt new file mode 100644 index 0000000..d1d736e --- /dev/null +++ b/ext/simplexml/tests/014.phpt @@ -0,0 +1,60 @@ +--TEST-- +SimpleXML: adding/removing attributes (direct) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"></person> +</people> +EOF; + +$people = simplexml_load_string($xml); +var_dump($people->person['name']); +var_dump($people->person['age']); +$person = $people->person; +$person['name'] = "XXX"; +var_dump($people->person['name']); +$people->person['age'] = 30; +var_dump($people->person['age']); +echo "---Unset:---\n"; +unset($people->person['age']); +echo "---Unset?---\n"; +var_dump($people->person['age']); +var_dump(isset($people->person['age'])); +$people->person['age'] = 30; +echo "---Unsupported---\n"; +var_dump($people->person['age']); +$people->person['age'] += 5; +var_dump($people->person['age']); +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Joe" +} +NULL +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "XXX" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) "30" +} +---Unset:--- +---Unset?--- +NULL +bool(false) +---Unsupported--- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) "30" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) "35" +} +===DONE=== diff --git a/ext/simplexml/tests/014a.phpt b/ext/simplexml/tests/014a.phpt new file mode 100644 index 0000000..649828b --- /dev/null +++ b/ext/simplexml/tests/014a.phpt @@ -0,0 +1,56 @@ +--TEST-- +SimpleXML: adding/removing attributes (single) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"></person> +</people> +EOF; + +$people = simplexml_load_string($xml); +var_dump($people->person[0]['name']); +var_dump($people->person[0]['age']); +$person = $people->person[0]; +$person['name'] = "XXX"; +var_dump($people->person[0]['name']); +$people->person[0]['age'] = 30; +var_dump($people->person[0]['age']); +echo "---Unset:---\n"; +unset($people->person[0]['age']); +echo "---Unset?---\n"; +var_dump($people->person[0]['age']); +var_dump(isset($people->person[0]['age'])); +echo "---Unsupported---\n"; +var_dump($people->person[0]['age']); +$people->person['age'] += 5; +var_dump($people->person[0]['age']); +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Joe" +} +NULL +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "XXX" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) "30" +} +---Unset:--- +---Unset?--- +NULL +bool(false) +---Unsupported--- +NULL +object(SimpleXMLElement)#%d (1) { + [0]=> + string(1) "5" +} +===DONE=== diff --git a/ext/simplexml/tests/014b.phpt b/ext/simplexml/tests/014b.phpt new file mode 100644 index 0000000..0343967 --- /dev/null +++ b/ext/simplexml/tests/014b.phpt @@ -0,0 +1,55 @@ +--TEST-- +SimpleXML: adding/removing attributes (second) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"></person> + <person name="Boe"></person> +</people> +EOF; + +$people = simplexml_load_string($xml); +var_dump($people->person[0]['name']); +var_dump($people->person[1]['age']); +$person = $people->person[1]; +$person['name'] = "XXX"; +var_dump($people->person[1]['name']); +$people->person[1]['age'] = 30; +var_dump($people->person[1]['age']); +echo "---Unset:---\n"; +unset($people->person[1]['age']); +echo "---Unset?---\n"; +var_dump($people->person[1]['age']); +var_dump(isset($people->person[1]['age'])); +echo "---Unsupported---\n"; +$people->person[1]['age'] += 5; +var_dump($people->person[1]['age']); +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Joe" +} +NULL +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "XXX" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) "30" +} +---Unset:--- +---Unset?--- +NULL +bool(false) +---Unsupported--- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(1) "5" +} +===DONE=== diff --git a/ext/simplexml/tests/015.phpt b/ext/simplexml/tests/015.phpt new file mode 100644 index 0000000..11e9cd5 --- /dev/null +++ b/ext/simplexml/tests/015.phpt @@ -0,0 +1,56 @@ +--TEST-- +SimpleXML: accessing singular subnode as array +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"></person> +</people> +EOF; + +$xml2 =<<<EOF +<people> + <person name="Joe"></person> + <person name="Boe"></person> +</people> +EOF; + +$people = simplexml_load_string($xml); +var_dump($people->person['name']); +var_dump($people->person[0]['name']); +//$people->person['name'] = "XXX"; +//var_dump($people->person['name']); +//var_dump($people->person[0]['name']); +//$people->person[0]['name'] = "YYY"; +//var_dump($people->person['name']); +//var_dump($people->person[0]['name']); +//unset($people->person[0]['name']); +//var_dump($people->person['name']); +//var_dump($people->person[0]['name']); +//var_dump(isset($people->person['name'])); +//var_dump(isset($people->person[0]['name'])); +$people = simplexml_load_string($xml2); +var_dump($people->person[0]['name']); +var_dump($people->person[1]['name']); +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Joe" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Joe" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Joe" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Boe" +} +===DONE=== diff --git a/ext/simplexml/tests/016.phpt b/ext/simplexml/tests/016.phpt new file mode 100644 index 0000000..ab80a7a --- /dev/null +++ b/ext/simplexml/tests/016.phpt @@ -0,0 +1,57 @@ +--TEST-- +SimpleXML: modifying attributes of singular subnode +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"></person> +</people> +EOF; + +$people = simplexml_load_string($xml); +var_dump($people->person['name']); +$people->person['name'] = $people->person['name'] . 'Foo'; +var_dump($people->person['name']); +$people->person['name'] .= 'Bar'; +var_dump($people->person['name']); + +echo "---[0]---\n"; + +$people = simplexml_load_string($xml); +var_dump($people->person[0]['name']); +$people->person[0]['name'] = $people->person[0]['name'] . 'Foo'; +var_dump($people->person[0]['name']); +$people->person[0]['name'] .= 'Bar'; +var_dump($people->person[0]['name']); + +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Joe" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(6) "JoeFoo" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(9) "JoeFooBar" +} +---[0]--- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Joe" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(6) "JoeFoo" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(9) "JoeFooBar" +} +===DONE=== diff --git a/ext/simplexml/tests/016a.phpt b/ext/simplexml/tests/016a.phpt new file mode 100644 index 0000000..9797e29 --- /dev/null +++ b/ext/simplexml/tests/016a.phpt @@ -0,0 +1,29 @@ +--TEST-- +SimpleXML: concatenating attributes +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Foo"></person> +</people> +EOF; + +$people = simplexml_load_string($xml); +var_dump($people->person['name']); +$people->person['name'] .= 'Bar'; +var_dump($people->person['name']); + +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(3) "Foo" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(6) "FooBar" +} +===DONE=== diff --git a/ext/simplexml/tests/017.phpt b/ext/simplexml/tests/017.phpt new file mode 100644 index 0000000..776b00c --- /dev/null +++ b/ext/simplexml/tests/017.phpt @@ -0,0 +1,86 @@ +--TEST-- +SimpleXML: iteration through subnodes +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"> + <child name="Ann" /> + <child name="Marray" /> + </person> + <person name="Boe"> + <child name="Joe" /> + <child name="Ann" /> + </person> +</people> +EOF; +$xml1 =<<<EOF +<people> + <person name="Joe"> + <child name="Ann" /> + </person> +</people> +EOF; + +function print_xml($xml) { + foreach($xml->children() as $person) { + echo "person: ".$person['name']."\n"; + foreach($person->children() as $child) { + echo " child: ".$child['name']."\n"; + } + } +} + +function print_xml2($xml) { + $persons = 2; + for ($i=0;$i<$persons;$i++) { + echo "person: ".$xml->person[$i]['name']."\n"; + $children = 2; + for ($j=0;$j<$children;$j++) { + echo " child: ".$xml->person[$i]->child[$j]['name']."\n"; + } + } +} + +echo "---11---\n"; +print_xml(simplexml_load_string($xml)); +echo "---12---\n"; +print_xml(simplexml_load_string($xml1)); +echo "---21---\n"; +print_xml2(simplexml_load_string($xml)); +echo "---22---\n"; +print_xml2(simplexml_load_string($xml1)); +?> +===DONE=== +--EXPECTF-- +---11--- +person: Joe + child: Ann + child: Marray +person: Boe + child: Joe + child: Ann +---12--- +person: Joe + child: Ann +---21--- +person: Joe + child: Ann + child: Marray +person: Boe + child: Joe + child: Ann +---22--- +person: Joe + child: Ann + child: +person: + +Notice: Trying to get property of non-object in %s017.php on line %d + child: + +Notice: Trying to get property of non-object in %s017.php on line %d + child: +===DONE=== diff --git a/ext/simplexml/tests/018.phpt b/ext/simplexml/tests/018.phpt new file mode 100644 index 0000000..e5c8109 --- /dev/null +++ b/ext/simplexml/tests/018.phpt @@ -0,0 +1,65 @@ +--TEST-- +SimpleXML: iteration through subnodes and attributes +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"> + Text1 + <child name="Ann" /> + Text2 + <child name="Marray" /> + Text3 + </person> + <person name="Boe"> + <child name="Joe" /> + <child name="Ann" /> + </person> +</people> +EOF; +$xml1 =<<<EOF +<people> + <person name="Joe"> + <child /> + </person> +</people> +EOF; + +function traverse_xml($pad,$xml) { + foreach($xml->children() as $name => $node) { + echo $pad."<$name"; + foreach($node->attributes() as $attr => $value) { + echo " $attr=\"$value\""; + } + echo ">\n"; + traverse_xml($pad." ",$node); + echo $pad."</$name>\n"; + } +} + +traverse_xml("",simplexml_load_string($xml)); +echo "----------\n"; +traverse_xml("",simplexml_load_string($xml1)); +echo "---Done---\n"; +?> +--EXPECT-- +<person name="Joe"> + <child name="Ann"> + </child> + <child name="Marray"> + </child> +</person> +<person name="Boe"> + <child name="Joe"> + </child> + <child name="Ann"> + </child> +</person> +---------- +<person name="Joe"> + <child> + </child> +</person> +---Done---
\ No newline at end of file diff --git a/ext/simplexml/tests/019.phpt b/ext/simplexml/tests/019.phpt new file mode 100644 index 0000000..aec74ba --- /dev/null +++ b/ext/simplexml/tests/019.phpt @@ -0,0 +1,80 @@ +--TEST-- +SimpleXML: foreach with children() +--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. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + <elem111> + Foo Bar + </elem111> + </elem11> +</sxe> +EOF +); + +foreach($sxe->children() as $name => $data) { + var_dump($name); + var_dump(trim($data)); +} + +echo "===CLONE===\n"; + +foreach(clone $sxe->children() as $name => $data) { + var_dump($name); + var_dump(trim($data)); +} + +echo "===ELEMENT===\n"; + +foreach($sxe->elem11->children() as $name => $data) { + var_dump($name); + var_dump(trim($data)); +} + +echo "===COMMENT===\n"; + +foreach($sxe->elem1->children() as $name => $data) { + var_dump($name); + var_dump(trim($data)); +} + +?> +===DONE=== +--EXPECT-- +string(5) "elem1" +string(10) "Bla bla 1." +string(6) "elem11" +string(10) "Bla bla 2." +===CLONE=== +string(5) "elem1" +string(10) "Bla bla 1." +string(6) "elem11" +string(10) "Bla bla 2." +===ELEMENT=== +string(7) "elem111" +string(7) "Foo Bar" +===COMMENT=== +string(5) "elem2" +string(28) "Here we have some text data." +===DONE=== diff --git a/ext/simplexml/tests/020.phpt b/ext/simplexml/tests/020.phpt new file mode 100644 index 0000000..9e91b5a --- /dev/null +++ b/ext/simplexml/tests/020.phpt @@ -0,0 +1,21 @@ +--TEST-- +SimpleXML: Attribute compared to string +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$doc = simplexml_load_string('<root><name attr="foo">bar</name></root>'); +print $doc->name["attr"]; +print "\n"; +if ($doc->name["attr"] == "foo") { + print "Works\n"; +} else { + print "Error\n"; +} +?> +===DONE=== +--EXPECT-- +foo +Works +===DONE=== diff --git a/ext/simplexml/tests/021.phpt b/ext/simplexml/tests/021.phpt new file mode 100644 index 0000000..d513868 --- /dev/null +++ b/ext/simplexml/tests/021.phpt @@ -0,0 +1,25 @@ +--TEST-- +SimpleXML: Element check +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$ok = 1; +$doc = simplexml_load_string('<root><exists>foo</exists></root>'); +if(!isset($doc->exists)) { + $ok *= 0; +} +if(isset($doc->doesnotexist)) { + $ok *= 0; +} +if ($ok) { + print "Works\n"; +} else { + print "Error\n"; +} +?> +===DONE=== +--EXPECT-- +Works +===DONE=== diff --git a/ext/simplexml/tests/022.phpt b/ext/simplexml/tests/022.phpt new file mode 100644 index 0000000..2af4a1d --- /dev/null +++ b/ext/simplexml/tests/022.phpt @@ -0,0 +1,62 @@ +--TEST-- +SimpleXML: Attributes inside foreach +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<pres><content><file glob="slide_*.xml"/></content></pres> +EOF; + +$sxe = simplexml_load_string($xml); + +echo "===CONTENT===\n"; +var_dump($sxe->content); + +echo "===FILE===\n"; +var_dump($sxe->content->file); + +echo "===FOREACH===\n"; +foreach($sxe->content->file as $file) +{ + var_dump($file); + var_dump($file['glob']); +} + +?> +===DONE=== +--EXPECTF-- +===CONTENT=== +object(SimpleXMLElement)#%d (1) { + ["file"]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["glob"]=> + string(11) "slide_*.xml" + } + } +} +===FILE=== +object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["glob"]=> + string(11) "slide_*.xml" + } +} +===FOREACH=== +object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["glob"]=> + string(11) "slide_*.xml" + } +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(11) "slide_*.xml" +} +===DONE=== diff --git a/ext/simplexml/tests/023.phpt b/ext/simplexml/tests/023.phpt new file mode 100644 index 0000000..515a146 --- /dev/null +++ b/ext/simplexml/tests/023.phpt @@ -0,0 +1,36 @@ +--TEST-- +SimpleXML: Attributes with entities +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE talks SYSTEM "nbsp.dtd" [ +<!ELEMENT root EMPTY> +<!ATTLIST root attr1 CDATA #IMPLIED> +<!ENTITY nbsp "&#x00A0;"> +]> +<root attr='foo bar baz'></root> +EOF; + +$sxe = simplexml_load_string($xml); + +var_dump($sxe); +var_dump($sxe['attr']); +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr"]=> + string(%d) "foo%sbar%sbaz" + } +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(%d) "foo%sbar%sbaz" +} +===DONE=== diff --git a/ext/simplexml/tests/024.phpt b/ext/simplexml/tests/024.phpt new file mode 100644 index 0000000..9f31fd5 --- /dev/null +++ b/ext/simplexml/tests/024.phpt @@ -0,0 +1,175 @@ +--TEST-- +SimpleXML: XPath and attributes +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<root> +<elem attr1='11' attr2='12' attr3='13'/> +<elem attr1='21' attr2='22' attr3='23'/> +<elem attr1='31' attr2='32' attr3='33'/> +</root> +EOF; + +$sxe = simplexml_load_string($xml); + +function test($xpath) +{ + global $sxe; + + echo "===$xpath===\n"; + var_dump($sxe->xpath($xpath)); +} + +test('elem/@attr2'); +test('//@attr2'); +test('//@*'); +test('elem[2]/@attr2'); + +?> +===DONE=== +--EXPECTF-- +===elem/@attr2=== +array(3) { + [0]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "12" + } + } + [1]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "22" + } + } + [2]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "32" + } + } +} +===//@attr2=== +array(3) { + [0]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "12" + } + } + [1]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "22" + } + } + [2]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "32" + } + } +} +===//@*=== +array(9) { + [0]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(2) "11" + } + } + [1]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "12" + } + } + [2]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr3"]=> + string(2) "13" + } + } + [3]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(2) "21" + } + } + [4]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "22" + } + } + [5]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr3"]=> + string(2) "23" + } + } + [6]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(2) "31" + } + } + [7]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "32" + } + } + [8]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr3"]=> + string(2) "33" + } + } +} +===elem[2]/@attr2=== +array(1) { + [0]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["attr2"]=> + string(2) "22" + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/025.phpt b/ext/simplexml/tests/025.phpt new file mode 100644 index 0000000..b9e3bbb --- /dev/null +++ b/ext/simplexml/tests/025.phpt @@ -0,0 +1,92 @@ +--TEST-- +SimpleXML: getting namespaces +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<xhtml:html xmlns:html='http://www.w3.org/1999/xhtml' xmlns:xhtml='http://www.w3.org/TR/REC-html40'> +<xhtml:head><xhtml:title xmlns:xhtml='http://www.w3.org/TR/REC-html401'>bla</xhtml:title></xhtml:head> +<xhtml:body html:title="b"> +<html:h1>bla</html:h1> +<foo:bar xmlns:foo='foobar' xmlns:baz='foobarbaz'/> +</xhtml:body> +</xhtml:html> +EOF; + +$sxe = simplexml_load_string($xml); + +var_dump($sxe->getNamespaces()); +var_dump($sxe->getNamespaces(true)); +var_dump($sxe->getDocNamespaces()); +var_dump($sxe->getDocNamespaces(true)); + +$xml =<<<EOF +<?xml version='1.0'?> +<html xmlns='http://www.w3.org/1999/xhtml'> +<head><title xmlns='http://www.w3.org/TR/REC-html40'>bla</title></head> +</html> +EOF; + +$sxe = simplexml_load_string($xml); + +var_dump($sxe->getNamespaces()); +var_dump($sxe->getDocNamespaces()); + +$xml =<<<EOF +<?xml version='1.0'?> +<root/> +EOF; + +$sxe = simplexml_load_string($xml); + +var_dump($sxe->getNamespaces()); +var_dump($sxe->getDocNamespaces()); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +array(1) { + ["xhtml"]=> + string(31) "http://www.w3.org/TR/REC-html40" +} +array(3) { + ["xhtml"]=> + string(31) "http://www.w3.org/TR/REC-html40" + ["html"]=> + string(28) "http://www.w3.org/1999/xhtml" + ["foo"]=> + string(6) "foobar" +} +array(2) { + ["html"]=> + string(28) "http://www.w3.org/1999/xhtml" + ["xhtml"]=> + string(31) "http://www.w3.org/TR/REC-html40" +} +array(4) { + ["html"]=> + string(28) "http://www.w3.org/1999/xhtml" + ["xhtml"]=> + string(31) "http://www.w3.org/TR/REC-html40" + ["foo"]=> + string(6) "foobar" + ["baz"]=> + string(9) "foobarbaz" +} +array(1) { + [""]=> + string(28) "http://www.w3.org/1999/xhtml" +} +array(1) { + [""]=> + string(28) "http://www.w3.org/1999/xhtml" +} +array(0) { +} +array(0) { +} +===DONE=== diff --git a/ext/simplexml/tests/026.phpt b/ext/simplexml/tests/026.phpt new file mode 100644 index 0000000..d6de94b --- /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 100644 index 0000000..a531cca --- /dev/null +++ b/ext/simplexml/tests/027.phpt @@ -0,0 +1,83 @@ +--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'; +traverse_xml($people); +?> +===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> +<people> + <person gender="female">Jane + </person> + <person gender="male">Joe + </person> + <person gender="male">Minni-me + </person> + <person gender="error"> + </person> +</people> +===DONE=== diff --git a/ext/simplexml/tests/028.phpt b/ext/simplexml/tests/028.phpt new file mode 100644 index 0000000..753056b --- /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 100644 index 0000000..86a4f30 --- /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 0000000..774a5f1 --- /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 0000000..cd2d266 --- /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 100644 index 0000000..48bc887 --- /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(false) +bool(false) +bool(false) +===DONE=== diff --git a/ext/simplexml/tests/033.phpt b/ext/simplexml/tests/033.phpt new file mode 100644 index 0000000..ba01b21 --- /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/034.phpt b/ext/simplexml/tests/034.phpt new file mode 100644 index 0000000..8610f70 --- /dev/null +++ b/ext/simplexml/tests/034.phpt @@ -0,0 +1,24 @@ +--TEST-- +SimpleXML: cast to array +--FAIL-- +Length of cast array does not match expected length +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$string = '<?xml version="1.0"?> +<foo><bar> + <p>Blah 1</p> + <p>Blah 2</p> + <p>Blah 3</p> + <tt>Blah 4</tt> +</bar></foo> +'; +$foo = simplexml_load_string($string); +$p = $foo->bar->p; +echo count($p); +$p = (array)$foo->bar->p; +echo count($p); +?> +--EXPECTF-- +33 diff --git a/ext/simplexml/tests/035.phpt b/ext/simplexml/tests/035.phpt new file mode 100644 index 0000000..2162c86 --- /dev/null +++ b/ext/simplexml/tests/035.phpt @@ -0,0 +1,26 @@ +--TEST-- +SimpleXML: __toString +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$string = '<?xml version="1.0"?> +<foo><bar> + <p>Blah 1</p> + <p>Blah 2</p> + <p>Blah 3</p> + <tt>Blah 4</tt> +</bar></foo> +'; +$foo = simplexml_load_string($string); +$p = $foo->bar->p; +echo $p."\n"; +echo $p->__toString()."\n"; +echo $p."\n"; +?> +==Done== +--EXPECT-- +Blah 1 +Blah 1 +Blah 1 +==Done== diff --git a/ext/simplexml/tests/036.phpt b/ext/simplexml/tests/036.phpt new file mode 100644 index 0000000..24bfe60 --- /dev/null +++ b/ext/simplexml/tests/036.phpt @@ -0,0 +1,22 @@ +--TEST-- +SimpleXML: overriden count() method +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +class SXE extends SimpleXmlElement { + public function count() { + echo "Called Count!\n"; + return parent::count(); + } +} + +$str = '<xml><c>asdf</c><c>ghjk</c></xml>'; +$sxe = new SXE($str); +var_dump(count($sxe)); +?> +==Done== +--EXPECT-- +Called Count! +int(2) +==Done== diff --git a/ext/simplexml/tests/SimpleXMLElement_addAttribute_basic.phpt b/ext/simplexml/tests/SimpleXMLElement_addAttribute_basic.phpt new file mode 100644 index 0000000..15c81b2 --- /dev/null +++ b/ext/simplexml/tests/SimpleXMLElement_addAttribute_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +SimpleXMLElement->addAttribute() +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) die("skip"); ?> +--FILE-- +<?php + $simple = simplexml_load_file(dirname(__FILE__)."/book.xml"); + $simple->addAttribute('type','novels'); + + var_dump($simple->attributes()); + echo "Done"; +?> +--EXPECTF-- +object(SimpleXMLElement)#2 (1) { + ["@attributes"]=> + array(1) { + ["type"]=> + string(6) "novels" + } +} +Done
\ No newline at end of file diff --git a/ext/simplexml/tests/SimpleXMLElement_addAttribute_required_attribute_name.phpt b/ext/simplexml/tests/SimpleXMLElement_addAttribute_required_attribute_name.phpt new file mode 100644 index 0000000..22ea448 --- /dev/null +++ b/ext/simplexml/tests/SimpleXMLElement_addAttribute_required_attribute_name.phpt @@ -0,0 +1,18 @@ +--TEST-- +SimpleXMLElement: Test to ensure that the required attribute name correctly is giving a warning +--CREDITS-- +Havard Eide <nucleuz@gmail.com> +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) { echo "skip extension not available"; } ?> +--FILE-- +<?php +$a = new SimpleXMLElement("<php>testfest</php>"); +$a->addAttribute( "", "" ); +echo $a->asXML(); +?> +--EXPECTF-- +Warning: SimpleXMLElement::addAttribute(): Attribute name is required in %s on line %d +<?xml version="1.0"?> +<php>testfest</php> + diff --git a/ext/simplexml/tests/book.xml b/ext/simplexml/tests/book.xml new file mode 100644 index 0000000..ea40508 --- /dev/null +++ b/ext/simplexml/tests/book.xml @@ -0,0 +1,10 @@ +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> diff --git a/ext/simplexml/tests/bug24392.phpt b/ext/simplexml/tests/bug24392.phpt new file mode 100644 index 0000000..0a462e5 --- /dev/null +++ b/ext/simplexml/tests/bug24392.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #24392 (empty namespaces causing confusion) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?> +--FILE-- +<?php +$s = simplexml_load_file(dirname(__FILE__).'/bug24392.xml'); +foreach ($s->item as $item) { + echo $item->title . "\n"; +} +?> +--EXPECT-- +EU Parliament to Vote on New Patent Rules +Most Powerful Amateur Rocket in Canada +GF FX 5900 Ultra vs. ATi Radeon 9800 Pro +PHP 5 Beta 1 +Engaging with the OSS Community +Pure Math, Pure Joy +Windows Tech Writer Looks at Linux +US Cell Phone Users Discover SMS Spam +Verizon Sues Nextel For Espionage +Introduction to Debian diff --git a/ext/simplexml/tests/bug24392.xml b/ext/simplexml/tests/bug24392.xml new file mode 100644 index 0000000..d669f1d --- /dev/null +++ b/ext/simplexml/tests/bug24392.xml @@ -0,0 +1,76 @@ +<?xml version="1.0"?> + +<rdf:RDF +xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" +xmlns="http://my.netscape.com/rdf/simple/0.9/"> + +<channel> +<title>Slashdot</title> +<link>http://slashdot.org/</link> +<description>News for nerds, stuff that matters</description> +</channel> + +<image> +<title>Slashdot</title> +<url>http://images.slashdot.org/topics/topicslashdot.gif</url> +<link>http://slashdot.org/</link> +</image> + +<item> +<title>EU Parliament to Vote on New Patent Rules</title> +<link>http://slashdot.org/article.pl?sid=03/06/30/002211</link> +</item> + +<item> +<title>Most Powerful Amateur Rocket in Canada</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/2121211</link> +</item> + +<item> +<title>GF FX 5900 Ultra vs. ATi Radeon 9800 Pro</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/202218</link> +</item> + +<item> +<title>PHP 5 Beta 1</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/1957253</link> +</item> + +<item> +<title>Engaging with the OSS Community</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/1913235</link> +</item> + +<item> +<title>Pure Math, Pure Joy</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/183258</link> +</item> + +<item> +<title>Windows Tech Writer Looks at Linux</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/1554201</link> +</item> + +<item> +<title>US Cell Phone Users Discover SMS Spam</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/1542249</link> +</item> + +<item> +<title>Verizon Sues Nextel For Espionage</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/1443230</link> +</item> + +<item> +<title>Introduction to Debian</title> +<link>http://slashdot.org/article.pl?sid=03/06/29/1424213</link> +</item> + +<textinput> +<title>Search Slashdot</title> +<description>Search Slashdot stories</description> +<name>query</name> +<link>http://slashdot.org/search.pl</link> +</textinput> + +</rdf:RDF>
\ No newline at end of file diff --git a/ext/simplexml/tests/bug25756.xsd b/ext/simplexml/tests/bug25756.xsd new file mode 100644 index 0000000..427b7a1 --- /dev/null +++ b/ext/simplexml/tests/bug25756.xsd @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <xsd:element name="foo" type="foo-type" /> + <xsd:complexType name="item-type"> + <xsd:all> + <xsd:element name="product-name" type="xsd:string" + minOccurs="1" maxOccurs="1"/> + <xsd:element name="quantity" type="xsd:decimal" + minOccurs="1" maxOccurs="1"/> + </xsd:all> + </xsd:complexType> + <xsd:complexType name="foo-type"> + <xsd:sequence> + <xsd:element name="items" minoccurs="1" maxOccurs="1"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="item" type="item-type" + minOccurs="0" maxOccurs="unbounded" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + </xsd:complexType> +</xsd:schema> diff --git a/ext/simplexml/tests/bug25756_1.xml b/ext/simplexml/tests/bug25756_1.xml new file mode 100644 index 0000000..33ab30b --- /dev/null +++ b/ext/simplexml/tests/bug25756_1.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<foo> + <items> + <item> + <product-name>abc</product-name> + <quantity>123</quantity> + </item> + <item> + <product-name>def</product-name> + <quantity>456</quantity> + </item> + </items> +</foo> diff --git a/ext/simplexml/tests/bug25756_2.xml b/ext/simplexml/tests/bug25756_2.xml new file mode 100644 index 0000000..53037ef --- /dev/null +++ b/ext/simplexml/tests/bug25756_2.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<foo> + <items> + <item> + <product-name>abc</product-name> + <quantity>abc</quantity> + </item> + <item> + <product-name>abc</product-name> + <quantity>123</quantity> + </item> + </items> +</foo> diff --git a/ext/simplexml/tests/bug26976.phpt b/ext/simplexml/tests/bug26976.phpt new file mode 100644 index 0000000..657c229 --- /dev/null +++ b/ext/simplexml/tests/bug26976.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #26976 (Can not access array elements using array indices) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?> +--FILE-- +<?php + +$root = simplexml_load_string( +'<?xml version="1.0"?> +<root> + <child>a</child> + <child>b</child> + <child>c</child> + <child>d</child> +</root> +'); + +echo $root->child[0], "\n"; +echo $root->child[1], "\n"; +echo $root->child[2], "\n"; +echo $root->child[3], "\n"; + +?> +--EXPECT-- +a +b +c +d diff --git a/ext/simplexml/tests/bug27010.phpt b/ext/simplexml/tests/bug27010.phpt new file mode 100644 index 0000000..364ca46 --- /dev/null +++ b/ext/simplexml/tests/bug27010.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #27010 (segfault and node text not displayed when returned from children()) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml=<<<EOF +<drinks xmlns:hot="http://www.example.com/hot"> + <hot:drink><hot:name>Coffee</hot:name></hot:drink> + <hot:drink><hot:name>Tea</hot:name></hot:drink> + <drink><name>Cola</name></drink> + <drink><name>Juice</name></drink> +</drinks> +EOF; + +$sxe = simplexml_load_string($xml); + +foreach ($sxe as $element_name => $element) { + print "$element_name is $element->name\n"; +} + +foreach ($sxe->children('http://www.example.com/hot') as $element_name => $element) { + print "$element_name is $element->name\n"; +} + +?> +===DONE=== +--EXPECT-- +drink is Cola +drink is Juice +drink is Coffee +drink is Tea +===DONE=== diff --git a/ext/simplexml/tests/bug35785.phpt b/ext/simplexml/tests/bug35785.phpt new file mode 100644 index 0000000..0e03f07 --- /dev/null +++ b/ext/simplexml/tests/bug35785.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #35785 (SimpleXML memory read error) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml = simplexml_load_string("<root></root>"); +$xml->bla->posts->name = "FooBar"; +echo $xml->asXML(); +$xml = simplexml_load_string("<root></root>"); +$count = count($xml->bla->posts); +var_dump($count); +$xml->bla->posts[$count]->name = "FooBar"; +echo $xml->asXML(); +$xml = simplexml_load_string("<root></root>"); +$xml->bla->posts[]->name = "FooBar"; +echo $xml->asXML(); +?> +===DONE=== +<?php exit(0); __halt_compiler(); ?> +--EXPECTF-- +<?xml version="1.0"?> +<root><bla><posts><name>FooBar</name></posts></bla></root> +int(0) +<?xml version="1.0"?> +<root><bla><posts><name>FooBar</name></posts></bla></root> +<?xml version="1.0"?> +<root><bla><posts><name>FooBar</name></posts></bla></root> +===DONE=== diff --git a/ext/simplexml/tests/bug36611.phpt b/ext/simplexml/tests/bug36611.phpt new file mode 100644 index 0000000..fdcfd47 --- /dev/null +++ b/ext/simplexml/tests/bug36611.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #36611 (assignment to SimpleXML object attribute changes argument type to string) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--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); +$zml->pos["act_idx"] = $val; +var_dump($val) ; + +?> +===DONE=== +--EXPECT-- +int(1) +int(1) +===DONE=== diff --git a/ext/simplexml/tests/bug37076.phpt b/ext/simplexml/tests/bug37076.phpt new file mode 100644 index 0000000..c7f19b3 --- /dev/null +++ b/ext/simplexml/tests/bug37076.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #37076 (SimpleXML ignores .=) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml = simplexml_load_string("<root><foo /></root>"); +$xml->foo = "foo"; +$xml->foo .= "bar"; +print $xml->asXML(); +?> +===DONE=== +--EXPECT-- +<?xml version="1.0"?> +<root><foo>foobar</foo></root> +===DONE=== diff --git a/ext/simplexml/tests/bug37076_1.phpt b/ext/simplexml/tests/bug37076_1.phpt new file mode 100644 index 0000000..d4f4e03 --- /dev/null +++ b/ext/simplexml/tests/bug37076_1.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #37076 (SimpleXML ignores .=) (appending to unnamed attribute) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml = simplexml_load_string("<root><foo /></root>"); +$xml->{""} .= "bar"; +print $xml->asXML(); +?> +===DONE=== +--EXPECTF-- +Warning: main(): Cannot write or create unnamed element in %s on line %d + +Warning: main(): Cannot write or create unnamed element in %s on line %d +<?xml version="1.0"?> +<root><foo/></root> +===DONE=== diff --git a/ext/simplexml/tests/bug37386.phpt b/ext/simplexml/tests/bug37386.phpt new file mode 100644 index 0000000..cf86906 --- /dev/null +++ b/ext/simplexml/tests/bug37386.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #39760 (autocreating element doesn't assign value to first node) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?> +--FILE-- +<?php + +$sx1 = new SimpleXMLElement((binary)"<root />"); + +$sx1->node[0] = 'node1'; +$sx1->node[1] = 'node2'; + +print $sx1->asXML()."\n"; +$node = $sx1->node[0]; +$node[0] = 'New Value'; + +print $sx1->asXML(); + +?> +--EXPECTF-- +<?xml version="1.0"?> +<root><node>node1</node><node>node2</node></root> + +<?xml version="1.0"?> +<root><node>New Value</node><node>node2</node></root> diff --git a/ext/simplexml/tests/bug37565.phpt b/ext/simplexml/tests/bug37565.phpt new file mode 100644 index 0000000..c1e5104 --- /dev/null +++ b/ext/simplexml/tests/bug37565.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #37565 (Using reflection::export with simplexml causing a crash) +--SKIPIF-- +<?php if (!extension_loaded("simplexml") || !extension_loaded('reflection')) print "skip"; ?> +--FILE-- +<?php + +function my_error_handler($errno, $errstr, $errfile, $errline) { + echo "Error: $errstr\n"; +} + +set_error_handler('my_error_handler'); + +class Setting extends ReflectionObject +{ +} + +Reflection::export(simplexml_load_string('<test/>', 'Setting')); + +Reflection::export(simplexml_load_file('data:,<test/>', 'Setting')); + +?> +===DONE=== +--EXPECTF-- +Error: simplexml_load_string() expects parameter 2 to be a class name derived from SimpleXMLElement, 'Setting' given +Error: Argument 1 passed to Reflection::export() must implement interface Reflector, null given +Error: Reflection::export() expects parameter 1 to be Reflector, null given +Error: simplexml_load_file() expects parameter 2 to be a class name derived from SimpleXMLElement, 'Setting' given +Error: Argument 1 passed to Reflection::export() must implement interface Reflector, null given +Error: Reflection::export() expects parameter 1 to be Reflector, null given +===DONE=== diff --git a/ext/simplexml/tests/bug38347.phpt b/ext/simplexml/tests/bug38347.phpt new file mode 100644 index 0000000..0ea7b5d --- /dev/null +++ b/ext/simplexml/tests/bug38347.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #38347 (Segmentation fault when using foreach with an unknown/empty SimpleXMLElement) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +function iterate($xml) +{ + print_r($xml); + foreach ($xml->item as $item) { + echo "This code will crash!"; + } +} + +$xmlstr = "<xml><item>Item 1</item><item>Item 2</item></xml>"; +$xml = simplexml_load_string($xmlstr); +iterate($xml->unknown); + +echo "Done\n"; +?> +--EXPECTF-- +SimpleXMLElement Object +( +) + +Warning: Invalid argument supplied for foreach() in %sbug38347.php on line 6 +Done diff --git a/ext/simplexml/tests/bug38354.phpt b/ext/simplexml/tests/bug38354.phpt new file mode 100644 index 0000000..d2fcde1 --- /dev/null +++ b/ext/simplexml/tests/bug38354.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #38354 (Unwanted reformatting of XML when using AsXML) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml = simplexml_load_string( +'<code> + <a href="javascript:alert(\'1\');"><strong>Item Two</strong></a> +</code>' +); + +foreach ($xml->xpath("//*") as $element) { + var_dump($element->asXML()); +} + +echo "Done\n"; +?> +--EXPECTF-- +string(101) "<?xml version="1.0"?> +<code> + <a href="javascript:alert('1');"><strong>Item Two</strong></a> +</code> +" +string(62) "<a href="javascript:alert('1');"><strong>Item Two</strong></a>" +string(25) "<strong>Item Two</strong>" +Done diff --git a/ext/simplexml/tests/bug38406.phpt b/ext/simplexml/tests/bug38406.phpt new file mode 100644 index 0000000..f439e33 --- /dev/null +++ b/ext/simplexml/tests/bug38406.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #38406 (crash when assigning objects to SimpleXML attributes) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$item = new SimpleXMLElement(b'<something />'); +$item->attribute = b'something'; +var_dump($item->attribute); + +$item->otherAttribute = $item->attribute; +var_dump($item->otherAttribute); + +$a = array(); +$item->$a = new stdclass; + +echo "Done\n"; +?> +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(9) "something" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(9) "something" +} + +Notice: Array to string conversion in %s on line %d + +Warning: It is not yet possible to assign complex types to properties in %s on line %d +Done diff --git a/ext/simplexml/tests/bug38424.phpt b/ext/simplexml/tests/bug38424.phpt new file mode 100644 index 0000000..baab45f --- /dev/null +++ b/ext/simplexml/tests/bug38424.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #38424 (Different attribute assignment if new or exists) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml = simplexml_load_string('<xml></xml>'); + +$str = "abc & def" ; + +$xml["a1"] = "" ; +$xml["a1"] = htmlspecialchars($str,ENT_NOQUOTES) ; + +$xml["a2"] = htmlspecialchars($str,ENT_NOQUOTES) ; + +$xml["a3"] = "" ; +$xml["a3"] = $str ; + +$xml["a4"] = $str ; + +echo $xml->asXML(); +?> +--EXPECT-- +<?xml version="1.0"?> +<xml a1="abc &amp; def" a2="abc &amp; def" a3="abc & def" a4="abc & def"/> diff --git a/ext/simplexml/tests/bug39662.phpt b/ext/simplexml/tests/bug39662.phpt new file mode 100644 index 0000000..ae15f2e --- /dev/null +++ b/ext/simplexml/tests/bug39662.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #39662 (Segfault when calling asXML() of a cloned SimpleXMLElement) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?> +--FILE-- +<?php + +$xml = '<?xml version="1.0" encoding="utf-8" ?> +<test> + +</test>'; + +$root = simplexml_load_string($xml); +$clone = clone $root; +var_dump($root); +var_dump($clone); +var_dump($clone->asXML()); + +echo "Done\n"; +?> +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) " + +" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) " + +" +} +string(15) "<test> + +</test>" +Done diff --git a/ext/simplexml/tests/bug39760.phpt b/ext/simplexml/tests/bug39760.phpt new file mode 100644 index 0000000..e781765 --- /dev/null +++ b/ext/simplexml/tests/bug39760.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #39760 (cloning fails on nested SimpleXML-Object) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?> +--FILE-- +<?php + +$xml = '<?xml version="1.0" ?> +<test> + <level1> + <level2a>text1</level2a> + <level2b>text2</level2b> + </level1> +</test>'; +$test = simplexml_load_string($xml); + +var_dump($test->level1->level2a); + +$test2 = clone $test; +var_dump($test2->level1->level2a); + +$test3 = clone $test->level1->level2a; +var_dump($test3); + +echo "Done\n"; +?> +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "text1" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "text1" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "text1" +} +Done diff --git a/ext/simplexml/tests/bug40451.phpt b/ext/simplexml/tests/bug40451.phpt new file mode 100644 index 0000000..afd78c7 --- /dev/null +++ b/ext/simplexml/tests/bug40451.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #40451 (addAttribute() may crash when used with non-existent child node) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$string = <<<XML +<?xml version="1.0"?> + <Host enable="true"> + <Name>host.server.com</Name> + </Host> +XML; + +$xml = simplexml_load_string($string); + +$add = $xml->addChild('Host'); +$add->Host->addAttribute('enable', 'true'); + +?> +===DONE=== +--EXPECTF-- +Warning: SimpleXMLElement::addAttribute(): Unable to locate parent Element in %s on line %d +===DONE=== diff --git a/ext/simplexml/tests/bug41175.phpt b/ext/simplexml/tests/bug41175.phpt new file mode 100644 index 0000000..db03da9 --- /dev/null +++ b/ext/simplexml/tests/bug41175.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #41175 (addAttribute() fails to add an attribute with an empty value) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml = new SimpleXmlElement("<img></img>"); +$xml->addAttribute("src", "foo"); +$xml->addAttribute("alt", ""); +echo $xml->asXML(); + +?> +===DONE=== +--EXPECT-- +<?xml version="1.0"?> +<img src="foo" alt=""/> +===DONE===
\ No newline at end of file diff --git a/ext/simplexml/tests/bug41582.phpt b/ext/simplexml/tests/bug41582.phpt new file mode 100644 index 0000000..8733810 --- /dev/null +++ b/ext/simplexml/tests/bug41582.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #41582 (SimpleXML crashes when accessing newly created element) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml = new SimpleXMLElement('<?xml version="1.0" standalone="yes"?> +<collection></collection>'); + +$xml->movie[]->characters->character[0]->name = 'Miss Coder'; + +echo($xml->asXml()); + +?> +===DONE=== +--EXPECT-- +<?xml version="1.0" standalone="yes"?> +<collection><movie><characters><character><name>Miss Coder</name></character></characters></movie></collection> +===DONE=== diff --git a/ext/simplexml/tests/bug41861.phpt b/ext/simplexml/tests/bug41861.phpt new file mode 100644 index 0000000..607d301 --- /dev/null +++ b/ext/simplexml/tests/bug41861.phpt @@ -0,0 +1,42 @@ +--TEST-- +Bug #41861 (getNamespaces() returns the namespaces of a node's siblings) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml = simplexml_load_string('<root> + <first_node_no_ns /> + <ns1:node1 xmlns:ns1="#ns1" /> + <ns2:node2 xmlns:ns2="#ns2" /> + <ns3:node3 xmlns:ns3="#ns3" /> + <last_node_no_ns /> +</root>'); + +$name = $xml->getName(); +$namespaces = $xml->getNamespaces(True); +echo "root(recursive): '$name' -- namespaces: ", implode(', ', $namespaces), "\n"; +$namespaces = $xml->getNamespaces(False); +echo "root(non-recursive): '$name' -- namespaces: ", implode(', ', $namespaces), "\n"; + +foreach (array(null, '#ns1', '#ns2', '#ns3') as $ns) +{ + foreach ($xml->children($ns) as $child) + { + $name = $child->getName(); + $namespaces = $child->getNamespaces(false); + + echo "children($ns): '$name' -- namespaces: ", implode(', ', $namespaces), "\n"; + } +} +?> +===DONE=== +--EXPECT-- +root(recursive): 'root' -- namespaces: #ns1, #ns2, #ns3 +root(non-recursive): 'root' -- namespaces: +children(): 'first_node_no_ns' -- namespaces: +children(): 'last_node_no_ns' -- namespaces: +children(#ns1): 'node1' -- namespaces: #ns1 +children(#ns2): 'node2' -- namespaces: #ns2 +children(#ns3): 'node3' -- namespaces: #ns3 +===DONE=== diff --git a/ext/simplexml/tests/bug41867.phpt b/ext/simplexml/tests/bug41867.phpt new file mode 100644 index 0000000..33e2de9 --- /dev/null +++ b/ext/simplexml/tests/bug41867.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #41867 (getName is broken) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$a = simplexml_load_string("<a><b><c/></b></a>"); +echo $a->getName()."\n"; +echo $a->b->getName()."\n"; +echo $a->b->c->getName()."\n"; +?> +===DONE=== +--EXPECT-- +a +b +c +===DONE=== diff --git a/ext/simplexml/tests/bug41947.phpt b/ext/simplexml/tests/bug41947.phpt new file mode 100644 index 0000000..0b974ce --- /dev/null +++ b/ext/simplexml/tests/bug41947.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #41947 (addChild incorrectly registers empty strings as namespaces) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><root xmlns:myns="http://myns" />'); +$grandchild = $xml->addChild('child', null, 'http://myns')->addChild('grandchild', 'hello', ''); + +$gchild = $xml->xpath("//grandchild"); +if (count($gchild) > 0) { + echo $gchild[0]."\n"; +} +?> +===DONE=== +--EXPECT-- +hello +===DONE=== diff --git a/ext/simplexml/tests/bug42259.phpt b/ext/simplexml/tests/bug42259.phpt new file mode 100644 index 0000000..19c02a5 --- /dev/null +++ b/ext/simplexml/tests/bug42259.phpt @@ -0,0 +1,49 @@ +--TEST-- +Bug #42259 (SimpleXMLIterator loses ancestry) +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php +$xml =<<<EOF +<xml> + <fieldset1> + <field1/> + <field2/> + </fieldset1> + <fieldset2> + <options> + <option1/> + <option2/> + <option3/> + </options> + <field1/> + <field2/> + </fieldset2> +</xml> +EOF; + +$sxe = new SimpleXMLIterator($xml); +$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::LEAVES_ONLY); +foreach ($rit as $child) { + $path = ''; + $ancestry = $child->xpath('ancestor-or-self::*'); + foreach ($ancestry as $ancestor) { + $path .= $ancestor->getName() . '/'; + } + $path = substr($path, 0, strlen($path) - 1); + echo count($ancestry) . ' steps: ' . $path . PHP_EOL; +} +?> +===DONE=== +--EXPECT-- +3 steps: xml/fieldset1/field1 +3 steps: xml/fieldset1/field2 +4 steps: xml/fieldset2/options/option1 +4 steps: xml/fieldset2/options/option2 +4 steps: xml/fieldset2/options/option3 +3 steps: xml/fieldset2/field1 +3 steps: xml/fieldset2/field2 +===DONE=== diff --git a/ext/simplexml/tests/bug42369.phpt b/ext/simplexml/tests/bug42369.phpt new file mode 100644 index 0000000..e186770 --- /dev/null +++ b/ext/simplexml/tests/bug42369.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #42369 (Implicit conversion to string leaks memory) +--SKIPIF-- +<?php if (!extension_loaded('simplexml')) echo 'skip simplexml extension is not loaded'; ?> +--FILE-- +<?php + $xml = '<?xml version="1.0" encoding="utf-8"?>'; + $x = simplexml_load_string($xml . "<q><x>foo</x></q>"); + + echo 'explicit conversion' . PHP_EOL; + for ($i = 0; $i < 100000; $i++) { + md5(strval($x->x)); + } + + echo 'no conversion' . PHP_EOL; + for ($i = 0; $i < 100000; $i++) { + md5($x->x); + } + +?> +===DONE=== +--EXPECT-- +explicit conversion +no conversion +===DONE===
\ No newline at end of file diff --git a/ext/simplexml/tests/bug43221.phpt b/ext/simplexml/tests/bug43221.phpt new file mode 100644 index 0000000..53b6efd --- /dev/null +++ b/ext/simplexml/tests/bug43221.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #43221 (SimpleXML adding default namespace in addAttribute) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><root />'); +$n = $xml->addChild("node", "value"); +$n->addAttribute("a", "b"); +$n->addAttribute("c", "d", "http://bar.com"); +$n->addAttribute("foo:e", "f", "http://bar.com"); +print_r($xml->asXml()); +?> +===DONE=== +--EXPECTF-- +Warning: SimpleXMLElement::addAttribute(): Attribute requires prefix for namespace in %sbug43221.php on line %d +<?xml version="1.0" encoding="utf-8"?> +<root><node xmlns:foo="http://bar.com" a="b" foo:e="f">value</node></root> +===DONE=== +
\ No newline at end of file diff --git a/ext/simplexml/tests/bug44478.phpt b/ext/simplexml/tests/bug44478.phpt new file mode 100644 index 0000000..17a26f9 --- /dev/null +++ b/ext/simplexml/tests/bug44478.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #44478 (Inconsistent behaviour when assigning new nodes) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml_element = new simpleXMLElement('<root></root>'); +$xml_element->node1 = 'a & b'; +print $xml_element->node1."\n"; +$xml_element->node1 = 'a & b'; +print $xml_element->node1."\n"; +$xml_element->addChild('node2','a & b'); +print $xml_element->node2."\n"; +$xml_element->node2 = 'a & b'; +print $xml_element->node2."\n"; + +print $xml_element->asXML(); + +?> +===DONE=== +--EXPECTF-- +a & b +a & b +a & b +a & b +<?xml version="1.0"?> +<root><node1>a &#38; b</node1><node2>a & b</node2></root> +===DONE=== +
\ No newline at end of file diff --git a/ext/simplexml/tests/bug45553.phpt b/ext/simplexml/tests/bug45553.phpt new file mode 100644 index 0000000..b355c48 --- /dev/null +++ b/ext/simplexml/tests/bug45553.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #45553 (Using XPath to return values for attributes with a namespace does not work) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<XML +<xml xmlns:a="http://a"> + <data a:label="I am A" label="I am Nothing">test1</data> + <a:data a:label="I am a:A" label="I am a:Nothing">test2</a:data> +</xml> +XML; + +$x = simplexml_load_string($xml); +$x->registerXPathNamespace("a", "http://a"); + +$atts = $x->xpath("/xml/data/@a:label"); +echo $atts[0] . "\n"; +$atts = $x->xpath("/xml/a:data"); +echo $atts[0]->attributes() . "\n"; +$atts = $x->xpath("/xml/a:data/@a:label"); +echo $atts[0] . "\n"; +$atts = $x->xpath("/xml/a:data/@label"); +echo $atts[0] . "\n"; +$atts = $x->xpath("/xml/data/@label"); +echo $atts[0] . "\n"; +?> +===DONE=== +--EXPECTF-- +I am A +I am a:Nothing +I am a:A +I am a:Nothing +I am Nothing +===DONE=== +
\ No newline at end of file diff --git a/ext/simplexml/tests/bug46003.phpt b/ext/simplexml/tests/bug46003.phpt new file mode 100644 index 0000000..712675c --- /dev/null +++ b/ext/simplexml/tests/bug46003.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #46003 (isset on nonexisting nodes return unexpected results) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<XML +<r> + <p>Test</p> + <o d='h'> + <xx rr='info' /> + <yy rr='data' /> + </o> +</r> +XML; + +$x = simplexml_load_string($xml); + +var_dump(isset($x->p)); +var_dump(isset($x->p->o)); +var_dump(isset($x->o->yy)); +var_dump(isset($x->o->zz)); +var_dump(isset($x->o->text)); +var_dump(isset($x->o->xx)); +?> +===DONE=== +--EXPECTF-- +bool(true) +bool(false) +bool(true) +bool(false) +bool(false) +bool(true) +===DONE=== +
\ No newline at end of file diff --git a/ext/simplexml/tests/bug46047.phpt b/ext/simplexml/tests/bug46047.phpt new file mode 100644 index 0000000..0438154 --- /dev/null +++ b/ext/simplexml/tests/bug46047.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #46047 (SimpleXML converts empty nodes into object with nested array) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml = new SimpleXMLElement('<foo><bar><![CDATA[]]></bar><baz/></foo>', + LIBXML_NOCDATA); +print_r($xml); + +$xml = new SimpleXMLElement('<foo><bar></bar><baz/></foo>'); +print_r($xml); + +$xml = new SimpleXMLElement('<foo><bar/><baz/></foo>'); +print_r($xml); +?> +===DONE=== +--EXPECTF-- +SimpleXMLElement Object +( + [bar] => SimpleXMLElement Object + ( + ) + + [baz] => SimpleXMLElement Object + ( + ) + +) +SimpleXMLElement Object +( + [bar] => SimpleXMLElement Object + ( + ) + + [baz] => SimpleXMLElement Object + ( + ) + +) +SimpleXMLElement Object +( + [bar] => SimpleXMLElement Object + ( + ) + + [baz] => SimpleXMLElement Object + ( + ) + +) +===DONE=== +
\ No newline at end of file diff --git a/ext/simplexml/tests/bug46048.phpt b/ext/simplexml/tests/bug46048.phpt new file mode 100644 index 0000000..97fc9ed --- /dev/null +++ b/ext/simplexml/tests/bug46048.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #46048 (SimpleXML top-level @attributes not part of iterator) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml = ' +<data id="1"> + <key>value</key> +</data> +'; +$obj = simplexml_load_string($xml); +print_r(get_object_vars($obj)); +?> +===DONE=== +--EXPECT-- +Array +( + [@attributes] => Array + ( + [id] => 1 + ) + + [key] => value +) +===DONE=== diff --git a/ext/simplexml/tests/bug48601.phpt b/ext/simplexml/tests/bug48601.phpt new file mode 100644 index 0000000..0b81fac --- /dev/null +++ b/ext/simplexml/tests/bug48601.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #48601 (xpath() returns FALSE for legitimate query) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$sxe = simplexml_load_string('<root><node1>1</node1></root>'); + +$nodes = $sxe->xpath("/root/node2/@test"); + +if (! is_array($nodes)) { + echo "An error occurred\n"; +} else { + echo "Result Count: " . count($nodes) . "\n"; +} + +?> +--EXPECTF-- +Result Count: 0 diff --git a/ext/simplexml/tests/bug51615.phpt b/ext/simplexml/tests/bug51615.phpt new file mode 100644 index 0000000..c96b3ae --- /dev/null +++ b/ext/simplexml/tests/bug51615.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #51615 (PHP crash with wrong HTML in SimpleXML) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; + if (!extension_loaded("dom")) print "skip"; +?> +--FILE-- +<?php + +$dom = new DOMDocument; +$dom->loadHTML('<span title=""y">x</span><span title=""z">x</span>'); +$html = simplexml_import_dom($dom); + +var_dump($html->body->span); + +foreach ($html->body->span as $obj) { + var_dump((string)$obj->title); +} + +?> +--EXPECTF-- +Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d + +Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d +object(SimpleXMLElement)#%d (3) { + ["@attributes"]=> + array(2) { + ["title"]=> + string(0) "" + ["y"]=> + string(0) "" + } + [0]=> + string(1) "x" + [1]=> + string(1) "x" +} +string(0) "" +string(0) "" diff --git a/ext/simplexml/tests/feature55218.phpt b/ext/simplexml/tests/feature55218.phpt new file mode 100644 index 0000000..25ea534 --- /dev/null +++ b/ext/simplexml/tests/feature55218.phpt @@ -0,0 +1,117 @@ +--TEST-- +Bug #55218 getDocNamespaces from current element and not root +--SKIPIF-- +<?php +if (!extension_loaded("simplexml")) print "skip SimpleXML not present"; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$x = new SimpleXMLElement( +'<?xml version="1.0" standalone="yes"?> +<people xmlns:p="http://example.org/p" > + <person id="1" xmlns:t="http://example.org/t" > + <t:name>John Doe</t:name> + </person> + <person id="2">Susie Q. Public</person> + <o> + <p:div>jdslkfjsldk jskdfjsmlkjfkldjkjflskj kljfslkjf sldk</p:div> + </o> +</people>'); + +echo "getDocNamespaces\n"; +echo "\nBackwards Compatibility:\n"; +echo "recursion:\n"; + +var_dump ( $x->getDocNamespaces(true) ) ; +var_dump( $x->person[0]->getDocNamespaces(true) ); +var_dump( $x->person[1]->getDocNamespaces(true) ); + +echo "\nnon recursive:\n"; + +var_dump( $x->getDocNamespaces(false) ); +var_dump( $x->person[0]->getDocNamespaces(false) ); +var_dump( $x->person[1]->getDocNamespaces(false) ); + +echo "\n\nUsing new 'from_root' bool set to false:\n"; +echo "recursion:\n"; + +var_dump ( $x->getDocNamespaces(true, false) ) ; +var_dump( $x->person[0]->getDocNamespaces(true, false) ); +var_dump( $x->person[1]->getDocNamespaces(true, false) ); + +echo "\nnon recursive:\n"; + +var_dump( $x->getDocNamespaces(false, false) ); +var_dump( $x->person[0]->getDocNamespaces(false, false) ); +var_dump( $x->person[1]->getDocNamespaces(false, false) ); + +?> +===DONE=== +--EXPECTF-- +getDocNamespaces + +Backwards Compatibility: +recursion: +array(2) { + ["p"]=> + string(20) "http://example.org/p" + ["t"]=> + string(20) "http://example.org/t" +} +array(2) { + ["p"]=> + string(20) "http://example.org/p" + ["t"]=> + string(20) "http://example.org/t" +} +array(2) { + ["p"]=> + string(20) "http://example.org/p" + ["t"]=> + string(20) "http://example.org/t" +} + +non recursive: +array(1) { + ["p"]=> + string(20) "http://example.org/p" +} +array(1) { + ["p"]=> + string(20) "http://example.org/p" +} +array(1) { + ["p"]=> + string(20) "http://example.org/p" +} + + +Using new 'from_root' bool set to false: +recursion: +array(2) { + ["p"]=> + string(20) "http://example.org/p" + ["t"]=> + string(20) "http://example.org/t" +} +array(1) { + ["t"]=> + string(20) "http://example.org/t" +} +array(0) { +} + +non recursive: +array(1) { + ["p"]=> + string(20) "http://example.org/p" +} +array(1) { + ["t"]=> + string(20) "http://example.org/t" +} +array(0) { +} +===DONE===
\ No newline at end of file diff --git a/ext/simplexml/tests/profile01.phpt b/ext/simplexml/tests/profile01.phpt new file mode 100644 index 0000000..91b9544 --- /dev/null +++ b/ext/simplexml/tests/profile01.phpt @@ -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--- diff --git a/ext/simplexml/tests/profile02.phpt b/ext/simplexml/tests/profile02.phpt new file mode 100644 index 0000000..14b5bb8 --- /dev/null +++ b/ext/simplexml/tests/profile02.phpt @@ -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--- diff --git a/ext/simplexml/tests/profile03.phpt b/ext/simplexml/tests/profile03.phpt new file mode 100644 index 0000000..14f1c5f --- /dev/null +++ b/ext/simplexml/tests/profile03.phpt @@ -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--- diff --git a/ext/simplexml/tests/profile04.phpt b/ext/simplexml/tests/profile04.phpt new file mode 100644 index 0000000..27714e9 --- /dev/null +++ b/ext/simplexml/tests/profile04.phpt @@ -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->children('reserved-ns')->child; +echo "\n---Done---\n"; +?> +--EXPECT-- +Hello +---Done--- diff --git a/ext/simplexml/tests/profile05.phpt b/ext/simplexml/tests/profile05.phpt new file mode 100644 index 0000000..f696221 --- /dev/null +++ b/ext/simplexml/tests/profile05.phpt @@ -0,0 +1,18 @@ +--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> +'); + +echo $root->children('reserved')->child; +echo "\n---Done---\n"; +?> +--EXPECT-- +---Done--- diff --git a/ext/simplexml/tests/profile06.phpt b/ext/simplexml/tests/profile06.phpt new file mode 100644 index 0000000..e519fa9 --- /dev/null +++ b/ext/simplexml/tests/profile06.phpt @@ -0,0 +1,20 @@ +--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> +'); + +$attr = $root->child->attributes('reserved-ns'); +echo $attr['attribute']; +echo "\n---Done---\n"; +?> +--EXPECT-- +Sample +---Done--- diff --git a/ext/simplexml/tests/profile07.phpt b/ext/simplexml/tests/profile07.phpt new file mode 100644 index 0000000..c8a4269 --- /dev/null +++ b/ext/simplexml/tests/profile07.phpt @@ -0,0 +1,23 @@ +--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> +'); + +$rsattr = $root->child->attributes('reserved'); +$myattr = $root->child->attributes('reserved-ns'); + +echo $rsattr['attribute']; +echo $myattr['attribute']; +echo "\n---Done---\n"; +?> +--EXPECT-- +Sample +---Done--- diff --git a/ext/simplexml/tests/profile08.phpt b/ext/simplexml/tests/profile08.phpt new file mode 100644 index 0000000..bbb69b7 --- /dev/null +++ b/ext/simplexml/tests/profile08.phpt @@ -0,0 +1,18 @@ +--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--- diff --git a/ext/simplexml/tests/profile09.phpt b/ext/simplexml/tests/profile09.phpt new file mode 100644 index 0000000..714572d --- /dev/null +++ b/ext/simplexml/tests/profile09.phpt @@ -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--- diff --git a/ext/simplexml/tests/profile10.phpt b/ext/simplexml/tests/profile10.phpt new file mode 100644 index 0000000..6ef7456 --- /dev/null +++ b/ext/simplexml/tests/profile10.phpt @@ -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> +'); + +$rsattr = $root->child->attributes('reserved-ns'); +$spattr = $root->child->attributes('special-ns'); + +echo $rsattr['attribute']; +echo "\n"; +echo $spattr['attribute']; +echo "\n---Done---\n"; +?> +--EXPECT-- +Sample +Test +---Done--- diff --git a/ext/simplexml/tests/profile11.phpt b/ext/simplexml/tests/profile11.phpt new file mode 100644 index 0000000..54c31bf --- /dev/null +++ b/ext/simplexml/tests/profile11.phpt @@ -0,0 +1,35 @@ +--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> +'); + +var_dump($root->children('reserved-ns')->child); +var_dump($root->children('special-ns')->child); +var_dump((string)$root->children('reserved-ns')->child); +var_dump((string)$root->children('special-ns')->child); +var_dump($root->child); +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "Hello" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "World" +} +string(5) "Hello" +string(5) "World" +object(SimpleXMLElement)#%d (0) { +} +===DONE=== diff --git a/ext/simplexml/tests/profile12.phpt b/ext/simplexml/tests/profile12.phpt new file mode 100644 index 0000000..51a0d35 --- /dev/null +++ b/ext/simplexml/tests/profile12.phpt @@ -0,0 +1,74 @@ +--TEST-- +SimpleXML [profile]: Accessing namespaced root and non namespaced children +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version="1.0" encoding="utf-8"?> +<soap:Envelope +xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +xmlns:xsd="http://www.w3.org/2001/XMLSchema" +> +<soap:Body> +<businessList foo="bar"> +<businessInfo businessKey="bla"/> +</businessList> +</soap:Body> +</soap:Envelope> +EOF; + +$sxe = simplexml_load_string($xml); +$nsl = $sxe->getNamespaces(); +var_dump($nsl); + +$sxe = simplexml_load_string($xml, NULL, 0, $nsl['soap']); +var_dump($sxe->Body); +var_dump($sxe->Body->children('')); +var_dump($sxe->Body->children('')->businessList); + +?> +===DONE=== +--EXPECTF-- +array(1) { + ["soap"]=> + string(41) "http://schemas.xmlsoap.org/soap/envelope/" +} +object(SimpleXMLElement)#%s (0) { +} +object(SimpleXMLElement)#%s (1) { + ["businessList"]=> + object(SimpleXMLElement)#%s (2) { + ["@attributes"]=> + array(1) { + ["foo"]=> + string(3) "bar" + } + ["businessInfo"]=> + object(SimpleXMLElement)#%s (1) { + ["@attributes"]=> + array(1) { + ["businessKey"]=> + string(3) "bla" + } + } + } +} +object(SimpleXMLElement)#%s (2) { + ["@attributes"]=> + array(1) { + ["foo"]=> + string(3) "bar" + } + ["businessInfo"]=> + object(SimpleXMLElement)#%s (1) { + ["@attributes"]=> + array(1) { + ["businessKey"]=> + string(3) "bla" + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/profile13.phpt b/ext/simplexml/tests/profile13.phpt new file mode 100644 index 0000000..2ae89e7 --- /dev/null +++ b/ext/simplexml/tests/profile13.phpt @@ -0,0 +1,75 @@ +--TEST-- +SimpleXML [profile]: Accessing by namespace prefix +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version="1.0" encoding="utf-8"?> +<soap:Envelope +xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +xmlns:xsd="http://www.w3.org/2001/XMLSchema" +> +<soap:Body> +<businessList foo="bar"> +<businessInfo businessKey="bla"/> +</businessList> +</soap:Body> +</soap:Envelope> +EOF; + +$sxe = simplexml_load_string($xml); +var_dump($sxe->children('soap', 1)); + +$sxe = simplexml_load_string($xml, NULL, 0, 'soap', 1); +var_dump($sxe->Body); +var_dump($sxe->Body->children('')); +var_dump($sxe->Body->children('')->businessList); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + ["Body"]=> + object(SimpleXMLElement)#%d (0) { + } +} +object(SimpleXMLElement)#%d (0) { +} +object(SimpleXMLElement)#%d (1) { + ["businessList"]=> + object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["foo"]=> + string(3) "bar" + } + ["businessInfo"]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["businessKey"]=> + string(3) "bla" + } + } + } +} +object(SimpleXMLElement)#%d (2) { + ["@attributes"]=> + array(1) { + ["foo"]=> + string(3) "bar" + } + ["businessInfo"]=> + object(SimpleXMLElement)#%d (1) { + ["@attributes"]=> + array(1) { + ["businessKey"]=> + string(3) "bla" + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/simplexml_import_dom.phpt b/ext/simplexml/tests/simplexml_import_dom.phpt new file mode 100644 index 0000000..e108e05 --- /dev/null +++ b/ext/simplexml/tests/simplexml_import_dom.phpt @@ -0,0 +1,22 @@ +--TEST-- +SimpleXML [interop]: simplexml_import_dom +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) die("skip"); ?> +<?php if (!extension_loaded("dom")) die("skip dom extension not loaded"); ?> +--FILE-- +<?php +$dom = new domDocument; +$dom->load(dirname(__FILE__)."/book.xml"); +if(!$dom) { + echo "Error while parsing the document\n"; + exit; +} +$s = simplexml_import_dom($dom); +$books = $s->book; +foreach ($books as $book) { + echo "{$book->title} was written by {$book->author}\n"; +} +?> +--EXPECT-- +The Grapes of Wrath was written by John Steinbeck +The Pearl was written by John Steinbeck diff --git a/ext/simplexml/tests/simplexml_load_file.phpt b/ext/simplexml/tests/simplexml_load_file.phpt new file mode 100644 index 0000000..8dc6481 --- /dev/null +++ b/ext/simplexml/tests/simplexml_load_file.phpt @@ -0,0 +1,32 @@ +--TEST-- +simplexml_load_file() +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) die("skip"); ?> +--FILE-- +<?php + $simple = simplexml_load_file(dirname(__FILE__)."/book.xml"); + + var_dump($simple); + echo "Done"; +?> +--EXPECTF-- +object(SimpleXMLElement)#1 (1) { + ["book"]=> + array(2) { + [0]=> + object(SimpleXMLElement)#2 (2) { + ["title"]=> + string(19) "The Grapes of Wrath" + ["author"]=> + string(14) "John Steinbeck" + } + [1]=> + object(SimpleXMLElement)#3 (2) { + ["title"]=> + string(9) "The Pearl" + ["author"]=> + string(14) "John Steinbeck" + } + } +} +Done
\ No newline at end of file diff --git a/ext/simplexml/tests/sxe.dtd b/ext/simplexml/tests/sxe.dtd new file mode 100755 index 0000000..b75a792 --- /dev/null +++ b/ext/simplexml/tests/sxe.dtd @@ -0,0 +1,34 @@ +<?xml encoding='US-ASCII'?>
+
+<!ELEMENT sxe (elem1+, elem11, elem22*)>
+<!ATTLIST sxe id CDATA #implied>
+
+<!ELEMENT elem1 elem2*>
+<!ATTLIST elem1 attr1 CDATA #required
+ attr2 CDATA "default>
+
+<!ELEMENT elem2 elem3*>
+<!ATTLIST elem2 att25 CDATA #implied
+ att42 CDATA #implied>
+
+<!ELEMENT elem3 elem4*>
+<!ATTLIST elem3>
+
+<!ELEMENT elem4 EMPTY>
+<!ATTLIST elem4>
+
+<!ELEMENT elem11 elem111*>
+<!ATTLIST elem11>
+
+<!ELEMNET elem111 elem1111*>
+<!ATTLIST elem111>
+
+<!ELEMENT elem1111 EMPTY>
+<!ATTLIST elem1111>
+
+<!ELEMENT elem22 elem222*>
+<!ATTLIST elem22 attr22 CDATA #implied>
+
+<!ELEMENT elem222 EMPTY>
+<!ATTLIST elem222>
+
diff --git a/ext/simplexml/tests/sxe.ent b/ext/simplexml/tests/sxe.ent new file mode 100755 index 0000000..8f86465 --- /dev/null +++ b/ext/simplexml/tests/sxe.ent @@ -0,0 +1 @@ +<!ENTITY included-entity "This is text included from an entity"> diff --git a/ext/simplexml/tests/sxe.xml b/ext/simplexml/tests/sxe.xml new file mode 100755 index 0000000..909b4e6 --- /dev/null +++ b/ext/simplexml/tests/sxe.xml @@ -0,0 +1,17 @@ +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd" [ +<!ENTITY % incent SYSTEM "sxe.ent"> +%incent; +]> +<sxe id="elem1"> + <elem1 attr1='first'> + <!-- comment --> + <elem2> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe>
\ No newline at end of file diff --git a/ext/simplexml/tests/sxe_001.phpt b/ext/simplexml/tests/sxe_001.phpt new file mode 100644 index 0000000..bb93eea --- /dev/null +++ b/ext/simplexml/tests/sxe_001.phpt @@ -0,0 +1,63 @@ +--TEST-- +SPL: SimpleXMLIterator +--SKIPIF-- +<?php +if (!extension_loaded("simplexml")) print "skip SimpleXML not present"; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + <elem1 attr1='first'> + <!-- comment --> + <elem2> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF; + +var_dump(simplexml_load_string((binary)$xml, 'SimpleXMLIterator')); + +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLIterator)#%d (2) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(5) "elem1" + } + ["elem1"]=> + object(SimpleXMLIterator)#%d (3) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(5) "first" + } + ["comment"]=> + object(SimpleXMLIterator)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLIterator)#%d (1) { + ["elem3"]=> + object(SimpleXMLIterator)#%d (1) { + ["elem4"]=> + object(SimpleXMLIterator)#%d (1) { + ["test"]=> + object(SimpleXMLIterator)#%d (0) { + } + } + } + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/sxe_002.phpt b/ext/simplexml/tests/sxe_002.phpt new file mode 100644 index 0000000..b937b01 --- /dev/null +++ b/ext/simplexml/tests/sxe_002.phpt @@ -0,0 +1,75 @@ +--TEST-- +SPL: SimpleXMLIterator and recursion +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<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. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + <elem111> + Foo Bar + </elem111> + </elem11> +</sxe> +EOF; + +$sxe = simplexml_load_string((binary)$xml, 'SimpleXMLIterator'); + +foreach(new RecursiveIteratorIterator($sxe, 1) as $name => $data) { + var_dump($name); + var_dump(get_class($data)); + var_dump(trim($data)); +} + +echo "===DUMP===\n"; + +var_dump(get_class($sxe)); +var_dump(trim($sxe->elem1)); + +?> +===DONE=== +--EXPECT-- +string(5) "elem1" +string(17) "SimpleXMLIterator" +string(10) "Bla bla 1." +string(5) "elem2" +string(17) "SimpleXMLIterator" +string(28) "Here we have some text data." +string(5) "elem3" +string(17) "SimpleXMLIterator" +string(19) "And here some more." +string(5) "elem4" +string(17) "SimpleXMLIterator" +string(15) "Wow once again." +string(6) "elem11" +string(17) "SimpleXMLIterator" +string(10) "Bla bla 2." +string(7) "elem111" +string(17) "SimpleXMLIterator" +string(7) "Foo Bar" +===DUMP=== +string(17) "SimpleXMLIterator" +string(10) "Bla bla 1." +===DONE=== diff --git a/ext/simplexml/tests/sxe_003.phpt b/ext/simplexml/tests/sxe_003.phpt new file mode 100644 index 0000000..58c7523 --- /dev/null +++ b/ext/simplexml/tests/sxe_003.phpt @@ -0,0 +1,77 @@ +--TEST-- +SPL: SimpleXMLIterator and getChildren() +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<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. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + <elem111> + Foo Bar + </elem111> + </elem11> +</sxe> +EOF; + +$sxe = simplexml_load_string((binary)$xml, 'SimpleXMLIterator'); + +foreach($sxe->getChildren() as $name => $data) { + var_dump($name); + var_dump(get_class($data)); + var_dump(trim($data)); +} + +echo "===RESET===\n"; + +for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + var_dump($sxe->hasChildren()); + var_dump(trim($sxe->key())); + var_dump(trim($sxe->current())); + foreach($sxe->getChildren() as $name => $data) { + var_dump($name); + var_dump(get_class($data)); + var_dump(trim($data)); + } +} + +?> +===DONE=== +--EXPECTF-- + +Warning: Invalid argument supplied for foreach() in %ssxe_003.php on line %d +===RESET=== +bool(true) +string(5) "elem1" +string(10) "Bla bla 1." +string(5) "elem2" +string(17) "SimpleXMLIterator" +string(28) "Here we have some text data." +bool(true) +string(6) "elem11" +string(10) "Bla bla 2." +string(7) "elem111" +string(17) "SimpleXMLIterator" +string(7) "Foo Bar" +===DONE=== diff --git a/ext/simplexml/tests/sxe_004.phpt b/ext/simplexml/tests/sxe_004.phpt new file mode 100644 index 0000000..20431de --- /dev/null +++ b/ext/simplexml/tests/sxe_004.phpt @@ -0,0 +1,145 @@ +--TEST-- +SPL: SimpleXMLIterator and overridden iterator methods() +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<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. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + <elem111> + Foo Bar + </elem111> + </elem11> +</sxe> +EOF; + +class SXETest extends SimpleXMLIterator +{ + function rewind() + { + echo __METHOD__ . "\n"; + return parent::rewind(); + } + function valid() + { + echo __METHOD__ . "\n"; + return parent::valid(); + } + function current() + { + echo __METHOD__ . "\n"; + return parent::current(); + } + function key() + { + echo __METHOD__ . "\n"; + return parent::key(); + } + function next() + { + echo __METHOD__ . "\n"; + return parent::next(); + } + function hasChildren() + { + echo __METHOD__ . "\n"; + return parent::hasChildren(); + } + function getChildren() + { + echo __METHOD__ . "\n"; + return parent::getChildren(); + } +} + +$sxe = new SXETest((binary)$xml); +$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::SELF_FIRST); + +foreach($rit as $data) { + var_dump(get_class($data)); + var_dump(trim($data)); +} + +?> +===DONE=== +--EXPECTF-- +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(10) "Bla bla 1." +SXETest::getChildren +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(28) "Here we have some text data." +SXETest::getChildren +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(19) "And here some more." +SXETest::getChildren +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(15) "Wow once again." +SXETest::next +SXETest::valid +SXETest::next +SXETest::valid +SXETest::next +SXETest::valid +SXETest::next +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(10) "Bla bla 2." +SXETest::getChildren +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(7) "Foo Bar" +SXETest::next +SXETest::valid +SXETest::next +SXETest::valid +SXETest::valid +===DONE=== diff --git a/ext/simplexml/tests/sxe_005.phpt b/ext/simplexml/tests/sxe_005.phpt new file mode 100644 index 0000000..183d351 --- /dev/null +++ b/ext/simplexml/tests/sxe_005.phpt @@ -0,0 +1,44 @@ +--TEST-- +SPL: SimpleXMLIterator and overriden count() +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<sxe> + <elem1/> + <elem2/> + <elem2/> +</sxe> +EOF; + +class SXETest extends SimpleXMLIterator +{ + function count() + { + echo __METHOD__ . "\n"; + return parent::count(); + } +} + +$sxe = new SXETest((binary)$xml); + +var_dump(count($sxe)); +var_dump(count($sxe->elem1)); +var_dump(count($sxe->elem2)); + +?> +===DONE=== +--EXPECT-- +SXETest::count +int(3) +SXETest::count +int(1) +SXETest::count +int(2) +===DONE=== |