429af8ca4de366d9482ddd59bf0407aae4c66e52
[webpac2] / t / 6-unit.t
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Test::More tests => 23;
6 use Test::Exception;
7 use Cwd qw/abs_path/;
8 use File::Temp qw/tempdir/;
9 use blib;
10
11 BEGIN {
12 use_ok( 'WebPAC::Lookup' );
13 use_ok( 'WebPAC::Input::ISIS' );
14 use_ok( 'WebPAC::DB' );
15 use_ok( 'WebPAC::Normalize::XML' );
16 use_ok( 'WebPAC::Output::TT' );
17 }
18
19 ok(my $abs_path = abs_path($0), "abs_path");
20 $abs_path =~ s#/[^/]*$#/#;
21 diag "abs_path: $abs_path";
22
23 my $isis_file = "$abs_path../t/winisis/BIBL";
24
25 diag "isis_file: $isis_file";
26
27 ok(my $lookup = new WebPAC::Lookup(
28         lookup_file => "$abs_path../conf/lookup/isis.pm",
29 ), "new Lookup");
30
31 ok(my $isis = new WebPAC::Input::ISIS(
32         code_page => 'ISO-8859-2',      # application encoding
33 ), "new Input::ISIS");
34
35 ok(my $maxmfn = $isis->open(
36         filename => $isis_file,
37         code_page => '852',             # database encoding
38 ), "Input::ISIS->open");
39
40 ok(my $path = tempdir( CLEANUP => 1 ), "path");
41
42 ok(my $db = new WebPAC::DB(
43         path => $path,
44 ), "new DB");
45
46 ok(my $n = new WebPAC::Normalize::XML(
47 #       filter => { 'foo' => sub { shift } },
48         db => $db,
49         lookup_regex => $lookup->regex,
50         debug => 1,
51 ), "new Normalize::XML");
52
53 ok($n->open(
54         tag => 'isis',
55         xml_file => "$abs_path../conf/normalize/isis.xml",
56 ), "Normalize::XML->open");
57
58 ok(my $out = new WebPAC::Output::TT(
59         include_path => "$abs_path../conf/output/tt",
60         filters => { foo => sub { shift } },
61 ), "new Output::TT");
62
63 while (my $row = $isis->fetch) {
64         
65         ok(my @ds = $n->data_structure($row), "data_structure");
66
67 use Data::Dumper;
68 print Dumper(\@ds);
69
70         ok($out->apply(
71                 template => 'html.tt',
72                 data => @ds,
73         ), "apply");
74
75 };