1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use Test::More tests => 23; |
4 |
use Test::Exception; |
5 |
use Cwd qw/abs_path/; |
6 |
use blib; |
7 |
use File::Temp qw/tempdir/; |
8 |
use strict; |
9 |
|
10 |
BEGIN { |
11 |
use_ok( 'WebPAC::DB' ); |
12 |
} |
13 |
|
14 |
ok(my $abs_path = abs_path($0), "abs_path"); |
15 |
$abs_path =~ s#/[^/]*$#/#; |
16 |
diag "abs_path: $abs_path"; |
17 |
|
18 |
my $db; |
19 |
my $debug = 1; |
20 |
|
21 |
diag "NULL DB"; |
22 |
|
23 |
ok($db = new WebPAC::DB( debug => $debug ), "new"); |
24 |
|
25 |
ok(! $db->path, "path"); |
26 |
|
27 |
ok(! $db->load_gs(), 'load_gs'); |
28 |
ok(! $db->load_gs({ '000' => '000' }), 'load_gs'); |
29 |
|
30 |
ok(! $db->save_gs(), "save_gs"); |
31 |
ok(! $db->save_gs({ '000' => '000' }), 'save_gs'); |
32 |
|
33 |
undef $db; |
34 |
|
35 |
ok(my $path = tempdir(), "path"); |
36 |
|
37 |
diag "DB path: $path"; |
38 |
|
39 |
ok($db = new WebPAC::DB( path => $path, debug => $debug ), "new"); |
40 |
|
41 |
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
42 |
|
43 |
ok(! $db->path(''), "path - disable caching"); |
44 |
|
45 |
cmp_ok($db->{'path'}, '==', undef, "no path"); |
46 |
|
47 |
ok($db->path( $path ), "path($path)"); |
48 |
|
49 |
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
50 |
|
51 |
ok(! $db->load_gs(), 'load_gs'); |
52 |
ok(! $db->load_gs({ '000' => '000' }), 'load_gs'); |
53 |
|
54 |
ok(! $db->save_gs(), "save_gs"); |
55 |
|
56 |
my @ds = [ { |
57 |
'name' => 'Izvor: ', |
58 |
'tag' => 'Source', |
59 |
'display' => [ 'foo' ] |
60 |
}, { |
61 |
'name' => 'ID', |
62 |
'tag' => 'IDths', |
63 |
'swish' => [ 'bar' ], |
64 |
'lookup_key' => [ 'bar' ] |
65 |
}, { |
66 |
'filename' => [ 'out/thes/001.html' ], |
67 |
'name' => 'filename', |
68 |
'tag' => 'filename' |
69 |
}, |
70 |
]; |
71 |
|
72 |
ok(! $db->save_gs(), "empty save_gs"); |
73 |
throws_ok { $db->save_gs( foo => 1 ) } qr/ds/, "save_gs - ds"; |
74 |
throws_ok { $db->save_gs( ds => \@ds ) } qr/current_filename/, "save_gs - current_filename"; |
75 |
throws_ok { $db->save_gs( ds => \@ds, 'current_filename' => 'foo' ) } qr/headline/, "save_gs - headline"; |
76 |
|
77 |
ok($db->save_gs( ds => \@ds, 'current_filename' => 'foo', 'headline' => 'bar' ), "save_gs"); |
78 |
|
79 |
undef $db; |
80 |
|