From c1c3fada7a6b9a11aca997d042ce219a4202959b Mon Sep 17 00:00:00 2001 From: Knut Urdalen Date: Tue, 28 Jun 2011 20:17:15 +0000 Subject: [PATCH] working on test coverage for ext/dom, here's 17 more tests --- .../tests/DOMDocument_loadHTML_error1.phpt | 15 +++++++ .../tests/DOMDocument_loadHTML_error2.phpt | 15 +++++++ ...MDocument_relaxNGValidateSource_basic.phpt | 39 ++++++++++++++++++ ...Document_relaxNGValidateSource_error1.phpt | 41 +++++++++++++++++++ ...Document_relaxNGValidateSource_error2.phpt | 39 ++++++++++++++++++ .../DOMDocument_relaxNGValidate_basic.phpt | 24 +++++++++++ .../DOMDocument_relaxNGValidate_basic.rng | 11 +++++ .../DOMDocument_relaxNGValidate_error1.phpt | 26 ++++++++++++ .../DOMDocument_relaxNGValidate_error2.phpt | 25 +++++++++++ ...plementation_createDocumentType_basic.phpt | 18 ++++++++ ...OMImplementation_createDocument_basic.phpt | 14 +++++++ .../DOMImplementation_hasFeature_basic.phpt | 15 +++++++ ext/dom/tests/DOMNode_C14NFile_basic.phpt | 38 +++++++++++++++++ ext/dom/tests/DOMNode_C14N_basic.phpt | 29 +++++++++++++ ext/dom/tests/DOMNode_getLineNo_basic.phpt | 19 +++++++++ ext/dom/tests/DOMNode_getNodePath_basic.phpt | 19 +++++++++ .../tests/DOMNode_insertBefore_error1.phpt | 24 +++++++++++ 17 files changed, 411 insertions(+) create mode 100644 ext/dom/tests/DOMDocument_loadHTML_error1.phpt create mode 100644 ext/dom/tests/DOMDocument_loadHTML_error2.phpt create mode 100644 ext/dom/tests/DOMDocument_relaxNGValidateSource_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_relaxNGValidateSource_error1.phpt create mode 100644 ext/dom/tests/DOMDocument_relaxNGValidateSource_error2.phpt create mode 100644 ext/dom/tests/DOMDocument_relaxNGValidate_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_relaxNGValidate_basic.rng create mode 100644 ext/dom/tests/DOMDocument_relaxNGValidate_error1.phpt create mode 100644 ext/dom/tests/DOMDocument_relaxNGValidate_error2.phpt create mode 100644 ext/dom/tests/DOMImplementation_createDocumentType_basic.phpt create mode 100644 ext/dom/tests/DOMImplementation_createDocument_basic.phpt create mode 100644 ext/dom/tests/DOMImplementation_hasFeature_basic.phpt create mode 100644 ext/dom/tests/DOMNode_C14NFile_basic.phpt create mode 100644 ext/dom/tests/DOMNode_C14N_basic.phpt create mode 100644 ext/dom/tests/DOMNode_getLineNo_basic.phpt create mode 100644 ext/dom/tests/DOMNode_getNodePath_basic.phpt create mode 100644 ext/dom/tests/DOMNode_insertBefore_error1.phpt diff --git a/ext/dom/tests/DOMDocument_loadHTML_error1.phpt b/ext/dom/tests/DOMDocument_loadHTML_error1.phpt new file mode 100644 index 00000000000..c7b5e614d7c --- /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 +--SKIPIF-- + +--FILE-- +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 00000000000..3167c018903 --- /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 +--SKIPIF-- + +--FILE-- +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 00000000000..93b9cf71737 --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidateSource_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +DOMDocument::relaxNGValidateSource() +--CREDITS-- +Knut Urdalen +--SKIPIF-- + +--FILE-- + + + + + + + + + + +RNG; + +$good_xml = <<< GOOD_XML + + + Pear + +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 00000000000..7da71a57a19 --- /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 +--SKIPIF-- + +--FILE-- + + + + + + + + + + +RNG; + +$bad_xml = <<< BAD_XML + + + Pear + Pear + +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 00000000000..d689934f4e8 --- /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 +--SKIPIF-- + +--FILE-- + + + + + + + +RNG; + +$xml = <<< XML + + + Pear + +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 00000000000..76a64425ceb --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidate_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +DOMDocument::relaxNGValidate() +--CREDITS-- +Knut Urdalen +--SKIPIF-- + +--FILE-- + + + Pear + +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 00000000000..35e35184432 --- /dev/null +++ b/ext/dom/tests/DOMDocument_relaxNGValidate_basic.rng @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/ext/dom/tests/DOMDocument_relaxNGValidate_error1.phpt b/ext/dom/tests/DOMDocument_relaxNGValidate_error1.phpt new file mode 100644 index 00000000000..82957c35bd5 --- /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 +--SKIPIF-- + +--FILE-- + + + Pear + Pear + +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 00000000000..85749210b08 --- /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 +--SKIPIF-- + +--FILE-- + + + Pear + Pear + +XML; +$doc = new DOMDocument(); +$doc->loadXML($xml); +$result = $doc->relaxNGValidate($rng); +var_dump($result); +?> +--EXPECTF-- + diff --git a/ext/dom/tests/DOMImplementation_createDocumentType_basic.phpt b/ext/dom/tests/DOMImplementation_createDocumentType_basic.phpt new file mode 100644 index 00000000000..3b19ea46145 --- /dev/null +++ b/ext/dom/tests/DOMImplementation_createDocumentType_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +DOMImplementation::createDocumentType() +--SKIPIF-- + +--FILE-- +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-- + + diff --git a/ext/dom/tests/DOMImplementation_createDocument_basic.phpt b/ext/dom/tests/DOMImplementation_createDocument_basic.phpt new file mode 100644 index 00000000000..78d20aeee5f --- /dev/null +++ b/ext/dom/tests/DOMImplementation_createDocument_basic.phpt @@ -0,0 +1,14 @@ +--TEST-- +DOMImplementation::createDocument() +--SKIPIF-- + +--FILE-- +createDocument(null, 'html'); +echo $doc->saveHTML(); +?> +--EXPECTF-- + diff --git a/ext/dom/tests/DOMImplementation_hasFeature_basic.phpt b/ext/dom/tests/DOMImplementation_hasFeature_basic.phpt new file mode 100644 index 00000000000..b53e912b779 --- /dev/null +++ b/ext/dom/tests/DOMImplementation_hasFeature_basic.phpt @@ -0,0 +1,15 @@ +--TEST-- +DOMImplementation::hasFeature() +--SKIPIF-- + +--FILE-- +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 00000000000..6af6e3ecb28 --- /dev/null +++ b/ext/dom/tests/DOMNode_C14NFile_basic.phpt @@ -0,0 +1,38 @@ +--TEST-- +DOMNode::C14NFile() +--SKIPIF-- + +--FILE-- + + + + The Grapes of Wrath + John Steinbeck + + + The Pearl + John Steinbeck + + +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-- + +--EXPECTF-- +int(34) +string(34) "The Grapes of Wrath" diff --git a/ext/dom/tests/DOMNode_C14N_basic.phpt b/ext/dom/tests/DOMNode_C14N_basic.phpt new file mode 100644 index 00000000000..52a47a15d27 --- /dev/null +++ b/ext/dom/tests/DOMNode_C14N_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +DOMNode::C14N() +--SKIPIF-- + +--FILE-- + + + + The Grapes of Wrath + John Steinbeck + + + The Pearl + John Steinbeck + + +XML; + +$doc = new DOMDocument(); +$doc->loadXML($xml); +$node = $doc->getElementsByTagName('title')->item(0); +var_dump($node->C14N()); +?> +--EXPECTF-- +string(34) "The Grapes of Wrath" diff --git a/ext/dom/tests/DOMNode_getLineNo_basic.phpt b/ext/dom/tests/DOMNode_getLineNo_basic.phpt new file mode 100644 index 00000000000..3f57681c3e0 --- /dev/null +++ b/ext/dom/tests/DOMNode_getLineNo_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +DOMNode::getLineNo() +--SKIPIF-- + +--FILE-- +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 00000000000..7c14ffab909 --- /dev/null +++ b/ext/dom/tests/DOMNode_getNodePath_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +DOMNode::getNodePath() +--SKIPIF-- + +--FILE-- +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 00000000000..d655479d004 --- /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 +--SKIPIF-- + +--FILE-- +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