Bug 26886: Correct style of alert-error class in the OPAC
[koha.git] / C4 / SIP / t / 07hold.t
blobb05e3acb9ba123fc6f4d60948a02dede133409a7
1 #!/usr/bin/perl
2 # patron_enable: test Patron Enable Response
4 use strict;
5 use warnings;
6 use FindBin qw($Bin);
7 use lib "$Bin";
8 use Clone qw(clone);
10 use C4::SIP::Sip::Constants qw(:all);
12 use SIPtest qw(:basic :user1 :user2 :item1 :item2);
14 my $hold_test_template = {
15 id => "Place Hold: valid item ($item_barcode), valid patron ($user_barcode)", #BS could be another branch
16 msg => "15+20060415 110158BW20060815 110158|BS$instid|BY2|AO$instid|AA$user_barcode|AB$item_barcode|",
17 pat => qr/^161Y$datepat/,
18 fields => [
19 $SIPtest::field_specs{(FID_INST_ID)},
20 $SIPtest::field_specs{(FID_SCREEN_MSG)},
21 $SIPtest::field_specs{(FID_PRINT_LINE)},
22 { field => FID_PATRON_ID,
23 pat => qr/^$user_barcode$/,
24 required => 1, },
25 { field => FID_EXPIRATION,
26 pat => $datepat,
27 required => 0, },
28 { field => FID_QUEUE_POS,
29 pat => qr/^1$/,
30 required => 0, },
31 { field => FID_PICKUP_LOCN,
32 pat => qr/^$item_owner$/,
33 required => 0, },
34 { field => FID_TITLE_ID,
35 pat => qr/^$item_title$/,
36 required => 0, },
37 { field => FID_ITEM_ID,
38 pat => qr/^$item_barcode$/,
39 required => 0, },
40 ],};
42 my $tmp_msg = "6300020060329 201700 AO$instid|AA$user_barcode|";
43 my $hold_count_test_template0 = {
44 id => "Confirm patron ($user_barcode) has 0 holds",
45 msg => $tmp_msg,
46 pat => qr/^64 [ Y]{13}\d{3}${datepat}0000(\d{4}){5}/,
47 fields => [],
49 my $hold_count_test_template1 = {
50 id => "Confirm patron ($user_barcode) has 1 hold",
51 msg => $tmp_msg,
52 pat => qr/^64 [ Y]{13}\d{3}${datepat}((0001(\d{4}){4}0000)|(0000(\d{4}){4}0001))/,
53 # The tricky part at the end here is because we don't know whether
54 # the hold will count as "waiting" or unavailable.
55 # But it will be one or the other!
56 fields => [],
59 my @tests = (
60 $SIPtest::login_test, # 1
61 $SIPtest::sc_status_test, # 2
62 $hold_test_template, $hold_count_test_template1, # 3,4
65 my $test;
67 # Hold Queue: second hold placed on item
68 $test = clone($hold_test_template);
69 $test->{id} = "Place 2nd hold on item ($item_barcode) for user ($user2_barcode)";
70 $test->{msg} =~ s/AA$user_barcode\|/AA$user2_barcode|/;
71 $test->{pat} = qr/^161N$datepat/;
72 foreach my $i (0 .. (scalar @{$test->{fields}})-1) {
73 my $field = $test->{fields}[$i];
74 if ($field->{field} eq FID_PATRON_ID) {
75 $field->{pat} = qr/^$user2_barcode$/;
76 } elsif ($field->{field} eq FID_QUEUE_POS) {
77 $field->{pat} = qr/^2$/;
81 push @tests, $test; # 5
83 # Cancel hold: valid hold
84 $test = clone($hold_test_template);
85 $test->{id} = "Cancel Hold: valid hold for user ($user_barcode)";
86 $test->{msg} =~ s/\+/-/;
87 $test->{pat} = qr/^161[NY]$datepat/;
88 delete $test->{fields};
89 $test->{fields} = [
90 $SIPtest::field_specs{(FID_INST_ID)},
91 $SIPtest::field_specs{(FID_SCREEN_MSG)},
92 $SIPtest::field_specs{(FID_PRINT_LINE)},
93 { field => FID_PATRON_ID,
94 pat => qr/^$user_barcode$/,
95 required => 1, },
98 push @tests, $test, $hold_count_test_template0; # 6,7
100 # Cancel Hold: no hold on item
101 # $test is already set up to cancel a hold, just change
102 # the field tests
103 $test = clone($test);
104 $test->{id} = 'Cancel Hold: no hold on specified item';
105 $test->{pat} = qr/^160N$datepat/;
107 push @tests, $test, $hold_count_test_template0; # 8,9
109 # Cleanup: cancel 2nd user's hold too.
110 $test = clone($hold_test_template);
111 $test->{id} = "Cancel hold: cleanup hold for 2nd patron ($user2_barcode)";
112 $test->{msg} =~ s/\+/-/;
113 $test->{msg} =~ s/$user_barcode/$user2_barcode/;
114 $test->{pat} = qr/^161[NY]$datepat/;
115 delete $test->{fields};
116 $test->{fields} = [
117 $SIPtest::field_specs{(FID_INST_ID)},
118 $SIPtest::field_specs{(FID_SCREEN_MSG)},
119 $SIPtest::field_specs{(FID_PRINT_LINE)},
120 { field => FID_PATRON_ID,
121 pat => qr/^$user2_barcode$/,
122 required => 1, },
125 push @tests, $test; # 11
127 # Place hold: valid patron, item, invalid patron pwd
128 $test = clone($hold_test_template);
129 $test->{id} = 'Place hold: invalid patron password';
130 $test->{msg} .= FID_PATRON_PWD . 'bad password|';
131 $test->{pat} = qr/^160N$datepat/;
132 delete $test->{fields};
133 $test->{fields} = [
134 $SIPtest::field_specs{(FID_INST_ID)},
135 $SIPtest::field_specs{(FID_SCREEN_MSG)},
136 $SIPtest::field_specs{(FID_PRINT_LINE)},
137 { field => FID_PATRON_ID,
138 pat => qr/^$user_barcode$/,
139 required => 1, },
142 push @tests, $test, $hold_count_test_template0; # 12,13
144 # Place hold: invalid patron
145 $test = clone($hold_test_template);
146 $test->{id} = 'Place hold: invalid patron';
147 $test->{msg} =~ s/AA$user_barcode\|/AAbad_barcode|/;
148 $test->{pat} = qr/^160N$datepat/;
149 delete $test->{fields};
150 $test->{fields} = [
151 $SIPtest::field_specs{(FID_INST_ID)},
152 $SIPtest::field_specs{(FID_SCREEN_MSG)},
153 $SIPtest::field_specs{(FID_PRINT_LINE)},
154 { field => FID_PATRON_ID,
155 pat => qr/^bad_barcode$/,
156 required => 1, },
159 # There's no patron to check the number of holds against
160 push @tests, $test; # 14
162 # Place hold: invalid item
163 $test = clone($hold_test_template);
164 $test->{id} = 'Place hold: invalid item';
165 $test->{msg} =~ s/AB$item_barcode\|/ABnosuchitem|/;
166 $test->{pat} = qr/^160N$datepat/;
167 delete $test->{fields};
168 $test->{fields} = [
169 $SIPtest::field_specs{(FID_INST_ID)},
170 $SIPtest::field_specs{(FID_SCREEN_MSG)},
171 $SIPtest::field_specs{(FID_PRINT_LINE)},
172 { field => FID_PATRON_ID,
173 pat => qr/^$user_barcode$/,
174 required => 1, },
175 { field => FID_ITEM_ID,
176 pat => qr/^nosuchitem$/,
177 required => 0, },
180 push @tests, $test, $hold_count_test_template0; # 15
182 # Still need tests for:
183 # - valid patron not permitted to place holds
184 # - valid item, not allowed to hold item
185 # - multiple holds on item: correct queue position management
186 # - setting and verifying hold expiry dates (requires ILS support)
187 # - 3M checkin extensions for hold/ILL routing
189 SIPtest::run_sip_tests(@tests);