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
|
# Tests that base URLs are working OK.
use Test::More tests => 12;
BEGIN { use_ok('RDF::RDFa::Parser') };
my $xhtml_rdfa_10 = RDF::RDFa::Parser::Config->new('xhtml','1.0');
my ($parser, $model);
my $xhtml = <<EOF;
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ex="http://example.com/ns#"
xmlns:http="http://example.com/http#"
xml:lang="en">
<body>
<div about="[ex:r1/foo]" rel="ex:test" resource="[ex:test]" />
<div about="[ex:r2]" rel="ex:r2/foo" resource="[ex:test]" />
<div about="[ex:r3]" rel=":TEST" resource="[ex:test]" />
<div about="[ex:r4]" rel="ex:r4" href="[ex:r4]" />
<div about="[ex:r5]" rel="ex:r5" resource="[ex:r5]" />
<div about="[ex:r6]" rel="arkansas" resource="[ex:r6]" />
<div about="http://example.net/1" rel="ex:test" resource="[ex:test]" />
<div about="[http://example.net/2]" rel="ex:test" resource="[ex:test]" />
</body>
</html>
EOF
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/', $xhtml_rdfa_10);
$parser->consume;
$model = $parser->graph;
#my $iter = $model->as_stream;
#while (my $st = $iter->next)
#{
# diag $st->as_string;
#}
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/ns#r1/foo'),
undef,
undef,
),
"Supports non-QName characters in SafeCURIEs.");
ok($model->count_statements(
undef,
RDF::Trine::Node::Resource->new('http://example.com/ns#r2/foo'),
undef,
),
"Supports non-QName characters in CURIEs.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/ns#r3'),
RDF::Trine::Node::Resource->new('http://www.w3.org/1999/xhtml/vocab#TEST'),
undef,
),
"Default prefix works.");
ok(!$model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/ns#r4'),
RDF::Trine::Node::Resource->new('http://example.com/ns#r4'),
RDF::Trine::Node::Resource->new('http://example.com/ns#r4'),
),
"Safe CURIEs don't work in \@href.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/ns#r5'),
RDF::Trine::Node::Resource->new('http://example.com/ns#r5'),
RDF::Trine::Node::Resource->new('http://example.com/ns#r5'),
),
"Safe CURIEs work in \@resource.");
ok(!$model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/ns#r6'),
undef,
RDF::Trine::Node::Resource->new('http://example.com/ns#r6'),
),
"Nonsense keywords ignored.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.net/1'),
undef,
undef,
),
"http-URI recognised.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/http#//example.net/2'),
undef,
undef,
),
"http-URI-looking CURIE recognised.");
$xhtml = <<EOF;
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ex="http://example.com/ns#"
xmlns:http="http://example.com/http#"
xml:lang="en">
<body>
<div about="[ex:r1]" rel="http://example.com/ https://example.com/" resource="[ex:r1]" />
</body>
</html>
EOF
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/', $xhtml_rdfa_10);
$parser->consume;
$model = $parser->graph;
ok(1==$model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/ns#r1'),
undef,
RDF::Trine::Node::Resource->new('http://example.com/ns#r1'),
),
"Undefined CURIE ignored.");
$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/', {'full_uris'=>1});
$parser->consume;
$model = $parser->graph;
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/ns#r1'),
RDF::Trine::Node::Resource->new('http://example.com/http#//example.com/'),
RDF::Trine::Node::Resource->new('http://example.com/ns#r1'),
),
"http-URI-looking CURIE recognised, even if full URIs enabled.");
ok($model->count_statements(
RDF::Trine::Node::Resource->new('http://example.com/ns#r1'),
RDF::Trine::Node::Resource->new('https://example.com/'),
RDF::Trine::Node::Resource->new('http://example.com/ns#r1'),
),
"Full URI recognised.");
|