Bug 7904 Change SIP modules to use standard LIB path
[koha.git] / C4 / SIP / t / 10renew_all.t
1 #!/usr/bin/perl
2 # renew_all: test Renew All Response
3
4 use strict;
5 use warnings;
6 use FindBin qw($Bin);
7 use lib "$Bin";
8 use Clone qw(clone);
9
10 use C4::SIP::Sip::Constants qw(:all);
11
12 use SIPtest qw(:basic :user1 :item1 :item2);
13
14 my $enable_template = {
15     id => 'Renew All: prep: enable patron permissions',
16     msg => "2520060102    084238AO$instid|AA$user_barcode|",
17     pat => qr/^26 {4}[ Y]{10}000$datepat/,
18     fields => [],
19 };
20
21 my @checkout_templates = (
22         {    id => "Renew All: prep: check out $item_barcode to $user_barcode",
23                 msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item_barcode|AC$password|",
24                 pat => qr/^121NNY$datepat/,
25                 fields => [],},
26         {    id => "Renew All: prep: check out $item2_barcode to $user_barcode",
27                 msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item2_barcode|AC$password|",
28                 pat => qr/^121NNY$datepat/,
29                 fields => [],}
30 );
31
32 my @checkin_templates = (
33         {    id => "Renew All: prep: check in $item_barcode",
34                 msg => "09N20060102    08423620060113    084235AP$item_owner|AO$instid|AB$item_barcode|AC$password|",
35                 pat => qr/^101YNN$datepat/,
36                 fields => [],},
37         {    id => "Renew All: prep: check in $item2_barcode",
38                 msg => "09N20060102    08423620060113    084235AP$item2_owner|AO$instid|AB$item2_barcode|AC$password|",
39                 pat => qr/^101YNN$datepat/,
40                 fields => [],}
41 );
42
43 my $renew_all_test_template = {
44          id => "Renew All: patron ($user_barcode) with 1 item ($item_barcode) checked out, no patron password",
45         msg => "6520060102    084236AO$instid|AA$user_barcode|",
46         pat => qr/^66100010000$datepat/,
47         fields => [
48        $SIPtest::field_specs{(FID_INST_ID)},
49        $SIPtest::field_specs{(FID_SCREEN_MSG)},
50        $SIPtest::field_specs{(FID_PRINT_LINE)},
51        { field   => FID_RENEWED_ITEMS,
52                 pat      => qr/^$item_barcode$/,
53                 required => 1, },
54         ]
55 };
56
57 my @tests = (
58              $SIPtest::login_test,
59              $SIPtest::sc_status_test,
60 #            $enable_template,
61              $checkout_templates[0],
62              $renew_all_test_template,
63              $checkin_templates[0],     # check the book in, when done testing
64              );
65
66 my $test;
67
68 $test = clone($renew_all_test_template);
69 $test->{id} = 'Renew All: Valid patron, two items checked out';
70 $test->{pat} = qr/^66100020000$datepat/;
71 foreach my $i (0 .. (scalar @{$test->{fields}})-1) {
72         my $field =  $test->{fields}[$i];
73         if ($field->{field} eq FID_RENEWED_ITEMS) {
74                 $field->{pat} = qr/^$item_barcode\|$item2_barcode$/;
75         }
76 }
77
78 #push @tests, @checkout_templates[0..1], $renew_all_test_template, @checkin_templates[0..1];
79
80 $test = clone($renew_all_test_template);
81 $test->{id} = 'Renew All: valid patron, invalid patron password';
82 $test->{msg} .= (FID_PATRON_PWD) . 'bad_pwd|';
83 $test->{pat} = qr/^66000000000$datepat/;
84 delete $test->{fields};
85 $test->{fields} = [
86                $SIPtest::field_specs{(FID_INST_ID)},
87                $SIPtest::field_specs{(FID_SCREEN_MSG)},
88                $SIPtest::field_specs{(FID_PRINT_LINE)},
89                   ];
90
91 push @tests, $checkout_templates[0], $test, $checkin_templates[0];
92
93 $test = clone($renew_all_test_template);
94 $test->{id} = 'Renew All: invalid patron';
95 $test->{msg} =~ s/AA$user_barcode/AAbad_barcode/;
96 $test->{pat} = qr/^66000000000$datepat/;
97 delete $test->{fields};
98 $test->{fields} = [
99                $SIPtest::field_specs{(FID_INST_ID)},
100                $SIPtest::field_specs{(FID_SCREEN_MSG)},
101                $SIPtest::field_specs{(FID_PRINT_LINE)},
102                   ];
103 push @tests, $test;
104
105 SIPtest::run_sip_tests(@tests);
106
107 1;