File: 07rdfxml.t

package info (click to toggle)
librdf-rdfa-parser-perl 1.097-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,948 kB
  • sloc: perl: 6,582; makefile: 7; xml: 6; sh: 1
file content (96 lines) | stat: -rw-r--r-- 2,874 bytes parent folder | download | duplicates (2)
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
# Tests that lang tags work properly

use Test::More tests => 10;
BEGIN { use_ok('RDF::RDFa::Parser') };

my $xhtml = <<EOF;
<html xmlns:ex="http://example.com/ns#"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns="http://www.w3.org/1999/xhtml"
	xml:lang="en-gb">
	<body>
		<div about="[ex:r1]" property="ex:test" datatype="rdf:XMLLiteral">
			<!-- This is just a literal. Should not parse the RDF inside here. -->
			<rdf:RDF>
				<rdf:Description rdf:about="http://example.com/ns#r2">
					<ex:test rdf:resource="http://example.com/ns#test" />
				</rdf:Description>
			</rdf:RDF>
		</div>
		<rdf:RDF>
			<rdf:Description rdf:about="http://example.com/ns#r3">
				<ex:test rdf:resource="http://example.com/ns#test" />
				<ex:literal>Foo</ex:literal>
			</rdf:Description>
		</rdf:RDF>
	</body>
</html>
EOF

my $parser = RDF::RDFa::Parser->new(
	$xhtml,
	'http://example.com/',
	RDF::RDFa::Parser::Config->new(xhtml => '1.0', embedded_rdfxml=>1),
	);
$parser->consume;

my $model;
ok($model = $parser->graph, "Graph retrieved");

ok(!$model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r2'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		),
	"RDF/XML inside rdf:XMLLiterals is ignored.");

ok($model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r3'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		),
	"Embedded RDF/XML is parsed.");

ok($model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r3'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#literal'),
		RDF::Trine::Node::Literal->new('Foo', 'en-gb'),
		),
	"Language tags correctly inherited.");

$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/', {embedded_rdfxml=>2});
$parser->consume;

ok($model = $parser->graph, "Alternative graph retrieved");

ok(!$model->count_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r3'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#test'),
		),
	"Embedded RDF/XML is skipped.");

$parser = RDF::RDFa::Parser->new($xhtml, 'http://example.com/',
	{embedded_rdfxml=>1, graph=>1}
	);
$parser->consume;

$model = $parser->graph;

my $iter = $model->get_statements(
		RDF::Trine::Node::Resource->new('http://example.com/ns#r3'),
		RDF::Trine::Node::Resource->new('http://example.com/ns#literal'),
		RDF::Trine::Node::Literal->new('Foo', 'en-gb'),
		undef,
		);
my @r;
while (my $st = $iter->next)
{
	push @r, $st;
}
ok(@r,
	"Named graphs work with RDF/XML - I.");
ok(!$r[1],
	"Named graphs work with RDF/XML - II.");
ok($r[0]->context->is_blank,
	"Named graphs work with RDF/XML - III.");