|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
use Test::More tests => 3; |
| 5 |
use YAML; |
| 6 |
use File::Temp qw/ tempfile /; |
| 7 |
|
| 8 |
use C4::Context; |
| 9 |
|
| 10 |
#Make a temporary configuration file for the triplestore |
| 11 |
my ($fh, $filename) = tempfile(undef, UNLINK => 1); |
| 12 |
my $temp_config = { |
| 13 |
module => 'RDF::Trine::Store::SPARQL', |
| 14 |
url => 'http://localhost/example/rdf', |
| 15 |
realm => undef, |
| 16 |
username => undef, |
| 17 |
password => undef, |
| 18 |
}; |
| 19 |
|
| 20 |
#Tell C4::Context to use the temporary configuration file as the triplestore_config |
| 21 |
my $context = $C4::Context::context; |
| 22 |
$context->{config}->{triplestore_config} = $filename; |
| 23 |
|
| 24 |
SUCCESS: { |
| 25 |
YAML::DumpFile($filename, $temp_config); |
| 26 |
|
| 27 |
my $context_object = C4::Context->new(); |
| 28 |
my $triplestore = $context_object->triplestore; |
| 29 |
is(ref $triplestore, 'RDF::Trine::Model', 'C4::Context->new()->triplestore returns RDF::Trine::Model if module equals RDF::Trine::Store::SPARQL'); |
| 30 |
} |
| 31 |
|
| 32 |
MISSING_URL: { |
| 33 |
#Reset triplestore context |
| 34 |
delete $context->{triplestore}; |
| 35 |
|
| 36 |
my $url = delete $temp_config->{url}; |
| 37 |
YAML::DumpFile($filename, $temp_config); |
| 38 |
|
| 39 |
my $context_object = C4::Context->new(); |
| 40 |
my $triplestore = $context_object->triplestore; |
| 41 |
is($triplestore, undef, 'C4::Context->new()->triplestore returns undef if missing url for SPARQL store'); |
| 42 |
|
| 43 |
#Restore url for other tests |
| 44 |
$temp_config->{url} = $url; |
| 45 |
} |
| 46 |
|
| 47 |
BAD_MODULE: { |
| 48 |
#Reset triplestore context |
| 49 |
delete $context->{triplestore}; |
| 50 |
|
| 51 |
$temp_config->{module} = 'Local::RDF::Bad::Module'; |
| 52 |
YAML::DumpFile($filename, $temp_config); |
| 53 |
|
| 54 |
my $context_object = C4::Context->new(); |
| 55 |
my $triplestore = $context_object->triplestore; |
| 56 |
is($triplestore, undef, 'C4::Context->new()->triplestore returns undef if module equals Local::RDF::Bad::Module'); |
| 57 |
} |