1 |
dpavlin |
18 |
#!/usr/bin/perl -w |
2 |
|
|
|
3 |
|
|
use Test::More tests => 22; |
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 |
|
|
|
20 |
|
|
diag "NULL DB"; |
21 |
|
|
|
22 |
|
|
ok($db = new WebPAC::DB( debug => 1), "new"); |
23 |
|
|
|
24 |
|
|
ok(! $db->path, "path"); |
25 |
|
|
|
26 |
|
|
ok(! $db->load_gs(), 'load_gs'); |
27 |
|
|
ok(! $db->load_gs({ '000' => '000' }), 'load_gs'); |
28 |
|
|
|
29 |
|
|
ok(! $db->save_gs(), "save_gs"); |
30 |
|
|
ok(! $db->save_gs({ '000' => '000' }), 'save_gs'); |
31 |
|
|
|
32 |
|
|
undef $db; |
33 |
|
|
|
34 |
|
|
ok(my $path = tempdir(), "path"); |
35 |
|
|
|
36 |
|
|
diag "DB path: $path"; |
37 |
|
|
|
38 |
|
|
ok($db = new WebPAC::DB( path => $path, debug => 1), "new"); |
39 |
|
|
|
40 |
|
|
cmp_ok($db->{'path'}, 'eq', $path, "path"); |
41 |
|
|
|
42 |
|
|
ok(! $db->path, "path - disable caching"); |
43 |
|
|
|
44 |
|
|
cmp_ok($db->{'path'}, '==', undef, "no path"); |
45 |
|
|
|
46 |
|
|
ok($db->path( $path ), "path($path)"); |
47 |
|
|
|
48 |
|
|
ok(! $db->load_gs(), 'load_gs'); |
49 |
|
|
ok(! $db->load_gs({ '000' => '000' }), 'load_gs'); |
50 |
|
|
|
51 |
|
|
ok(! $db->save_gs(), "save_gs"); |
52 |
|
|
|
53 |
|
|
my @ds = [ { |
54 |
|
|
'name' => 'Izvor: ', |
55 |
|
|
'tag' => 'Source', |
56 |
|
|
'display' => [ 'foo' ] |
57 |
|
|
}, { |
58 |
|
|
'name' => 'ID', |
59 |
|
|
'tag' => 'IDths', |
60 |
|
|
'swish' => [ 'bar' ], |
61 |
|
|
'lookup_key' => [ 'bar' ] |
62 |
|
|
}, { |
63 |
|
|
'filename' => [ 'out/thes/001.html' ], |
64 |
|
|
'name' => 'filename', |
65 |
|
|
'tag' => 'filename' |
66 |
|
|
}, |
67 |
|
|
]; |
68 |
|
|
|
69 |
|
|
ok(! $db->save_gs(), "empty save_gs"); |
70 |
|
|
throws_ok { $db->save_gs( foo => 1 ) } qr/ds/, "save_gs - ds"; |
71 |
|
|
throws_ok { $db->save_gs( ds => \@ds ) } qr/current_filename/, "save_gs - current_filename"; |
72 |
|
|
throws_ok { $db->save_gs( ds => \@ds, 'current_filename' => 'foo' ) } qr/headline/, "save_gs - headline"; |
73 |
|
|
|
74 |
|
|
ok($db->save_gs( ds => \@ds, 'current_filename' => 'foo', 'headline' => 'bar' ), "save_gs"); |
75 |
|
|
|
76 |
|
|
undef $db; |
77 |
|
|
|