adding openncip / opensip SIP2 service
[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 Clone qw(clone);
7
8 use Sip::Constants qw(:all);
9
10 use SIPtest qw($datepat $textpat $user_barcode $item_barcode $item_owner
11                $item2_barcode $item2_owner $instid);
12
13 my $enable_template = {
14     id => 'Renew All: prep: enable patron permissions',
15     msg => "2520060102    084238AO$instid|AA$user_barcode|",
16     pat => qr/^26 {4}[ Y]{10}000$datepat/,
17     fields => [],
18 };
19
20 my @checkout_templates = (
21                           { id => "Renew All: prep: check out $item_barcode",
22                             msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item_barcode|AC|",
23                             pat => qr/^121NNY$datepat/,
24                             fields => [],},
25                           { id => "Renew All: prep: check out $item2_barcode",
26                             msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item2_barcode|AC|",
27                             pat => qr/^121NNY$datepat/,
28                             fields => [],}
29                          );
30
31 my @checkin_templates = (
32                         { id => "Renew All: prep: check in $item_barcode",
33                           msg => "09N20060102    08423620060113    084235APUnder the bed|AO$instid|AB$item_barcode|ACterminal password|",
34                           pat => qr/^101YNN$datepat/,
35                           fields => [],},
36                         { id => "Renew All: prep: check in $item2_barcode",
37                           msg => "09N20060102    08423620060113    084235APUnder the bed|AO$instid|AB$item2_barcode|ACterminal password|",
38                           pat => qr/^101YNN$datepat/,
39                           fields => [],}
40                        );
41
42 my $renew_all_test_template = {
43     id => 'Renew All: valid patron with one item checked out, no patron password',
44     msg => "6520060102    084236AO$instid|AA$user_barcode|",
45     pat => qr/^66100010000$datepat/,
46     fields => [
47                $SIPtest::field_specs{(FID_INST_ID)},
48                $SIPtest::field_specs{(FID_SCREEN_MSG)},
49                $SIPtest::field_specs{(FID_PRINT_LINE)},
50                { field    => FID_RENEWED_ITEMS,
51                  pat      => qr/^$item_barcode$/,
52                  required => 1, },
53                ],};
54
55 my @tests = (
56              $SIPtest::login_test,
57              $SIPtest::sc_status_test,
58 #            $enable_template,
59              $checkout_templates[0],
60              $renew_all_test_template,
61              $checkin_templates[0],     # check the book in, when done testing
62              );
63
64 my $test;
65
66 #$test = clone($renew_all_test_template);
67 #$test->{id} = 'Renew All: Valid patron, two items checked out';
68 #$test->{pat} = qr/^66100020000$datepat/;
69 #foreach my $i (0 .. (scalar @{$test->{fields}})-1) {
70 #    my $field =  $test->{fields}[$i];
71 #
72 #    if ($field->{field} eq FID_RENEWED_ITEMS) {
73 #       $field->{pat} = qr/^$item_barcode\|$item2_barcode$/;
74 #    }
75 #}
76 #
77 #push @tests, $checkout_templates[0], $checkout_templates[1],
78 #  $renew_all_test_template, $checkin_templates[0], $checkin_templates[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) . 'badpwd|';
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/AAberick/;
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;