]> granicus.if.org Git - php/commitdiff
- MFH: New tests (NorwayUG testfest)
authorFelipe Pena <felipe@php.net>
Thu, 2 Jul 2009 00:04:52 +0000 (00:04 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 2 Jul 2009 00:04:52 +0000 (00:04 +0000)
13 files changed:
ext/dom/tests/DOMDocument_createEntityReference_basic.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_saveHTMLFile_error1.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_saveHTMLFile_formatOutput.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_saveHTML_basic.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_saveHTML_error1.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_saveHTML_error2.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_validate_basic.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_validate_error1.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_validate_error2.phpt [new file with mode: 0644]
ext/dom/tests/DOMDocument_validate_external_dtd.phpt [new file with mode: 0644]

diff --git a/ext/dom/tests/DOMDocument_createEntityReference_basic.phpt b/ext/dom/tests/DOMDocument_createEntityReference_basic.phpt
new file mode 100644 (file)
index 0000000..4f4ddf1
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+DOMDocument::createEntityReference() should create a new entity reference node
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+$dom = new DOMDocument('1.0');
+$ref = $dom->createEntityReference('nbsp');
+$dom->appendChild($ref);
+echo $dom->saveXML();
+?>
+--EXPECTF--
+<?xml version="1.0"?>
+&nbsp;
diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt
new file mode 100644 (file)
index 0000000..dd0824b
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+DOMDocument::saveHTMLFile() should dump the internal document into a file using HTML formatting
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+$filename = dirname(__FILE__)."/tmp_savehtmlfile".time().".html";
+$doc = new DOMDocument('1.0');
+$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(126)
+<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>This is the title</title></head></html>
diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_error1.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_error1.phpt
new file mode 100644 (file)
index 0000000..d4dfbe8
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+DOMDocument::saveHTMLFile() should fail if no parameter is given
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+?>
+--FILE--
+<?php
+$doc = new DOMDocument('1.0');
+$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);
+$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 (file)
index 0000000..33e07c6
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+DOMDocument::saveHTMLFile() should fail if called statically
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+DOMDocument::saveHTMLFile();
+?>
+--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 (file)
index 0000000..5aece37
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+DOMDocument::saveHTMLFile() should format output on demand
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+$filename = dirname(__FILE__)."/tmp_savehtmlfile".time().".html";
+$doc = new DOMDocument('1.0');
+$doc->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)
+<html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>This is the title</title>
+</head></html>
diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt
new file mode 100644 (file)
index 0000000..d5c6a79
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+DOMDocument::saveHTMLFile() should fail with invalid filename
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+$filename = null;
+$doc = new DOMDocument('1.0');
+$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);
+?>
+--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 (file)
index 0000000..76f1ed0
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+DOMDocument::saveHTML() should dump the internal document into a string using HTML formatting 
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+$doc = new DOMDocument('1.0');
+$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);
+echo $doc->saveHTML();
+?>
+--EXPECTF--
+<html><head><title>This is the title</title></head></html>
diff --git a/ext/dom/tests/DOMDocument_saveHTML_error1.phpt b/ext/dom/tests/DOMDocument_saveHTML_error1.phpt
new file mode 100644 (file)
index 0000000..78718de
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+DOMDocument::saveHTML() should fail if a parameter is given
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+?>
+--FILE--
+<?php
+$doc = new DOMDocument('1.0');
+$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);
+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 (file)
index 0000000..614605b
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+DOMDocument::saveHTML() should fail if called statically
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+DOMDocument::saveHTML(true);
+?>
+--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 (file)
index 0000000..7c0eec8
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+DOMDocument::validate() should validate an internal DTD declaration
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+$xml = "<?xml version=\"1.0\"?>
+<!DOCTYPE note [
+<!ELEMENT note (to,from,heading,body)>
+<!ELEMENT to (#PCDATA)>
+<!ELEMENT from (#PCDATA)>
+<!ELEMENT heading (#PCDATA)>
+<!ELEMENT body (#PCDATA)>
+]>
+<note>
+<to>Tove</to>
+<from>Jani</from>
+<heading>Reminder</heading>
+<body>Don't forget me this weekend</body>
+</note>";
+$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 (file)
index 0000000..8e1e72f
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+DOMDocument::validate() should fail if any parameter is given
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+$dom = new DOMDocument('1.0');
+$dom->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 (file)
index 0000000..fe7e4fc
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+DOMDocument::validate() should fail if called statically
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+DOMDocument::validate();
+?>
+--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 (file)
index 0000000..51a044c
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+DOMDocument::validate() should validate an external DTD declaration
+--CREDITS--
+Knut Urdalen <knut@php.net>
+#PHPTestFest2009 Norway 2009-06-09 \o/
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) .'/skipif.inc';
+?>
+--FILE--
+<?php
+// reusing existing xml: http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/dom.xml?view=co&content-type=text%2Fplain
+// reusing existing dtd: http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/dom.ent?view=co&content-type=text%2Fplain
+$dom = new DOMDocument('1.0');
+$dom->load(dirname(__FILE__).'/dom.xml');
+var_dump($dom->validate());
+?>
+--EXPECTF--
+bool(true)