bddb31218a50373d01bc02126250d8ac0121db95
[koha.git] / C4 / SIP / koha_test / 07hold.t
1 #!/usr/bin/perl
2 # patron_enable: test  Patron Enable 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);
11
12 my $hold_test_template = {
13     id => 'Place Hold: valid item, valid patron',
14     msg => '15+20060415    110158BW20060815    110158|BSTaylor|BY2|AOUWOLS|AAdjfiander|AB1565921879|',
15     pat => qr/^161N$datepat/,
16     fields => [
17                $SIPtest::field_specs{(FID_INST_ID)},
18                $SIPtest::field_specs{(FID_SCREEN_MSG)},
19                $SIPtest::field_specs{(FID_PRINT_LINE)},
20                { field    => FID_PATRON_ID,
21                  pat      => qr/^djfiander$/,
22                  required => 1, },
23                { field    => FID_EXPIRATION,
24                  pat      => $datepat,
25                  required => 0, },
26                { field    => FID_QUEUE_POS,
27                  pat      => qr/^1$/,
28                  required => 1, },
29                { field    => FID_PICKUP_LOCN,
30                  pat      => qr/^Taylor$/,
31                  required => 1, },
32                { field    => FID_TITLE_ID,
33                  pat      => qr/^Perl 5 desktop reference$/,
34                  required => 1, },
35                { field    => FID_ITEM_ID,
36                  pat      => qr/^1565921879$/,
37                  required => 1, },
38                ],};
39
40 my $hold_count_test_template0 = {
41     id => 'Confirm patron has 0 holds',
42     msg => '6300020060329    201700          AOUWOLS|AAdjfiander|',
43     pat => qr/^64 [ Y]{13}\d{3}${datepat}0000(\d{4}){5}/,
44     fields => [],
45 };
46
47 my $hold_count_test_template1 = {
48     id => 'Confirm patron has 1 hold',
49     msg => '6300020060329    201700          AOUWOLS|AAdjfiander|',
50     pat => qr/^64 [ Y]{13}\d{3}${datepat}0001(\d{4}){5}/,
51     fields => [],
52 };
53
54
55 my @tests = (
56              $SIPtest::login_test,
57              $SIPtest::sc_status_test,
58              $hold_test_template, $hold_count_test_template1,
59              );
60
61 my $test;
62
63 # Hold Queue: second hold placed on item
64 $test = clone($hold_test_template);
65 $test->{id} = 'Place hold: second hold on item';
66 $test->{msg} =~ s/djfiander/miker/;
67 $test->{pat} = qr/^161N$datepat/;
68 foreach my $i (0 .. (scalar @{$test->{fields}})-1) {
69     my $field =  $test->{fields}[$i];
70
71     if ($field->{field} eq FID_PATRON_ID) {
72         $field->{pat} = qr/^miker$/;
73     } elsif ($field->{field} eq FID_QUEUE_POS) {
74         $field->{pat} = qr/^2$/;
75     }
76 }
77
78 push @tests, $test;
79
80 # Cancel hold: valid hold
81 $test = clone($hold_test_template);
82 $test->{id} = 'Cancel hold: valid hold';
83 $test->{msg} =~ s/\+/-/;
84 $test->{pat} = qr/^161[NY]$datepat/;
85 delete $test->{fields};
86 $test->{fields} = [
87                    $SIPtest::field_specs{(FID_INST_ID)},
88                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
89                    $SIPtest::field_specs{(FID_PRINT_LINE)},
90                    { field    => FID_PATRON_ID,
91                      pat      => qr/^djfiander$/,
92                      required => 1, },
93                    ];
94
95 push @tests, $test, $hold_count_test_template0;
96
97 # Cancel Hold: no hold on item
98 # $test is already set up to cancel a hold, just change
99 # the field tests
100 $test = clone($test);
101 $test->{id} = 'Cancel Hold: no hold on specified item';
102 $test->{pat} = qr/^160N$datepat/;
103
104 push @tests, $test, $hold_count_test_template0;
105
106 # Cleanup: cancel miker's hold too.
107 $test = clone($hold_test_template);
108 $test->{id} = "Cancel hold: cleanup second patron's hold";
109 $test->{msg} =~ s/\+/-/;
110 $test->{msg} =~ s/djfiander/miker/;
111 $test->{pat} = qr/^161[NY]$datepat/;
112 delete $test->{fields};
113 $test->{fields} = [
114                    $SIPtest::field_specs{(FID_INST_ID)},
115                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
116                    $SIPtest::field_specs{(FID_PRINT_LINE)},
117                    { field    => FID_PATRON_ID,
118                      pat      => qr/^miker$/,
119                      required => 1, },
120                    ];
121
122 push @tests, $test;
123
124 # Place hold: valid patron, item, invalid patron pwd
125 $test = clone($hold_test_template);
126 $test->{id} = 'Place hold: invalid patron password';
127 $test->{msg} .= FID_PATRON_PWD . 'bad password|';
128 $test->{pat} = qr/^160N$datepat/;
129 delete $test->{fields};
130 $test->{fields} = [
131                    $SIPtest::field_specs{(FID_INST_ID)},
132                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
133                    $SIPtest::field_specs{(FID_PRINT_LINE)},
134                    { field    => FID_PATRON_ID,
135                      pat      => qr/^djfiander$/,
136                      required => 1, },
137                    ];
138
139 push @tests, $test, $hold_count_test_template0;
140
141 # Place hold: invalid patron
142 $test = clone($hold_test_template);
143 $test->{id} = 'Place hold: invalid patron';
144 $test->{msg} =~ s/AAdjfiander\|/AAberick|/;
145 $test->{pat} = qr/^160N$datepat/;
146 delete $test->{fields};
147 $test->{fields} = [
148                    $SIPtest::field_specs{(FID_INST_ID)},
149                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
150                    $SIPtest::field_specs{(FID_PRINT_LINE)},
151                    { field    => FID_PATRON_ID,
152                      pat      => qr/^berick$/,
153                      required => 1, },
154                    ];
155
156 # There's no patron to check the number of holds against
157 push @tests, $test;
158
159 # Place hold: invalid item
160 $test = clone($hold_test_template);
161 $test->{id} = 'Place hold: invalid item';
162 $test->{msg} =~ s/AB1565921879\|/ABnosuchitem|/;
163 $test->{pat} = qr/^160N$datepat/;
164 delete $test->{fields};
165 $test->{fields} = [
166                    $SIPtest::field_specs{(FID_INST_ID)},
167                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
168                    $SIPtest::field_specs{(FID_PRINT_LINE)},
169                    { field    => FID_PATRON_ID,
170                      pat      => qr/^djfiander$/,
171                      required => 1, },
172                    { field    => FID_ITEM_ID,
173                      pat      => qr/^nosuchitem$/,
174                      required => 0, },
175                    ];
176
177 push @tests, $test, $hold_count_test_template0;
178
179 # Still need tests for:
180 #     - valid patron not permitted to place holds
181 #     - valid item, not allowed to hold item
182 #     - multiple holds on item: correct queue position management
183 #     - setting and verifying hold expiry dates (requires ILS support)
184
185 SIPtest::run_sip_tests(@tests);
186
187 1;