Lines 16-22
Link Here
|
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use Test::More tests => 3; |
19 |
use Test::More tests => 5; |
|
|
20 |
use RDF::Trine; |
21 |
use JSON; |
20 |
|
22 |
|
21 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
22 |
|
24 |
|
Lines 31-33
is($well_formed_uri,'http://koha-community.org/bib/1','Successfully minted a RDF
Link Here
|
31 |
t::lib::Mocks::mock_preference('OPACBaseURL', 'koha-community.org'); |
33 |
t::lib::Mocks::mock_preference('OPACBaseURL', 'koha-community.org'); |
32 |
my $malformed_uri = $rdf->mint_uri('biblio',2); |
34 |
my $malformed_uri = $rdf->mint_uri('biblio',2); |
33 |
is($malformed_uri,undef,"Didn't mint URI due to missing URI scheme"); |
35 |
is($malformed_uri,undef,"Didn't mint URI due to missing URI scheme"); |
34 |
- |
36 |
|
|
|
37 |
|
38 |
subtest 'Create and delete named graphs' => sub { |
39 |
plan tests => 3; |
40 |
my $store = RDF::Trine::Store::Memory->new(); |
41 |
my $model = RDF::Trine::Model->new($store); |
42 |
|
43 |
my $context = RDF::Trine::Node::Resource->new("http://koha-community/graph/1"); |
44 |
my $subject = RDF::Trine::Node::Resource->new("http://koha-community/resource/1"); |
45 |
my $predicate = RDF::Trine::Node::Resource->new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); |
46 |
my $object = RDF::Trine::Node::Resource->new("http://koha-community/vocab/record"); |
47 |
my $triple = RDF::Trine::Statement->new($subject,$predicate,$object); |
48 |
my $quad = RDF::Trine::Statement::Quad->new($subject,$predicate,$object,undef); |
49 |
my $stream = [ |
50 |
$quad, |
51 |
]; |
52 |
my $iterator = RDF::Trine::Iterator::Graph->new($stream); |
53 |
|
54 |
#NOTE: Add a triple to the default graph |
55 |
$model->add_statement($triple); |
56 |
|
57 |
#NOTE: Add a triple to a named graph (ie add a quad to the triplestore) separate from the |
58 |
#named graph we're going to make with the Koha::RDF method |
59 |
if (my $clone = $quad->clone){ |
60 |
my $separate_context = RDF::Trine::Node::Resource->new("http://koha-community/graph/keep"); |
61 |
$clone->context($separate_context); |
62 |
$model->add_statement($clone); |
63 |
} |
64 |
|
65 |
is($model->size,2,"2 statements in model (in default graph and a named graph)"); |
66 |
$rdf->AddNamedGraph({ |
67 |
model => $model, |
68 |
context => $context, |
69 |
iterator => $iterator, |
70 |
}); |
71 |
is($model->size,3,"3 statements in model (1 in default graph and 2 in separate named graphs"); |
72 |
|
73 |
$rdf->DelNamedGraph({ |
74 |
model => $model, |
75 |
context => $context, |
76 |
}); |
77 |
is($model->size,2,"2 statements in model (1 in default graph and 1 in a named graph) after 1 of the named graphs was deleted"); |
78 |
}; |
79 |
|
80 |
subtest 'Add triple using Koha::RDF::AddSeeAlso' => sub { |
81 |
plan tests => 2; |
82 |
my $store = RDF::Trine::Store::Memory->new(); |
83 |
my $model = RDF::Trine::Model->new($store); |
84 |
|
85 |
my $resource = RDF::Trine::Node::Resource->new("http://koha-community/resource/1"); |
86 |
my $linked_resource = RDF::Trine::Node::Resource->new("http://upstream/resource/1000"); |
87 |
|
88 |
$rdf->AddSeeAlso({ |
89 |
model => $model, |
90 |
subject => $resource, |
91 |
object => $linked_resource, |
92 |
}); |
93 |
my $iterator = $model->as_stream; |
94 |
my @statements = $iterator->get_all; |
95 |
is(scalar @statements,1,"Added one statement"); |
96 |
my $statement = shift @statements; |
97 |
my $string = $statement->as_string; |
98 |
is($string,'(quad <http://koha-community/resource/1> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://upstream/resource/1000> (nil))',"Statement correctly added"); |
99 |
}; |