Debian Codegraph @

t/serializer-rdfa.t

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/env perl
2
3 use strict;
4 use Test::More;
5 use Test::RDF;
6 use RDF::Trine qw(iri);
7
8 use_ok('RDF::Trine::Serializer');
9 use_ok('RDF::Trine::Serializer::RDFa');
10
11 use Module::Load::Conditional qw[check_install];
12
13 my $rdfpr = check_install( module => 'RDF::Prefixes');
14
15 my $testmodel = RDF::Trine::Model->temporary_model;
16 my $parser = RDF::Trine::Parser->new( 'turtle' );
17
18 my $testdata = '<http://example.org/foo> a <http://example.org/Bar> ; <http://example.org/title> "Dahut"@fr ; <http://example.org/something> [ <http://example.org/else> "Foo" ; <http://example.org/pi> 3.14 ] .';
19
20 $parser->parse_into_model('http://example.org/', $testdata, $testmodel );
21
22 subtest 'Default generator' => sub {
23 plan skip_all => 'RDF::Prefixes is not installed' unless $rdfpr;
24 ok(my $s = RDF::Trine::Serializer->new('RDFa'), 'Assignment OK');
25 isa_ok($s, 'RDF::Trine::Serializer');
26 isa_ok($s, 'RDF::Trine::Serializer::RDFa');
27 my $string = $s->serialize_model_to_string($testmodel);
28 tests($string);
29 like($string, qr|resource="http://example.org/Bar"|, 'Object present');
30 like($string, qr|property="ex:title" content="Dahut"|, 'Literals OK');
31 };
32
33 my $ns = URI::NamespaceMap->new( { ex => iri('http://example.org/') });
34
35 subtest 'Hidden generator' => sub {
36 ok(my $s = RDF::Trine::Serializer->new('RDFa', style => 'HTML::Hidden', namespacemap => $ns), 'Assignment OK');
37 isa_ok($s, 'RDF::Trine::Serializer::RDFa');
38 my $string = $s->serialize_model_to_string($testmodel);
39 tests($string);
40 like($string, qr|resource="http://example.org/Bar"|, 'Object present');
41 like($string, qr|property="ex:title" content="Dahut"|, 'Literals OK');
42 };
43
44 subtest 'Pretty generator' => sub {
45 ok(my $s = RDF::Trine::Serializer->new('RDFa', style => 'HTML::Pretty', namespacemap => $ns), 'Assignment OK');
46 isa_ok($s, 'RDF::Trine::Serializer::RDFa');
47 my $string = $s->serialize_model_to_string($testmodel);
48 tests($string);
49 like($string, qr|<dd property="ex:title" class="typed-literal" xml:lang="fr" datatype="rdf:langString">Dahut</dd>|, 'Language literals OK');
50 like($string, qr|<dd property="ex:else" class="typed-literal" datatype="xsd:string">Foo</dd>|, '"Plain" Literal OK');
51 };
52
53 subtest 'Pretty generator with interlink' => sub {
54 ok(my $s = RDF::Trine::Serializer->new('RDFa',
55 namespacemap => $ns,
56 style => 'HTML::Pretty',
57 generator_options => {interlink => 1, id_prefix => 'test'}),
58 'Assignment OK');
59 my $string = $s->serialize_model_to_string($testmodel);
60 tests($string);
61 like($string, qr|<main>\s?<div|, 'div element just local part');
62 like($string, qr|<dd property="ex:title" class="typed-literal" xml:lang="fr" datatype="rdf:langString">Dahut</dd>|, 'Literals OK');
63 };
64
65 subtest 'Pretty generator with Note' => sub {
66 ok(my $note = RDF::RDFa::Generator::HTML::Pretty::Note->new(iri('http://example.org/foo'), 'This is a Note'), 'Note creation OK');
67 ok(my $s = RDF::Trine::Serializer->new('RDFa',
68 style => 'HTML::Pretty',
69 namespacemap => $ns,
70 generator_options => {notes => [$note]}),
71 'Assignment OK');
72 my $string = $s->serialize_model_to_string($testmodel);
73 tests($string);
74 like($string, qr|<aside>|, 'aside element found');
75 like($string, qr|This is a Note|, 'Note text found');
76 };
77
78
79 sub tests {
80 my $string = shift;
81 is_valid_rdf($string, 'rdfa', 'RDFa is syntactically valid');
82 like($string, qr|about="http://example.org/foo"|, 'Subject URI present');
83 like($string, qr|rel="rdf:type"|, 'Type predicate present');
84 like($string, qr|property="ex:pi"|, 'pi predicate present');
85 like($string, qr|3\.14|, 'pi decimal present');
86 }
87
88
89 done_testing;