Debian Codegraph @

t/44extent.t

raw
1 # Test file created outside of h2xs framework.
2 # Run this like so: `perl 44extent.t'
3 # [email protected] 2009/09/24 13:18:43
4
5 #########################
6
7 # change 'tests => 1' to 'tests => last_test_to_print';
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 use XML::LibXML;
15
16 use IO::Handle;
17
18 STDOUT->autoflush(1);
19 STDERR->autoflush(1);
20
21 if (XML::LibXML::LIBXML_VERSION() < 20627)
22 {
23 plan skip_all => "skipping for libxml2 < 2.6.27";
24 }
25 else
26 {
27 plan tests => 7;
28 }
29
30 my $parser = XML::LibXML->new({
31 expand_entities => 1,
32 ext_ent_handler => \&handler,
33 });
34
35 sub handler {
36 return join(",",@_);
37 }
38
39 my $xml = <<'EOF';
40 <?xml version="1.0"?>
41 <!DOCTYPE foo [
42 <!ENTITY a PUBLIC "//foo/bar/b" "file:/dev/null">
43 <!ENTITY b SYSTEM "file:///dev/null">
44 ]>
45 <root>
46 <a>&a;</a>
47 <b>&b;</b>
48 </root>
49 EOF
50 my $xml_out = $xml;
51 $xml_out =~ s{&a;}{file:/dev/null,//foo/bar/b};
52 $xml_out =~ s{&b;}{file:///dev/null,};
53
54 my $doc = $parser->parse_string($xml);
55
56 # TEST
57 is( $doc->toString(), $xml_out, ' TODO : Add test name' );
58
59 my $xml_out2 = $xml; $xml_out2 =~ s{&[ab];}{<!-- -->}g;
60
61 $parser->set_option( ext_ent_handler => sub { return '<!-- -->' } );
62 $doc = $parser->parse_string($xml);
63 # TEST
64 is( $doc->toString(), $xml_out2, ' TODO : Add test name' );
65
66 $parser->set_option( ext_ent_handler=>sub{ '' } );
67 $parser->set_options({
68 expand_entities => 0,
69 recover => 2,
70 });
71 $doc = $parser->parse_string($xml);
72 # TEST
73 is( $doc->toString(), $xml, ' TODO : Add test name' );
74
75 # TEST:$el=2;
76 foreach my $el ($doc->findnodes('/root/*')) {
77 # TEST*$el
78 ok ($el->hasChildNodes, ' TODO : Add test name');
79 # TEST*$el
80 ok ($el->firstChild->nodeType == XML_ENTITY_REF_NODE, ' TODO : Add test name');
81 }
82