2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 34; |
use Test::More tests => 66; |
6 |
use Test::Exception; |
use Test::Exception; |
7 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
8 |
use File::Temp qw/tempdir/; |
use File::Temp qw/tempdir/; |
9 |
|
use File::Slurp; |
10 |
use Data::Dumper; |
use Data::Dumper; |
11 |
use blib; |
use blib; |
12 |
|
|
13 |
|
my $debug = 1; |
14 |
|
|
15 |
BEGIN { |
BEGIN { |
16 |
use_ok( 'WebPAC::Lookup' ); |
use_ok( 'WebPAC::Lookup' ); |
17 |
use_ok( 'WebPAC::Input' ); |
use_ok( 'WebPAC::Input' ); |
18 |
use_ok( 'WebPAC::Store' ); |
use_ok( 'WebPAC::Store' ); |
19 |
use_ok( 'WebPAC::Normalize::XML' ); |
use_ok( 'WebPAC::Normalize::XML' ); |
20 |
|
use_ok( 'WebPAC::Normalize::Set' ); |
21 |
use_ok( 'WebPAC::Output::TT' ); |
use_ok( 'WebPAC::Output::TT' ); |
22 |
} |
} |
23 |
|
|
24 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
25 |
$abs_path =~ s#/[^/]*$#/#; |
$abs_path =~ s#/[^/]*$#/#; |
26 |
diag "abs_path: $abs_path"; |
diag "abs_path: $abs_path" if ($debug); |
27 |
|
|
28 |
my $isis_file = "$abs_path../t/winisis/BIBL"; |
my $isis_file = "$abs_path../t/winisis/BIBL"; |
29 |
$isis_file = '/data/hidra/THS/THS'; |
$isis_file = '/data/hidra/THS/THS'; |
30 |
|
|
31 |
diag "isis_file: $isis_file"; |
diag "isis_file: $isis_file" if ($debug); |
32 |
|
|
33 |
|
my $normalize_set_pl = "$abs_path/data/normalize.pl"; |
34 |
|
my $lookup_file = "$abs_path../conf/lookup/isis.pm"; |
35 |
|
|
36 |
ok(my $lookup = new WebPAC::Lookup( |
ok(my $lookup = new WebPAC::Lookup( |
37 |
lookup_file => "$abs_path../conf/lookup/isis.pm", |
lookup_file => $lookup_file, |
38 |
), "new Lookup"); |
), "new Lookup"); |
39 |
|
|
40 |
ok(my $isis = new WebPAC::Input( |
ok(my $isis = new WebPAC::Input( |
65 |
|
|
66 |
ok($n->open( |
ok($n->open( |
67 |
tag => 'isis', |
tag => 'isis', |
68 |
xml_file => "$abs_path../conf/normalize/isis.xml", |
xml_file => "$abs_path/data/normalize.xml", |
69 |
), "Normalize::XML->open"); |
), "Normalize::XML->open"); |
70 |
|
|
71 |
|
ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" ); |
72 |
|
|
73 |
ok(my $out = new WebPAC::Output::TT( |
ok(my $out = new WebPAC::Output::TT( |
74 |
include_path => "$abs_path../conf/output/tt", |
include_path => "$abs_path../conf/output/tt", |
75 |
filters => { foo => sub { shift } }, |
filters => { foo => sub { shift } }, |
76 |
), "new Output::TT"); |
), "new Output::TT"); |
77 |
|
|
78 |
while (my $row = $isis->fetch) { |
while (my $row = $isis->fetch) { |
79 |
|
|
80 |
ok(my $ds = $n->data_structure($row), "data_structure"); |
ok(my $ds = $n->data_structure($row), "data_structure"); |
81 |
|
|
82 |
# diag Dumper($ds); |
diag " ds => ",Dumper($ds) if ($debug); |
83 |
|
|
84 |
|
# TODO move somewhere |
85 |
|
{ |
86 |
|
no strict 'subs'; |
87 |
|
use WebPAC::Normalize::Set; |
88 |
|
diag " row => ",Dumper($row) if ($debug); |
89 |
|
set_rec( $row ); |
90 |
|
#diag " lookup => ",Dumper($lookup) if ($debug); |
91 |
|
#set_lookup( $lookup ); |
92 |
|
clean_ds(); |
93 |
|
eval "$norm_pl"; |
94 |
|
ok(! $@, $@ ? "error: $@" : "no error"); |
95 |
|
ok(my $ds2 = get_ds(), "get_ds"); |
96 |
|
is_deeply( $ds, $ds2, 'ds same for xml and sets'); |
97 |
|
|
98 |
|
diag " ds2 => ",Dumper($ds2) if ($debug); |
99 |
|
} |
100 |
|
|
101 |
ok(my $html = $out->apply( |
ok(my $html = $out->apply( |
102 |
template => 'html.tt', |
template => 'html.tt', |
105 |
|
|
106 |
$html =~ s#\s*[\n\r]+\s*##gs; |
$html =~ s#\s*[\n\r]+\s*##gs; |
107 |
|
|
108 |
diag $html; |
#diag $html; |
109 |
|
|
110 |
}; |
}; |