fetch MARC records directly from Koha database
[webpac2] / t / 2-input-koha.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib 'lib';
5
6 use Test::More tests => 27;
7
8 BEGIN {
9 use_ok( 'WebPAC::Test' );
10 use_ok( 'WebPAC::Input' );
11 }
12
13 my $module = 'WebPAC::Input::Koha';
14 diag "testing with $module";
15
16 ok(my $input = new WebPAC::Input(
17         module => $module,
18         no_progress_bar => 1,
19         %LOG
20 ), "new");
21
22 ok(my $db = $input->open(
23         path => '/tmp/koha.marc', # required?
24         dsn    => 'dbi:mysql:database=koha',
25         user   => $ENV{KOHA_USER},
26         passwd => $ENV{KOHA_PASSWD},
27         sql    => q{
28                 select biblioitemnumber as mfn, marc from biblioitems limit 7
29         },
30 ), "open");
31 ok(my $size = $input->size, "size");
32 cmp_ok( $size, '==', 7, 'size ok' );
33
34 foreach my $mfn ( 1 ... $size ) {
35         my $rec = $input->fetch;
36         ok($rec, "fetch $mfn");
37         cmp_ok($rec->{'000'}->[0], '==', $mfn, 'has mfn');
38         cmp_ok($input->pos, '==', $mfn, "pos $mfn");
39         diag "rec: ", dump($rec), "\n" if $debug;
40 }
41