From 634f233cc015a96cce89e10f2eefe24a3bb73a14 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Thu, 2 Jul 2009 00:04:52 +0000 Subject: [PATCH] - MFH: New tests (NorwayUG testfest) --- ...MDocument_createEntityReference_basic.phpt | 19 +++++++++++ .../tests/DOMDocument_saveHTMLFile_basic.phpt | 29 ++++++++++++++++ .../DOMDocument_saveHTMLFile_error1.phpt | 24 ++++++++++++++ .../DOMDocument_saveHTMLFile_error2.phpt | 15 +++++++++ ...DOMDocument_saveHTMLFile_formatOutput.phpt | 33 +++++++++++++++++++ ...ocument_saveHTMLFile_invalid_filename.phpt | 25 ++++++++++++++ ext/dom/tests/DOMDocument_saveHTML_basic.phpt | 24 ++++++++++++++ .../tests/DOMDocument_saveHTML_error1.phpt | 24 ++++++++++++++ .../tests/DOMDocument_saveHTML_error2.phpt | 15 +++++++++ ext/dom/tests/DOMDocument_validate_basic.phpt | 31 +++++++++++++++++ .../tests/DOMDocument_validate_error1.phpt | 16 +++++++++ .../tests/DOMDocument_validate_error2.phpt | 15 +++++++++ .../DOMDocument_validate_external_dtd.phpt | 19 +++++++++++ 13 files changed, 289 insertions(+) create mode 100644 ext/dom/tests/DOMDocument_createEntityReference_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_saveHTMLFile_error1.phpt create mode 100644 ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt create mode 100644 ext/dom/tests/DOMDocument_saveHTMLFile_formatOutput.phpt create mode 100644 ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt create mode 100644 ext/dom/tests/DOMDocument_saveHTML_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_saveHTML_error1.phpt create mode 100644 ext/dom/tests/DOMDocument_saveHTML_error2.phpt create mode 100644 ext/dom/tests/DOMDocument_validate_basic.phpt create mode 100644 ext/dom/tests/DOMDocument_validate_error1.phpt create mode 100644 ext/dom/tests/DOMDocument_validate_error2.phpt create mode 100644 ext/dom/tests/DOMDocument_validate_external_dtd.phpt diff --git a/ext/dom/tests/DOMDocument_createEntityReference_basic.phpt b/ext/dom/tests/DOMDocument_createEntityReference_basic.phpt new file mode 100644 index 0000000000..4f4ddf1765 --- /dev/null +++ b/ext/dom/tests/DOMDocument_createEntityReference_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +DOMDocument::createEntityReference() should create a new entity reference node +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +createEntityReference('nbsp'); +$dom->appendChild($ref); +echo $dom->saveXML(); +?> +--EXPECTF-- + +  diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt new file mode 100644 index 0000000000..dd0824b0d1 --- /dev/null +++ b/ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +DOMDocument::saveHTMLFile() should dump the internal document into a file using HTML formatting +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +createElement('html'); +$root = $doc->appendChild($root); +$head = $doc->createElement('head'); +$head = $root->appendChild($head); +$title = $doc->createElement('title'); +$title = $head->appendChild($title); +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); +$bytes = $doc->saveHTMLFile($filename); +var_dump($bytes); +echo file_get_contents($filename); +unlink($filename); +?> +--EXPECTF-- +int(126) +This is the title diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_error1.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_error1.phpt new file mode 100644 index 0000000000..d4dfbe8fe0 --- /dev/null +++ b/ext/dom/tests/DOMDocument_saveHTMLFile_error1.phpt @@ -0,0 +1,24 @@ +--TEST-- +DOMDocument::saveHTMLFile() should fail if no parameter is given +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +createElement('html'); +$root = $doc->appendChild($root); +$head = $doc->createElement('head'); +$head = $root->appendChild($head); +$title = $doc->createElement('title'); +$title = $head->appendChild($title); +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); +$doc->saveHTMLFile(); +?> +--EXPECTF-- +Warning: DOMDocument::saveHTMLFile() expects exactly 1 parameter, 0 given in %s on line %d diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt new file mode 100644 index 0000000000..33e07c641d --- /dev/null +++ b/ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt @@ -0,0 +1,15 @@ +--TEST-- +DOMDocument::saveHTMLFile() should fail if called statically +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Non-static method DOMDocument::saveHTMLFile() cannot be called statically in %s on line %d diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_formatOutput.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_formatOutput.phpt new file mode 100644 index 0000000000..5aece3780a --- /dev/null +++ b/ext/dom/tests/DOMDocument_saveHTMLFile_formatOutput.phpt @@ -0,0 +1,33 @@ +--TEST-- +DOMDocument::saveHTMLFile() should format output on demand +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +formatOutput = true; +$root = $doc->createElement('html'); +$root = $doc->appendChild($root); +$head = $doc->createElement('head'); +$head = $root->appendChild($head); +$title = $doc->createElement('title'); +$title = $head->appendChild($title); +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); +$bytes = $doc->saveHTMLFile($filename); +var_dump($bytes); +echo file_get_contents($filename); +unlink($filename); +?> +--EXPECTF-- +int(129) + + +This is the title + diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt new file mode 100644 index 0000000000..d5c6a797ef --- /dev/null +++ b/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt @@ -0,0 +1,25 @@ +--TEST-- +DOMDocument::saveHTMLFile() should fail with invalid filename +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +createElement('html'); +$root = $doc->appendChild($root); +$head = $doc->createElement('head'); +$head = $root->appendChild($head); +$title = $doc->createElement('title'); +$title = $head->appendChild($title); +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); +$bytes = $doc->saveHTMLFile($filename); +?> +--EXPECTF-- +Warning: DOMDocument::saveHTMLFile(): Invalid Filename in %s on line %d diff --git a/ext/dom/tests/DOMDocument_saveHTML_basic.phpt b/ext/dom/tests/DOMDocument_saveHTML_basic.phpt new file mode 100644 index 0000000000..76f1ed0abf --- /dev/null +++ b/ext/dom/tests/DOMDocument_saveHTML_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +DOMDocument::saveHTML() should dump the internal document into a string using HTML formatting +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +createElement('html'); +$root = $doc->appendChild($root); +$head = $doc->createElement('head'); +$head = $root->appendChild($head); +$title = $doc->createElement('title'); +$title = $head->appendChild($title); +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); +echo $doc->saveHTML(); +?> +--EXPECTF-- +This is the title diff --git a/ext/dom/tests/DOMDocument_saveHTML_error1.phpt b/ext/dom/tests/DOMDocument_saveHTML_error1.phpt new file mode 100644 index 0000000000..78718de8e7 --- /dev/null +++ b/ext/dom/tests/DOMDocument_saveHTML_error1.phpt @@ -0,0 +1,24 @@ +--TEST-- +DOMDocument::saveHTML() should fail if a parameter is given +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +createElement('html'); +$root = $doc->appendChild($root); +$head = $doc->createElement('head'); +$head = $root->appendChild($head); +$title = $doc->createElement('title'); +$title = $head->appendChild($title); +$text = $doc->createTextNode('This is the title'); +$text = $title->appendChild($text); +echo $doc->saveHTML(true); +?> +--EXPECTF-- +Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in %s on line %d diff --git a/ext/dom/tests/DOMDocument_saveHTML_error2.phpt b/ext/dom/tests/DOMDocument_saveHTML_error2.phpt new file mode 100644 index 0000000000..614605b34a --- /dev/null +++ b/ext/dom/tests/DOMDocument_saveHTML_error2.phpt @@ -0,0 +1,15 @@ +--TEST-- +DOMDocument::saveHTML() should fail if called statically +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Non-static method DOMDocument::saveHTML() cannot be called statically in %s on line %d diff --git a/ext/dom/tests/DOMDocument_validate_basic.phpt b/ext/dom/tests/DOMDocument_validate_basic.phpt new file mode 100644 index 0000000000..7c0eec8ddd --- /dev/null +++ b/ext/dom/tests/DOMDocument_validate_basic.phpt @@ -0,0 +1,31 @@ +--TEST-- +DOMDocument::validate() should validate an internal DTD declaration +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- + + + + + + +]> + +Tove +Jani +Reminder +Don't forget me this weekend +"; +$dom = new DOMDocument('1.0'); +$dom->loadXML($xml); +var_dump($dom->validate()); +?> +--EXPECTF-- +bool(true) diff --git a/ext/dom/tests/DOMDocument_validate_error1.phpt b/ext/dom/tests/DOMDocument_validate_error1.phpt new file mode 100644 index 0000000000..8e1e72fe0f --- /dev/null +++ b/ext/dom/tests/DOMDocument_validate_error1.phpt @@ -0,0 +1,16 @@ +--TEST-- +DOMDocument::validate() should fail if any parameter is given +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +validate(true); +?> +--EXPECTF-- +Warning: DOMDocument::validate() expects exactly 0 parameters, 1 given in %s on line %d diff --git a/ext/dom/tests/DOMDocument_validate_error2.phpt b/ext/dom/tests/DOMDocument_validate_error2.phpt new file mode 100644 index 0000000000..fe7e4fc9d9 --- /dev/null +++ b/ext/dom/tests/DOMDocument_validate_error2.phpt @@ -0,0 +1,15 @@ +--TEST-- +DOMDocument::validate() should fail if called statically +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Non-static method DOMDocument::validate() cannot be called statically in %s on line %d diff --git a/ext/dom/tests/DOMDocument_validate_external_dtd.phpt b/ext/dom/tests/DOMDocument_validate_external_dtd.phpt new file mode 100644 index 0000000000..51a044c54a --- /dev/null +++ b/ext/dom/tests/DOMDocument_validate_external_dtd.phpt @@ -0,0 +1,19 @@ +--TEST-- +DOMDocument::validate() should validate an external DTD declaration +--CREDITS-- +Knut Urdalen +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- + +--FILE-- +load(dirname(__FILE__).'/dom.xml'); +var_dump($dom->validate()); +?> +--EXPECTF-- +bool(true) -- 2.40.0