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