1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
# Tests that base URLs are working OK.
use Test::More tests => 14;
BEGIN { use_ok('RDF::RDFa::Parser') };
my ($parser, $model);
my $xhtml = <<EOF;
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ex="http://example.com/ns#"
xml:lang="en">
<head>
<base href="http://example.com/html" />
</head>
<body xml:base="http://example.com/xml">
<div about="#about" rel="ex:test" resource="#resource" />
<div src="#src" rel="ex:test" href="#href" />
</body>
</html>
EOF
my $config = RDF::RDFa::Parser::Config->new('xhtml', '1.0');
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/perl', $config);
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/html#about'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/html#resource'),
),
"Default behaviour respects BASE element - about and resource.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/html#src'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/html#href'),
),
"Default behaviour respects BASE element - src and href.");
$config = RDF::RDFa::Parser::Config->new('xhtml', '1.0', xhtml_base=>0);
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/perl', $config);
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/perl#about'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/perl#resource'),
),
"Can switch off BASE element - about and resource.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/perl#src'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/perl#href'),
),
"Can switch off BASE element - src and href.");
$config = RDF::RDFa::Parser::Config->new('xhtml', '1.0', xml_base=>1);
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/perl', $config);
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/xml#about'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/xml#resource'),
),
"Can switch on xml:base attribute selectively - about and resource.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/html#src'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/html#href'),
),
"Can switch on xml:base attribute selectively - src and href don't use it.");
$config = RDF::RDFa::Parser::Config->new('xhtml', '1.0', xml_base=>2);
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/perl', $config);
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/xml#about'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/xml#resource'),
),
"Can switch on xml:base attribute completely - about and resource.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/xml#src'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/xml#href'),
),
"Can switch on xml:base attribute completely - src and href.");
$config = RDF::RDFa::Parser::Config->new('xhtml', '1.0', xml_base=>1,xhtml_base=>0);
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/perl', $config);
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/xml#about'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/xml#resource'),
),
"Can switch on xml:base attribute and switch off BASE element at the same time - about and resource.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/perl#src'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/perl#href'),
),
"Can switch on xml:base attribute and switch off BASE element at the same time - src and href.");
$xhtml = <<EOF;
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ex="http://example.com/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xml:lang="en">
<head>
<base href="http://example.com/html" />
</head>
<body xml:base="http://example.com/xml">
<rdf:RDF>
<rdf:Description rdf:about="#rdfabout">
<ex:foo rdf:resource="#rdfresource" />
</rdf:Description>
</rdf:RDF>
</body>
</html>
EOF
$config = RDF::RDFa::Parser::Config->new('xhtml', '1.0', xml_base=>0,embedded_rdfxml=>1);
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/perl', $config);
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/xml#rdfabout'),
RDF::Trine::Node::Resource->new('http://example.com/ns#foo'),
RDF::Trine::Node::Resource->new('http://example.com/xml#rdfresource'),
),
"RDF/XML respects xml:base always.");
$xhtml = <<EOF;
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ex="http://example.com/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xml:lang="en">
<head>
<base href="http://example.com/html" />
</head>
<body>
<rdf:RDF>
<rdf:Description rdf:about="#rdfabout">
<ex:foo rdf:resource="#rdfresource" />
</rdf:Description>
</rdf:RDF>
</body>
</html>
EOF
$config = RDF::RDFa::Parser::Config->new('xhtml', '1.0', xml_base=>0,xhtml_base=>2,embedded_rdfxml=>1);
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/perl', $config);
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/html#rdfabout'),
RDF::Trine::Node::Resource->new('http://example.com/ns#foo'),
RDF::Trine::Node::Resource->new('http://example.com/html#rdfresource'),
),
"RDF/XML respects BASE element if you're crazy.");
$xhtml = <<EOF;
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ex="http://example.com/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xml:lang="en">
<head>
<base href="http://example.com/html" />
</head>
<body xml:base="http://example.com/xml-rubbish">
<div xml:base="http://example.com/xml">
<div about="#about" rel="ex:test" resource="#resource" />
</div>
</body>
</html>
EOF
$config = RDF::RDFa::Parser::Config->new('xhtml', '1.0', xml_base=>1);
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/perl', {xml_base=>1});
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/xml#about'),
RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
RDF::Trine::Node::Resource->new('http://example.com/xml#resource'),
),
"Nesting xml:base works.");
|