diff options
Diffstat (limited to 'ext/dom/tests')
22 files changed, 449 insertions, 14 deletions
diff --git a/ext/dom/tests/DOMDocument_loadHTML_error1.phpt b/ext/dom/tests/DOMDocument_loadHTML_error1.phpt new file mode 100644 index 000000000..c7b5e614d --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadHTML_error1.phpt @@ -0,0 +1,15 @@ +--TEST-- +DOMDocument::loadHTML() should fail if no parameter is given +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$doc = new DOMDocument(); +$doc->loadHTML(); +?> +--EXPECTF-- +Warning: DOMDocument::loadHTML() expects exactly 1 parameter, 0 given in %s on line %d diff --git a/ext/dom/tests/DOMDocument_loadHTML_error2.phpt b/ext/dom/tests/DOMDocument_loadHTML_error2.phpt new file mode 100644 index 000000000..3167c0189 --- /dev/null +++ b/ext/dom/tests/DOMDocument_loadHTML_error2.phpt @@ -0,0 +1,15 @@ +--TEST-- +DOMDocument::loadHTML() should fail if empty string provided as input +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$doc = new DOMDocument(); +$doc->loadHTML(''); +?> +--EXPECTF-- +Warning: DOMDocument::loadHTML(): Empty string supplied as input in %s on line %d diff --git a/ext/dom/tests/DOMDocument_relaxNGValidateSource_basic.phpt b/ext/dom/tests/DOMDocument_relaxNGValidateSource_basic.phpt new file mode 100644 index 000000000..93b9cf717 --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidateSource_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +DOMDocument::relaxNGValidateSource() +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$rng = <<< RNG +<?xml version="1.0" encoding="UTF-8"?> +<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0" + datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <start> + <element name="apple"> + <element name="pear"> + <data type="NCName"/> + </element> + </element> + </start> +</grammar> +RNG; + +$good_xml = <<< GOOD_XML +<?xml version="1.0"?> +<apple> + <pear>Pear</pear> +</apple> +GOOD_XML; + +$doc = new DOMDocument(); +$doc->loadXML($good_xml); +$result = $doc->relaxNGValidateSource($rng); +var_dump($result); + +?> +--EXPECTF-- +bool(true) diff --git a/ext/dom/tests/DOMDocument_relaxNGValidateSource_error1.phpt b/ext/dom/tests/DOMDocument_relaxNGValidateSource_error1.phpt new file mode 100644 index 000000000..7da71a57a --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidateSource_error1.phpt @@ -0,0 +1,41 @@ +--TEST-- +DOMDocument::relaxNGValidateSource() should fail if document doesn't validate +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$rng = <<< RNG +<?xml version="1.0" encoding="UTF-8"?> +<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0" + datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <start> + <element name="apple"> + <element name="pear"> + <data type="NCName"/> + </element> + </element> + </start> +</grammar> +RNG; + +$bad_xml = <<< BAD_XML +<?xml version="1.0"?> +<apple> + <pear>Pear</pear> + <pear>Pear</pear> +</apple> +BAD_XML; + +$doc = new DOMDocument(); +$doc->loadXML($bad_xml); +$result = $doc->relaxNGValidateSource($rng); +var_dump($result); + +?> +--EXPECTF-- +Warning: DOMDocument::relaxNGValidateSource(): Did not expect element pear there in %s on line %d +bool(false) diff --git a/ext/dom/tests/DOMDocument_relaxNGValidateSource_error2.phpt b/ext/dom/tests/DOMDocument_relaxNGValidateSource_error2.phpt new file mode 100644 index 000000000..d689934f4 --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidateSource_error2.phpt @@ -0,0 +1,39 @@ +--TEST-- +DOMDocument::relaxNGValidateSource() should fail on invalid RNG schema +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$rng = <<< RNG +<?xml version="1.0" encoding="UTF-8"?> +<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0" + datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <start> + <element name="apple"> + </element> + </start> +</grammar> +RNG; + +$xml = <<< XML +<?xml version="1.0"?> +<apple> + <pear>Pear</pear> +</apple> +XML; + +$doc = new DOMDocument(); +$doc->loadXML($xml); +$result = $doc->relaxNGValidateSource($rng); +var_dump($result); + +?> +--EXPECTF-- +Warning: DOMDocument::relaxNGValidateSource(): xmlRelaxNGParseElement: element has no content in %s on line %d + +Warning: DOMDocument::relaxNGValidateSource(): Invalid RelaxNG in %s on line %d +bool(false) diff --git a/ext/dom/tests/DOMDocument_relaxNGValidate_basic.phpt b/ext/dom/tests/DOMDocument_relaxNGValidate_basic.phpt new file mode 100644 index 000000000..76a64425c --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidate_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +DOMDocument::relaxNGValidate() +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$rng = dirname(__FILE__).'/DOMDocument_relaxNGValidate_basic.rng'; +$xml = <<< XML +<?xml version="1.0"?> +<apple> + <pear>Pear</pear> +</apple> +XML; +$doc = new DOMDocument(); +$doc->loadXML($xml); +$result = $doc->relaxNGValidate($rng); +var_dump($result); +?> +--EXPECTF-- +bool(true) diff --git a/ext/dom/tests/DOMDocument_relaxNGValidate_basic.rng b/ext/dom/tests/DOMDocument_relaxNGValidate_basic.rng new file mode 100644 index 000000000..35e351844 --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidate_basic.rng @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0" + datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <start> + <element name="apple"> + <element name="pear"> + <data type="NCName"/> + </element> + </element> + </start> +</grammar> diff --git a/ext/dom/tests/DOMDocument_relaxNGValidate_error1.phpt b/ext/dom/tests/DOMDocument_relaxNGValidate_error1.phpt new file mode 100644 index 000000000..82957c35b --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidate_error1.phpt @@ -0,0 +1,26 @@ +--TEST-- +DOMDocument::relaxNGValidate() should fail if document doesn't validate +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$rng = dirname(__FILE__).'/DOMDocument_relaxNGValidate_basic.rng'; +$xml = <<< XML +<?xml version="1.0"?> +<apple> + <pear>Pear</pear> + <pear>Pear</pear> +</apple> +XML; +$doc = new DOMDocument(); +$doc->loadXML($xml); +$result = $doc->relaxNGValidate($rng); +var_dump($result); +?> +--EXPECTF-- +Warning: DOMDocument::relaxNGValidate(): Did not expect element pear there in %s on line %d +bool(false) diff --git a/ext/dom/tests/DOMDocument_relaxNGValidate_error2.phpt b/ext/dom/tests/DOMDocument_relaxNGValidate_error2.phpt new file mode 100644 index 000000000..85749210b --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidate_error2.phpt @@ -0,0 +1,25 @@ +--TEST-- +DOMDocument::relaxNGValidate() should fail on invalid RelaxNG file source +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$rng = dirname(__FILE__).'/foo.rng'; +$xml = <<< XML +<?xml version="1.0"?> +<apple> + <pear>Pear</pear> + <pear>Pear</pear> +</apple> +XML; +$doc = new DOMDocument(); +$doc->loadXML($xml); +$result = $doc->relaxNGValidate($rng); +var_dump($result); +?> +--EXPECTF-- + diff --git a/ext/dom/tests/DOMDocument_validate_on_parse_variation.phpt b/ext/dom/tests/DOMDocument_validate_on_parse_variation.phpt index 6aa390ca9..403e01aa7 100644 --- a/ext/dom/tests/DOMDocument_validate_on_parse_variation.phpt +++ b/ext/dom/tests/DOMDocument_validate_on_parse_variation.phpt @@ -6,17 +6,14 @@ Hans Zaunere --SKIPIF-- <?php require_once('skipif.inc'); - -// need external DTD/XML docs -if( @file_get_contents('http://www.php.net/') === FALSE ) - exit('skip network not available'); ?> --FILE-- <?php require_once('dom_test.inc'); -$XMLStringGood = file_get_contents('http://www.php.net/'); +chdir(__DIR__ . "/../examples"); +$XMLStringGood = file_get_contents('note.xml'); $dom = new DOMDocument; $dom->resolveExternals = TRUE; @@ -27,7 +24,7 @@ $dom->loadXML($XMLStringGood); echo "No Error Report Above\n"; $BogusElement = $dom->createElement('NYPHP','DOMinatrix'); -$Body = $dom->getElementsByTagName('body')->item(0); +$Body = $dom->getElementsByTagName('from')->item(0); $Body->appendChild($BogusElement); $XMLStringBad = $dom->saveXML(); @@ -44,6 +41,6 @@ validateOnParse set to TRUE: Warning: DOMDocument::loadXML(): No declaration for element NYPHP in Entity, line: %d in %s on line %d -Warning: DOMDocument::loadXML(): Element body content does not follow the DTD, expecting (p | h1 | h2 | h3 | h4 | h5 | h6 | div | ul | ol | dl | pre | hr | blockquote | address | fieldset | table | form | noscript | ins | del | script)*, got (div div div div div NYPHP) in Entity, line: %d in %s on line %d +Warning: DOMDocument::loadXML(): Element from was declared #PCDATA but contains non text nodes in Entity, line: %d in %s on line %d Error Report Above diff --git a/ext/dom/tests/DOMImplementation_createDocumentType_basic.phpt b/ext/dom/tests/DOMImplementation_createDocumentType_basic.phpt new file mode 100644 index 000000000..3b19ea461 --- /dev/null +++ b/ext/dom/tests/DOMImplementation_createDocumentType_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +DOMImplementation::createDocumentType() +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php +$imp = new DOMImplementation(); +$doctype = $imp->createDocumentType("html", + "-//W3C//DTD XHTML 1.0 Strict//EN", + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); +$doc = $imp->createDocument(null, 'html', $doctype); +echo $doc->saveHTML(); +?> +--EXPECTF-- +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html></html> diff --git a/ext/dom/tests/DOMImplementation_createDocument_basic.phpt b/ext/dom/tests/DOMImplementation_createDocument_basic.phpt new file mode 100644 index 000000000..78d20aeee --- /dev/null +++ b/ext/dom/tests/DOMImplementation_createDocument_basic.phpt @@ -0,0 +1,14 @@ +--TEST-- +DOMImplementation::createDocument() +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php +$x = new DOMImplementation(); +$doc = $x->createDocument(null, 'html'); +echo $doc->saveHTML(); +?> +--EXPECTF-- +<html></html> diff --git a/ext/dom/tests/DOMImplementation_hasFeature_basic.phpt b/ext/dom/tests/DOMImplementation_hasFeature_basic.phpt new file mode 100644 index 000000000..b53e912b7 --- /dev/null +++ b/ext/dom/tests/DOMImplementation_hasFeature_basic.phpt @@ -0,0 +1,15 @@ +--TEST-- +DOMImplementation::hasFeature() +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php +$imp = new DOMImplementation(); +var_dump($imp->hasFeature('Core', '1.0')); +var_dump($imp->hasFeature('XML', '2.0')); +?> +--EXPECTF-- +bool(true) +bool(true) diff --git a/ext/dom/tests/DOMNode_C14NFile_basic.phpt b/ext/dom/tests/DOMNode_C14NFile_basic.phpt new file mode 100644 index 000000000..6af6e3ecb --- /dev/null +++ b/ext/dom/tests/DOMNode_C14NFile_basic.phpt @@ -0,0 +1,38 @@ +--TEST-- +DOMNode::C14NFile() +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php +$xml = <<< XML +<?xml version="1.0" ?> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> +XML; + +$output = dirname(__FILE__).'/DOMNode_C14NFile_basic.tmp'; +$doc = new DOMDocument(); +$doc->loadXML($xml); +$node = $doc->getElementsByTagName('title')->item(0); +var_dump($node->C14NFile($output)); +$content = file_get_contents($output); +var_dump($content); +?> +--CLEAN-- +<?php +$output = dirname(__FILE__).'/DOMNode_C14NFile_basic.tmp'; +unlink($output); +?> +--EXPECTF-- +int(34) +string(34) "<title>The Grapes of Wrath</title>" diff --git a/ext/dom/tests/DOMNode_C14N_basic.phpt b/ext/dom/tests/DOMNode_C14N_basic.phpt new file mode 100644 index 000000000..52a47a15d --- /dev/null +++ b/ext/dom/tests/DOMNode_C14N_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +DOMNode::C14N() +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php +$xml = <<< XML +<?xml version="1.0" ?> +<books> + <book> + <title>The Grapes of Wrath</title> + <author>John Steinbeck</author> + </book> + <book> + <title>The Pearl</title> + <author>John Steinbeck</author> + </book> +</books> +XML; + +$doc = new DOMDocument(); +$doc->loadXML($xml); +$node = $doc->getElementsByTagName('title')->item(0); +var_dump($node->C14N()); +?> +--EXPECTF-- +string(34) "<title>The Grapes of Wrath</title>" diff --git a/ext/dom/tests/DOMNode_getLineNo_basic.phpt b/ext/dom/tests/DOMNode_getLineNo_basic.phpt new file mode 100644 index 000000000..3f57681c3 --- /dev/null +++ b/ext/dom/tests/DOMNode_getLineNo_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +DOMNode::getLineNo() +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php +$file = dirname(__FILE__).'/book.xml'; +$doc = new DOMDocument(); +$doc->load($file); +$nodes = $doc->getElementsByTagName('title'); +foreach($nodes as $node) { + var_dump($node->getLineNo()); +} +?> +--EXPECTF-- +int(4) +int(8) diff --git a/ext/dom/tests/DOMNode_getNodePath_basic.phpt b/ext/dom/tests/DOMNode_getNodePath_basic.phpt new file mode 100644 index 000000000..7c14ffab9 --- /dev/null +++ b/ext/dom/tests/DOMNode_getNodePath_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +DOMNode::getNodePath() +--SKIPIF-- +<?php +include('skipif.inc'); +?> +--FILE-- +<?php +$file = dirname(__FILE__).'/book.xml'; +$doc = new DOMDocument(); +$doc->load($file); +$nodes = $doc->getElementsByTagName('title'); +foreach($nodes as $node) { + var_dump($node->getNodePath()); +} +?> +--EXPECTF-- +string(20) "/books/book[1]/title" +string(20) "/books/book[2]/title" diff --git a/ext/dom/tests/DOMNode_insertBefore_error1.phpt b/ext/dom/tests/DOMNode_insertBefore_error1.phpt new file mode 100644 index 000000000..d655479d0 --- /dev/null +++ b/ext/dom/tests/DOMNode_insertBefore_error1.phpt @@ -0,0 +1,24 @@ +--TEST-- +DOMNode::insertBefore() should fail if node belongs to another document +--CREDITS-- +Knut Urdalen <knut@php.net> +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +$doc1 = new DOMDocument(); +$doc2 = new DOMDocument(); + +$node_in_doc1 = $doc1->createElement("foo"); +$node_in_doc2 = $doc2->createElement("bar"); + +try { + $node_in_doc2->insertBefore($node_in_doc1); +} catch(DOMException $e) { + echo $e->getMessage(); +} + +?> +--EXPECTF-- +Wrong Document Error diff --git a/ext/dom/tests/bug54601.phpt b/ext/dom/tests/bug54601.phpt new file mode 100644 index 000000000..8a2da2dee --- /dev/null +++ b/ext/dom/tests/bug54601.phpt @@ -0,0 +1,30 @@ +--TEST-- +Segfault when removing the Doctype node +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$xml = <<< XML +<?xml version='1.0' encoding='utf-8' ?> +<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN" "http://www.docbook.org/xml/5.0/dtd/docbook.dtd" [ +<!ENTITY foo '<foo>footext</foo>'> +<!ENTITY bar '<bar>bartext</bar>'> +]> +<set>&foo;&bar;</set> +XML; + +$doc = new DOMDocument(); +$doc->loadXML($xml, LIBXML_NOENT); +$n = $doc->doctype; +$doc->removeChild($n); +var_dump($n); +print $doc->saveXML(); +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +object(DOMDocumentType)#%d (0) { +} +<?xml version="1.0" encoding="utf-8"?> +<set><foo>footext</foo><bar>bartext</bar></set> +===DONE=== diff --git a/ext/dom/tests/dom004.phpt b/ext/dom/tests/dom004.phpt index 82b7915f6..5b65f24ba 100644 --- a/ext/dom/tests/dom004.phpt +++ b/ext/dom/tests/dom004.phpt @@ -3,7 +3,7 @@ Test 4: Streams Test --SKIPIF-- <?php require_once('skipif.inc'); -array_search('compress.zlib', stream_get_wrappers()) or die('skip compress.zlib wrapper is not available'); +in_array('compress.zlib', stream_get_wrappers()) or die('skip compress.zlib wrapper is not available'); ?> --FILE-- <?php diff --git a/ext/dom/tests/dom005.phpt b/ext/dom/tests/dom005.phpt index 249869eff..715aec402 100644 --- a/ext/dom/tests/dom005.phpt +++ b/ext/dom/tests/dom005.phpt @@ -27,10 +27,7 @@ html files with undeclared entities  </body></html> --- save as HTML <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> -<html> -<head><title>Hello world</title></head> -<body> +<html><head><title>Hello world</title></head><body> This is a not well-formed<br> html files with undeclared entities -</body> -</html> +</body></html> diff --git a/ext/dom/tests/dom_xinclude.phpt b/ext/dom/tests/dom_xinclude.phpt index bf335d032..686a9e81a 100644 --- a/ext/dom/tests/dom_xinclude.phpt +++ b/ext/dom/tests/dom_xinclude.phpt @@ -3,7 +3,7 @@ Test: Xinclude and Streams --SKIPIF-- <?php require_once('skipif.inc'); -array_search('compress.zlib', stream_get_wrappers()) or die('skip compress.zlib wrapper is not available'); +in_array('compress.zlib', stream_get_wrappers()) or die('skip compress.zlib wrapper is not available'); ?> --FILE-- <?php |
