bug 8022 follow-up, missing permission in spanish
[koha.git] / C4 / SIP / t / 03checkout.t
1 #!/usr/bin/perl
2 # checkout: test Checkout Response
3
4 use strict;
5 use warnings;
6 use Clone qw(clone);
7
8 use CGI;
9
10 use Sip::Constants qw(:all);
11 use SIPtest qw(
12                 :basic
13                 $user_barcode
14                 :diacritic
15         :item1
16         );
17
18 my $patron_enable_template = {
19     id => 'Renew All: prep: enable patron permissions',
20     msg => "2520060102    084238AO$instid|AA$user_barcode|",
21     pat => qr/^26 {4}[ Y]{10}000$datepat/o,
22     fields => [],
23 };
24
25 my $patron_disable_template = {
26     id => 'Checkout: block patron (prep to test checkout denied)',
27     msg => "01N20060102    084238AO$instid|ALFees overrun|AA$user_barcode|",
28     # response to block patron is a patron status message
29     pat => qr/^24Y{4}[ Y]{10}000$datepat/o,
30     fields => [],
31 };
32
33 my $checkin_template = {
34         id => 'Checkout: cleanup: check in item',
35         msg => "09N20050102    08423620060113    084235AP$item_owner|AO$instid|AB$item_barcode|ACterminal password|",
36         pat => qr/^101YNN$datepat/o,
37         fields => [],
38 };
39
40 my $checkout_test_template = {
41     id => 'Checkout: valid item, valid patron',
42     msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item_barcode|AC|",
43     pat => qr/^121NNY$datepat/,
44     fields => [
45                $SIPtest::field_specs{(FID_INST_ID)},
46                $SIPtest::field_specs{(FID_SCREEN_MSG)},
47                $SIPtest::field_specs{(FID_PRINT_LINE)},
48                { field    => FID_PATRON_ID,
49                  pat      => qr/^$user_barcode$/o,
50                  required => 1, },
51                { field    => FID_ITEM_ID,
52                  pat      => qr/^$item_barcode$/o,
53                  required => 1, },
54                { field    => FID_TITLE_ID,
55                  pat      => qr/^$item_title\s*$/o,
56                  required => 1, },
57                { field    => FID_DUE_DATE,
58                  pat      => $textpat,
59                  required => 1, },
60                { field    => FID_FEE_TYPE,
61                  pat      => qr/^\d{2}$/,
62                  required => 0, },
63                { field    => FID_SECURITY_INHIBIT,
64                  pat      => qr/^[YN]$/,
65                  required => 0, },
66                { field    => FID_CURRENCY,
67                  pat      => qr/^$currency$/o,
68                  required => 0, },
69                { field    => FID_FEE_AMT,
70                  pat      => qr/^[.0-9]+$/,
71                  required => 0, },
72                { field    => FID_MEDIA_TYPE,
73                  pat      => qr/^\d{3}$/,
74                  required => 0, },
75                { field    => FID_ITEM_PROPS,
76                  pat      => $textpat,
77                  required => 0, },
78                { field    => FID_TRANSACTION_ID,
79                  pat      => $textpat,
80                  required => 0, },
81                ], };
82
83 my @tests = (
84              $SIPtest::login_test,
85              $SIPtest::sc_status_test,
86              clone($checkout_test_template),
87              # Don't check the item in, because we're about to test renew
88              );
89
90 my $test;
91
92 ## Renewal OK
93 ## Test this by checking out exactly the same book a second time.
94 ## The only difference should be that the "Renewal OK" flag should now
95 ## be 'Y'.
96 #$test = clone($checkout_test_template);
97 #$test->{id} = 'Checkout: patron renewal';
98 #$test->{pat} = qr/^121YNY$datepat/;
99
100 #push @tests, $test;
101
102 # NOW check it in
103
104 push @tests, $checkin_template;
105
106 # Valid Patron, item with diacritical in the title
107 #$test = clone($checkout_test_template);
108 #
109 #$test->{id} = 'Checkout: valid patron, diacritical character in title';
110 #$test->{msg} =~ s/AB$item_barcode/AB$item_diacritic_barcode/;
111
112 #foreach my $i (0 .. (scalar @{$test->{fields}})-1) {
113 #    my $field =  $test->{fields}[$i];
114
115 #    if ($field->{field} eq FID_ITEM_ID) {
116 #       $field->{pat} = qr/^$item_diacritic_barcode$/;
117 #    } elsif ($field->{field} eq FID_TITLE_ID) {
118 #       $field->{pat} = qr/^$item_diacritic_title\s*$/;
119 #    } elsif ($field->{field} eq FID_OWNER) {
120 #       $field->{pat} = qr/^$item_diacritic_owner$/;
121 #    }
122 #}
123
124 #push @tests, $test;
125
126 #$test = clone($checkin_template);
127 #$test->{msg} =~ s/AB$item_barcode/AB$item_diacritic_barcode/;
128 #push @tests, $test;
129
130 # Valid Patron, Invalid Item_id
131 $test = clone($checkout_test_template);
132
133 $test->{id} = 'Checkout: valid patron, invalid item';
134 $test->{msg} =~ s/AB$item_barcode/ABno-barcode/o;
135 $test->{pat} = qr/^120NUN$datepat/;
136 delete $test->{fields};
137 $test->{fields} = [
138                    $SIPtest::field_specs{(FID_INST_ID)},
139                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
140                    $SIPtest::field_specs{(FID_PRINT_LINE)},
141                    { field    => FID_PATRON_ID,
142                      pat      => qr/^$user_barcode$/o,
143                      required => 1, },
144                    { field    => FID_ITEM_ID,
145                      pat      => qr/^no-barcode$/,
146                      required => 1, },
147                    { field    => FID_TITLE_ID,
148                      pat      => qr/^$/,
149                      required => 1, },
150                    { field    => FID_DUE_DATE,
151                      pat      => qr/^$/,
152                      required => 1, },
153                    { field    => FID_VALID_PATRON,
154                      pat      => qr/^Y$/,
155                      required => 1, },
156                    ];
157
158 push @tests, $test;
159
160 # Invalid patron, valid item
161 $test = clone($checkout_test_template);
162 $test->{id} = 'Checkout: invalid patron, valid item';
163 $test->{msg} =~ s/AA$user_barcode/AAberick/;
164 $test->{pat} = qr/^120NUN$datepat/;
165 delete $test->{fields};
166 $test->{fields} = [
167                    $SIPtest::field_specs{(FID_INST_ID)},
168                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
169                    $SIPtest::field_specs{(FID_PRINT_LINE)},
170                    { field    => FID_PATRON_ID,
171                      pat      => qr/^berick$/,
172                      required => 1, },
173                    { field    => FID_ITEM_ID,
174                      pat      => qr/^$item_barcode$/o,
175                      required => 1, },
176                    { field    => FID_TITLE_ID,
177                      pat      => qr/^$item_title\s*$/o,
178                      required => 1, },
179                    { field    => FID_DUE_DATE,
180                      pat      => qr/^$/,
181                      required => 1, },
182                    { field    => FID_VALID_PATRON,
183                      pat      => qr/^N$/,
184                      required => 1, },
185                    ];
186
187 push @tests, $test;
188
189 # Needed: tests for blocked patrons, patrons with excessive
190 # fines/fees, magnetic media, charging fees to borrow items.
191
192 ## Blocked patron
193 #$test = clone($checkout_test_template);
194 #$test->{id} = 'Checkout: Blocked patron';
195 #$test->{pat} = qr/^120NUN$datepat/;
196 #delete $test->{fields};
197 #$test->{fields} = [
198 #                  $SIPtest::field_specs{(FID_INST_ID)},
199 #                  $SIPtest::field_specs{(FID_SCREEN_MSG)},
200 #                  $SIPtest::field_specs{(FID_PRINT_LINE)},
201 #                  { field    => FID_PATRON_ID,
202 #                    pat      => qr/^$user_barcode$/,
203 #                    required => 1, },
204 #                  { field    => FID_VALID_PATRON,
205 #                    pat      => qr/^Y$/,
206 #                    required => 1, },
207 #                 ];
208 #
209 #push @tests, $patron_disable_template, $test, $patron_enable_template;
210 #
211 SIPtest::run_sip_tests(@tests);
212
213 1;