import zend libxml tests

only 1 good test? *sigh*
Esse commit está contido em:
Paul Tarjan
2013-04-22 18:29:10 -07:00
commit de Sara Golemon
commit 8d15db5860
23 arquivos alterados com 421 adições e 1 exclusões
+14
Ver Arquivo
@@ -0,0 +1,14 @@
<?php
var_dump(libxml_use_internal_errors(false));
var_dump(libxml_use_internal_errors(true));
var_dump(libxml_use_internal_errors());
var_dump(libxml_use_internal_errors(new stdclass));
var_dump(libxml_get_errors());
var_dump(libxml_get_last_error());
var_dump(libxml_clear_errors());
echo "Done\n";
?>
@@ -0,0 +1,10 @@
bool(false)
bool(false)
bool(true)
HipHop Warning: %a
NULL
array(0) {
}
bool(false)
NULL
Done
+56
Ver Arquivo
@@ -0,0 +1,56 @@
<?php
var_dump(libxml_use_internal_errors(true));
$xmlstr = <<< XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<titles>PHP: Behind the Parser</title>
</movie>
</movies>
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";
?>
@@ -0,0 +1,25 @@
bool(false)
<titles>PHP: Behind the Parser</title>
%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
+23
Ver Arquivo
@@ -0,0 +1,23 @@
<?php
$ctxs = array(
NULL,
'bogus',
123,
new stdclass,
array('a'),
stream_context_create(),
stream_context_create(array('file')),
stream_context_create(array('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";
?>
@@ -0,0 +1,23 @@
HipHop Warning: %a
HipHop Warning: %a
NULL
bool(true)
HipHop Warning: %a
NULL
bool(true)
HipHop Warning: %a
NULL
bool(true)
HipHop Warning: %a
NULL
bool(true)
HipHop Warning: %a
NULL
bool(true)
NULL
bool(true)
NULL
bool(true)
NULL
bool(true)
Done
+23
Ver Arquivo
@@ -0,0 +1,23 @@
<?php
$xml = <<<EOXML
<root><child xml:id="id1">baz</child></root>
EOXML;
function remove_node($doc) {
$node = $doc->getElementById( 'id1' );
print 'Deleting Node: '.$node->nodeName."\n";
$node->parentNode->removeChild( $node );
}
$doc = new DOMDocument();
$doc->loadXML($xml);
remove_node($doc);
$node = $doc->getElementById( 'id1' );
if ($node) {
print 'Found Node: '.$node->nodeName."\n";
}
$root = $doc->documentElement;
print 'Root Node: '.$root->nodeName."\n";
?>
@@ -0,0 +1,2 @@
Deleting Node: child
Root Node: root
+29
Ver Arquivo
@@ -0,0 +1,29 @@
<?php
class TestWrapper {
function stream_open($path, $mode, $options, &$opened_path)
{
if ($this->context)
print_r(stream_context_get_options($this->context));
return false;
}
function url_stat($path, $flags)
{
return array();
}
}
stream_wrapper_register("test", "TestWrapper")
or die("Failed to register protocol");
$ctx1 = stream_context_create(array('test'=>array('test'=>'test 1')));
$ctx2 = stream_context_create(array('test'=>array('test'=>'test 2')));
stream_context_set_default(stream_context_get_options($ctx1));
@simplexml_load_file('test://sdfsdf');
libxml_set_streams_context($ctx2);
@simplexml_load_file('test://sdfsdf');
@@ -0,0 +1,16 @@
Array
(
[test] => Array
(
[test] => test 1
)
)
Array
(
[test] => Array
(
[test] => test 2
)
)
+6
Ver Arquivo
@@ -0,0 +1,6 @@
<?php
$fp = fopen("php://input", "r");
libxml_set_streams_context($fp);
libxml_set_streams_context("a");
echo "okey";
?>
@@ -0,0 +1,2 @@
HipHop Warning: %a
okey
@@ -0,0 +1,27 @@
<?php
$xml = <<<XML
<!DOCTYPE foo PUBLIC "-//FOO/BAR" "http://example.com/foobar">
<foo>bar</foo>
XML;
$dtd = <<<DTD
<!ELEMENT foo (#PCDATA)>
DTD;
libxml_set_external_entity_loader(
function ($public, $system, $context) use($dtd){
var_dump($public);
var_dump($system);
var_dump($context);
$f = fopen("php://temp", "r+");
fwrite($f, $dtd);
rewind($f);
return $f;
}
);
$dd = new DOMDocument;
$r = $dd->loadXML($xml);
var_dump($dd->validate());
echo "Done.\n";
@@ -0,0 +1,14 @@
string(10) "-//FOO/BAR"
string(25) "http://example.com/foobar"
array(4) {
["directory"]=>
NULL
["intSubName"]=>
NULL
["extSubURI"]=>
NULL
["extSubSystem"]=>
NULL
}
bool(true)
Done.
@@ -0,0 +1,17 @@
<?php
$xml = <<<XML
<!DOCTYPE foo PUBLIC "-//FOO/BAR" "http://example.com/foobar">
<foo>bar</foo>
XML;
$dd = new DOMDocument;
$r = $dd->loadXML($xml);
var_dump(libxml_set_external_entity_loader([]));
var_dump(libxml_set_external_entity_loader());
var_dump(libxml_set_external_entity_loader(function() {}, 2));
var_dump(libxml_set_external_entity_loader(function($a, $b, $c, $d) {}));
var_dump($dd->validate());
echo "Done.\n";
@@ -0,0 +1,11 @@
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
HipHop Warning: %a
NULL
bool(true)
HipHop Warning: %a
HipHop Warning: %a
bool(false)
Done.
@@ -0,0 +1,39 @@
<?php
chdir(__DIR__);
$xml = <<<XML
<!DOCTYPE foo PUBLIC "-//FOO/BAR" "http://example.com/foobar">
<foo>bar&fooz;</foo>
XML;
$dtd = <<<DTD
<!ELEMENT foo (#PCDATA)>
<!ENTITY % fooentity PUBLIC
"-//FOO/ENTITY"
"fooentity.ent">
%fooentity;
DTD;
$entity = <<<ENT
<!ENTITY fooz "baz">
ENT;
libxml_set_external_entity_loader(
function ($public, $system, $context) use($dtd,$entity){
static $first = true;
var_dump($public);
var_dump($system);
var_dump($context);
$f = fopen("php://temp", "r+");
fwrite($f, $first ? $dtd : $entity);
$first = false;
rewind($f);
return $f;
}
);
$dd = new DOMDocument;
$dd->resolveExternals = true;
$r = $dd->loadXML($xml);
var_dump($dd->validate());
echo "Done.\n";
@@ -0,0 +1,26 @@
string(10) "-//FOO/BAR"
string(25) "http://example.com/foobar"
array(4) {
["directory"]=>
string(%d) "%s"
["intSubName"]=>
string(3) "foo"
["extSubURI"]=>
string(25) "http://example.com/foobar"
["extSubSystem"]=>
string(10) "-//FOO/BAR"
}
string(13) "-//FOO/ENTITY"
string(32) "http://example.com/fooentity.ent"
array(4) {
["directory"]=>
string(%d) "%s"
["intSubName"]=>
string(3) "foo"
["extSubURI"]=>
string(25) "http://example.com/foobar"
["extSubSystem"]=>
string(10) "-//FOO/BAR"
}
bool(true)
Done.
@@ -0,0 +1,30 @@
<?php
chdir(__DIR__);
$xml = <<<XML
<!DOCTYPE foo PUBLIC "-//FOO/BAR" "foobar.dtd">
<foo>bar</foo>
XML;
$dtd = <<<DTD
<!ELEMENT foo (#PCDATA)>
DTD;
libxml_set_external_entity_loader(
function ($public, $system, $context) {
var_dump($public,$system);
return null;
}
);
$dd = new DOMDocument;
$r = $dd->loadXML($xml);
var_dump($dd->validate());
libxml_set_external_entity_loader(NULL);
file_put_contents(__DIR__ . "/foobar.dtd", $dtd);
var_dump($dd->validate());
echo "Done.\n";
<?php
@unlink(__DIR__ . "/foobar.dtd");
@@ -0,0 +1,6 @@
string(10) "-//FOO/BAR"
string(%d) "%sfoobar.dtd"
HipHop Warning: %a
bool(false)
bool(true)
Done.
+19
Ver Arquivo
@@ -0,0 +1,19 @@
<?php
var_dump(libxml_use_internal_errors(true));
$xmlstr = <<< XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<titles>PHP: Behind the Parser</title>
</movie>
</movies>
XML;
simplexml_load_string($xmlstr);
// test memleaks here
var_dump(libxml_use_internal_errors(false));
echo "Done\n";
?>
@@ -0,0 +1,3 @@
bool(false)
bool(true)
Done
-1
Ver Arquivo
@@ -106,7 +106,6 @@ no_import = (
'/ext/imap',
'/ext/intl',
'/ext/ldap',
'/ext/libxml',
'/ext/mbstring',
'/ext/standard',
'/ext/mcrypt',