From 38e47dd0bb4286b5ab3393130fd5bd4b82ae60a8 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Tue, 27 Jun 2006 22:43:26 +0000 Subject: [PATCH] add new tests. bump code coverage to more than 80% --- ext/libxml/tests/001.phpt | 31 ++++++++++++++ ext/libxml/tests/002.phpt | 87 +++++++++++++++++++++++++++++++++++++++ ext/libxml/tests/003.phpt | 28 +++++++++++++ ext/libxml/tests/004.phpt | 57 +++++++++++++++++++++++++ ext/libxml/tests/test.xml | 8 ++++ 5 files changed, 211 insertions(+) create mode 100644 ext/libxml/tests/001.phpt create mode 100644 ext/libxml/tests/002.phpt create mode 100644 ext/libxml/tests/003.phpt create mode 100644 ext/libxml/tests/004.phpt create mode 100644 ext/libxml/tests/test.xml diff --git a/ext/libxml/tests/001.phpt b/ext/libxml/tests/001.phpt new file mode 100644 index 0000000000..6f68cb4a86 --- /dev/null +++ b/ext/libxml/tests/001.phpt @@ -0,0 +1,31 @@ +--TEST-- +libxml_use_internal_errors() +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(false) +bool(false) +bool(true) + +Warning: libxml_use_internal_errors() expects parameter 1 to be boolean, object given in %s001.php on line 6 +NULL +array(0) { +} +bool(false) +NULL +Done diff --git a/ext/libxml/tests/002.phpt b/ext/libxml/tests/002.phpt new file mode 100644 index 0000000000..f803d7ab1b --- /dev/null +++ b/ext/libxml/tests/002.phpt @@ -0,0 +1,87 @@ +--TEST-- +libxml_get_errors() +--SKIPIF-- + +--FILE-- + + + + PHP: Behind the Parser + + +XML; + +$doc = simplexml_load_string($xmlstr); +$xml = explode("\n", $xmlstr); + +if (!$doc) { + $errors = libxml_get_errors(); + + foreach ($errors as $error) { + echo display_xml_error($error, $xml); + } + + var_dump(libxml_get_last_error()); +} + + +function display_xml_error($error, $xml) +{ + $return = $xml[$error->line - 1] . "\n"; + $return .= str_repeat('-', $error->column) . "^\n"; + + switch ($error->level) { + case LIBXML_ERR_WARNING: + $return .= "Warning $error->code: "; + break; + case LIBXML_ERR_ERROR: + $return .= "Error $error->code: "; + break; + case LIBXML_ERR_FATAL: + $return .= "Fatal Error $error->code: "; + break; + } + + $return .= trim($error->message) . "\n Line: $error->line" . "\n Column: $error->column"; + + if ($error->file) { + $return .= "\n File: $error->file"; + } + + return "$return\n\n--------------------------------------------\n\n"; +} + + +echo "Done\n"; +?> +--EXPECTF-- +bool(false) + PHP: Behind the Parser +%s +Fatal Error 76: Opening and ending tag mismatch: titles line 4 and title + Line: 4 + Column: %d + +-------------------------------------------- + +object(LibXMLError)#%d (6) { + ["level"]=> + int(3) + ["code"]=> + int(76) + ["column"]=> + int(%d) + ["message"]=> + string(57) "Opening and ending tag mismatch: titles line 4 and title +" + ["file"]=> + string(0) "" + ["line"]=> + int(4) +} +Done diff --git a/ext/libxml/tests/003.phpt b/ext/libxml/tests/003.phpt new file mode 100644 index 0000000000..dcf6c0bb65 --- /dev/null +++ b/ext/libxml/tests/003.phpt @@ -0,0 +1,28 @@ +--TEST-- +libxml_use_internal_errors() memory leaks +--SKIPIF-- + +--FILE-- + + + + PHP: Behind the Parser + + +XML; + +simplexml_load_string($xmlstr); + +// test memleaks here +var_dump(libxml_use_internal_errors(false)); + +echo "Done\n"; +?> +--EXPECTF-- +bool(false) +bool(true) +Done diff --git a/ext/libxml/tests/004.phpt b/ext/libxml/tests/004.phpt new file mode 100644 index 0000000000..f347aed615 --- /dev/null +++ b/ext/libxml/tests/004.phpt @@ -0,0 +1,57 @@ +--TEST-- +libxml_set_streams_context() +--SKIPIF-- + +--FILE-- + array('some_opt' => 'aaa'))) +); + + +foreach ($ctxs as $ctx) { + var_dump(libxml_set_streams_context($ctx)); + $dom = new DOMDocument(); + var_dump($dom->load(dirname(__FILE__).'/test.xml')); +} + +echo "Done\n"; + +?> +--EXPECTF-- +Warning: options should have the form ["wrappername"]["optionname"] = $value in %s004.php on line 10 +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL +bool(true) +NULL +bool(true) +NULL +bool(true) +Done diff --git a/ext/libxml/tests/test.xml b/ext/libxml/tests/test.xml new file mode 100644 index 0000000000..fc1d328905 --- /dev/null +++ b/ext/libxml/tests/test.xml @@ -0,0 +1,8 @@ + + + PHP made simple + + + learn PHP easily + + -- 2.50.1