Annotation of embedaddon/php/ext/libxml/tests/libxml_set_external_entity_loader_variation1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: libxml_set_external_entity_loader() variation: resolve externals and entities
! 3: --SKIPIF--
! 4: <?php if (!extension_loaded('dom')) die('skip'); ?>
! 5: --FILE--
! 6: <?php
! 7: chdir(__DIR__);
! 8: $xml = <<<XML
! 9: <!DOCTYPE foo PUBLIC "-//FOO/BAR" "http://example.com/foobar">
! 10: <foo>bar&fooz;</foo>
! 11: XML;
! 12:
! 13: $dtd = <<<DTD
! 14: <!ELEMENT foo (#PCDATA)>
! 15: <!ENTITY % fooentity PUBLIC
! 16: "-//FOO/ENTITY"
! 17: "fooentity.ent">
! 18: %fooentity;
! 19: DTD;
! 20:
! 21: $entity = <<<ENT
! 22: <!ENTITY fooz "baz">
! 23: ENT;
! 24:
! 25: libxml_set_external_entity_loader(
! 26: function ($public, $system, $context) use($dtd,$entity){
! 27: static $first = true;
! 28: var_dump($public);
! 29: var_dump($system);
! 30: var_dump($context);
! 31: $f = fopen("php://temp", "r+");
! 32: fwrite($f, $first ? $dtd : $entity);
! 33: $first = false;
! 34: rewind($f);
! 35: return $f;
! 36: }
! 37: );
! 38:
! 39: $dd = new DOMDocument;
! 40: $dd->resolveExternals = true;
! 41: $r = $dd->loadXML($xml);
! 42: var_dump($dd->validate());
! 43:
! 44: echo "Done.\n";
! 45:
! 46: --EXPECTF--
! 47: string(10) "-//FOO/BAR"
! 48: string(25) "http://example.com/foobar"
! 49: array(4) {
! 50: ["directory"]=>
! 51: string(%d) "%s"
! 52: ["intSubName"]=>
! 53: string(3) "foo"
! 54: ["extSubURI"]=>
! 55: string(25) "http://example.com/foobar"
! 56: ["extSubSystem"]=>
! 57: string(10) "-//FOO/BAR"
! 58: }
! 59: string(13) "-//FOO/ENTITY"
! 60: string(32) "http://example.com/fooentity.ent"
! 61: array(4) {
! 62: ["directory"]=>
! 63: string(%d) "%s"
! 64: ["intSubName"]=>
! 65: string(3) "foo"
! 66: ["extSubURI"]=>
! 67: string(25) "http://example.com/foobar"
! 68: ["extSubSystem"]=>
! 69: string(10) "-//FOO/BAR"
! 70: }
! 71: bool(true)
! 72: Done.
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>