Debian Codegraph @

t/03_kk_attean.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 # tests from KjetilK
4
5 use strict;
6 use Test::More;
7 use Test::Modern;
8
9 BEGIN {
10 use_ok('Attean') or BAIL_OUT "Attean required for tests";
11 use_ok('RDF::RDFa::Generator');
12 }
13
14 use Attean::RDF qw(iri);
15
16 my $store = Attean->get_store('Memory')->new();
17 my $parser = Attean->get_parser('Turtle')->new(base=>'http://example.org/');
18
19 my $iter = $parser->parse_iter_from_bytes('<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 ] .');
20
21 $store->add_iter($iter->as_quads(iri('http://graph.invalid/')));
22 my $model = Attean::QuadModel->new( store => $store );
23
24
25 subtest 'Default generator' => sub {
26 ok(my $document = RDF::RDFa::Generator->new->create_document($model), 'Assignment OK');
27 my $string = tests($document);
28 like($string, qr|<link|, 'link element just local part');
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
34 subtest 'Hidden generator' => sub {
35 ok(my $document = RDF::RDFa::Generator::HTML::Hidden->new->create_document($model), 'Assignment OK');
36 my $string = tests($document);
37 like($string, qr|<body>\s?<i|, 'i element just local part');
38 like($string, qr|resource="http://example.org/Bar"|, 'Object present');
39 like($string, qr|property="ex:title" content="Dahut"|, 'Literals OK');
40 };
41
42 subtest 'Pretty generator' => sub {
43 ok(my $document = RDF::RDFa::Generator::HTML::Pretty->new->create_document($model), 'Assignment OK');
44 my $string = tests($document);
45 like($string, qr|<dd property="ex:title" class="typed-literal" xml:lang="fr" datatype="rdf:langString">Dahut</dd>|, 'Language Literal OK');
46 like($string, qr|<dd property="ex:else" class="typed-literal" datatype="xsd:string">Foo</dd>|, '"Plain" Literal OK');
47 };
48
49 subtest 'Pretty generator with interlink' => sub {
50 ok(my $document = RDF::RDFa::Generator::HTML::Pretty->new()->create_document($model, interlink => 1, id_prefix => 'test'), 'Assignment OK');
51 my $string = tests($document);
52 like($string, qr|<main>\s?<div|, 'div element just local part');
53 like($string, qr|<dd property="ex:title" class="typed-literal" xml:lang="fr" datatype="rdf:langString">Dahut</dd>|, 'Literals OK');
54 };
55
56 subtest 'Pretty generator with Note' => sub {
57 ok(my $note = RDF::RDFa::Generator::HTML::Pretty::Note->new(iri('http://example.org/foo'), 'This is a Note'), 'Note creation OK');
58 ok(my $document = RDF::RDFa::Generator::HTML::Pretty->new->create_document($model, notes => [$note]), 'Assignment OK');
59 my $string = tests($document);
60 like($string, qr|<aside>|, 'aside element found');
61 like($string, qr|This is a Note|, 'Note text found');
62 };
63
64
65 sub tests {
66 my $document = shift;
67 isa_ok($document, 'XML::LibXML::Document');
68 my $string = $document->toString;
69 like($string, qr|about="http://example.org/foo"|, 'Subject URI present');
70 like($string, qr|rel="rdf:type"|, 'Type predicate present');
71 like($string, qr|property="ex:pi"|, 'pi predicate present');
72 like($string, qr|3\.14|, 'pi decimal present');
73 like($string, qr|datatype="xsd:decimal"|, 'pi decimal datatype present');
74 return $string;
75 }
76 done_testing();