bug 4865: added dependency for using memcached for sessions
[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(:basic :user1 :item1 :item2);
11
12 my $enable_template = {
13     id => 'Renew All: prep: enable patron permissions',
14     msg => "2520060102    084238AO$instid|AA$user_barcode|",
15     pat => qr/^26 {4}[ Y]{10}000$datepat/,
16     fields => [],
17 };
18
19 my @checkout_templates = (
20         {    id => "Renew All: prep: check out $item_barcode to $user_barcode",
21                 msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item_barcode|AC$password|",
22                 pat => qr/^121NNY$datepat/,
23                 fields => [],},
24         {    id => "Renew All: prep: check out $item2_barcode to $user_barcode",
25                 msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item2_barcode|AC$password|",
26                 pat => qr/^121NNY$datepat/,
27                 fields => [],}
28 );
29
30 my @checkin_templates = (
31         {    id => "Renew All: prep: check in $item_barcode",
32                 msg => "09N20060102    08423620060113    084235AP$item_owner|AO$instid|AB$item_barcode|AC$password|",
33                 pat => qr/^101YNN$datepat/,
34                 fields => [],},
35         {    id => "Renew All: prep: check in $item2_barcode",
36                 msg => "09N20060102    08423620060113    084235AP$item2_owner|AO$instid|AB$item2_barcode|AC$password|",
37                 pat => qr/^101YNN$datepat/,
38                 fields => [],}
39 );
40
41 my $renew_all_test_template = {
42          id => "Renew All: patron ($user_barcode) with 1 item ($item_barcode) checked out, no patron password",
43         msg => "6520060102    084236AO$instid|AA$user_barcode|",
44         pat => qr/^66100010000$datepat/,
45         fields => [
46        $SIPtest::field_specs{(FID_INST_ID)},
47        $SIPtest::field_specs{(FID_SCREEN_MSG)},
48        $SIPtest::field_specs{(FID_PRINT_LINE)},
49        { field   => FID_RENEWED_ITEMS,
50                 pat      => qr/^$item_barcode$/,
51                 required => 1, },
52         ]
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         if ($field->{field} eq FID_RENEWED_ITEMS) {
72                 $field->{pat} = qr/^$item_barcode\|$item2_barcode$/;
73         }
74 }
75
76 #push @tests, @checkout_templates[0..1], $renew_all_test_template, @checkin_templates[0..1];
77
78 $test = clone($renew_all_test_template);
79 $test->{id} = 'Renew All: valid patron, invalid patron password';
80 $test->{msg} .= (FID_PATRON_PWD) . 'bad_pwd|';
81 $test->{pat} = qr/^66000000000$datepat/;
82 delete $test->{fields};
83 $test->{fields} = [
84                $SIPtest::field_specs{(FID_INST_ID)},
85                $SIPtest::field_specs{(FID_SCREEN_MSG)},
86                $SIPtest::field_specs{(FID_PRINT_LINE)},
87                   ];
88
89 push @tests, $checkout_templates[0], $test, $checkin_templates[0];
90
91 $test = clone($renew_all_test_template);
92 $test->{id} = 'Renew All: invalid patron';
93 $test->{msg} =~ s/AA$user_barcode/AAbad_barcode/;
94 $test->{pat} = qr/^66000000000$datepat/;
95 delete $test->{fields};
96 $test->{fields} = [
97                $SIPtest::field_specs{(FID_INST_ID)},
98                $SIPtest::field_specs{(FID_SCREEN_MSG)},
99                $SIPtest::field_specs{(FID_PRINT_LINE)},
100                   ];
101 push @tests, $test;
102
103 SIPtest::run_sip_tests(@tests);
104
105 1;