Bug 18578: Use subdirectory in /tmp for session storage during installation
[koha.git] / C4 / SIP / t / 02patron_info.t
blobff332129cd679e28d33c5e58423c0a3855af6061
1 #!/usr/bin/perl
2 # patron_info: test Patron Information 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);
14 # This is a template test case for the Patron Information
15 # message handling. Because of the large number of fields,
16 # this template forms the basis for all of the different
17 # situations: valid patron no details, valid patron with each
18 # individual detail requested, invalid patron, invalid patron
19 # password, etc.
20 our $patron_info_test_template = {
21 id => 'valid Patron Info no details',
22 msg => "6300020060329 201700 AO$instid|AA$user_barcode|",
23 pat => qr/^64 [ Y]{13}\d{3}$datepat(\d{4}){6}/,
24 fields => [
25 $SIPtest::field_specs{(FID_INST_ID)},
26 $SIPtest::field_specs{(FID_SCREEN_MSG)},
27 $SIPtest::field_specs{(FID_PRINT_LINE)},
28 { field => FID_PATRON_ID,
29 pat => qr/^$user_barcode$/o,
30 required => 1, },
31 { field => FID_PERSONAL_NAME,
32 pat => qr/^$user_fullname$/o,
33 required => 1, },
34 $SIPtest::field_specs{(FID_HOLD_ITEMS_LMT)},
35 $SIPtest::field_specs{(FID_OVERDUE_ITEMS_LMT)},
36 $SIPtest::field_specs{(FID_CHARGED_ITEMS_LMT)},
37 { field => FID_VALID_PATRON,
38 pat => qr/^Y$/,
39 # Not required by the spec, but by the test
40 required => 1, },
41 $SIPtest::field_specs{(FID_CURRENCY)},
42 { field => FID_FEE_AMT,
43 pat => $textpat,
44 required => 0, },
45 { field => FID_FEE_LMT,
46 pat => $textpat,
47 required => 0, },
48 { field => FID_HOME_ADDR,
49 pat => qr/^$user_homeaddr$/o,
50 required => 1, }, # required by this test case
51 { field => FID_EMAIL,
52 pat => qr/^$user_email$/o,
53 required => 1, },
54 { field => FID_HOME_PHONE,
55 pat => qr/^$user_phone$/o,
56 required => 1, },
57 { field => FID_PATRON_BIRTHDATE,
58 pat => qr/^$user_birthday$/o,
59 required => 1, },
60 { field => FID_PATRON_CLASS,
61 pat => qr/^$user_ptype$/o,
62 required => 1, },
63 { field => FID_INET_PROFILE,
64 pat => qr/^$user_inet$/,
65 required => 1, },
66 ], };
68 our @tests = (
69 $SIPtest::login_test,
70 $SIPtest::sc_status_test,
71 clone($patron_info_test_template),
75 # Create the test cases for the various summary detail fields
76 sub create_patron_summary_tests {
77 my $test;
78 my @patron_info_summary_tests = (
79 { field => FID_HOLD_ITEMS,
80 pat => $textpat,
81 required => 0, },
82 { field => FID_OVERDUE_ITEMS,
83 pat => $textpat,
84 required => 0, },
85 { field => FID_CHARGED_ITEMS,
86 pat => $textpat,
87 required => 0, },
88 # The test user has no items of these types, so the tests seem to fail
89 # { field => FID_FINE_ITEMS,
90 # pat => $textpat,
91 # required => 1, },
92 # { field => FID_RECALL_ITEMS,
93 # pat => $textpat,
94 # required => 0, },
95 # { field => FID_UNAVAILABLE_HOLD_ITEMS,
96 # pat => $textpat,
97 # required => 0, },
100 foreach my $i (0 .. scalar @patron_info_summary_tests-1) {
101 # The tests for each of the summary fields are exactly the
102 # same as the basic one, except for the fact that there's
103 # an extra field to test
105 # Copy the hash, adjust it, add it to the end of the list
106 $test = clone($patron_info_test_template);
108 substr($test->{msg}, 23+$i, 1) = 'Y';
109 $test->{id} = "valid Patron Info details: "
110 . $patron_info_summary_tests[$i]->{field};
111 push @{$test->{fields}}, $patron_info_summary_tests[$i];
112 push @tests, $test;
116 sub create_invalid_patron_tests {
117 my $test;
119 $test = clone($patron_info_test_template);
120 $test->{id} = "invalid Patron Info id";
121 $test->{msg} =~ s/AA$user_barcode\|/AAberick|/o;
122 $test->{pat} = qr/^64Y[ Y]{13}\d{3}$datepat(\d{4}){6}/;
123 delete $test->{fields};
124 $test->{fields} = [
125 $SIPtest::field_specs{(FID_INST_ID)},
126 $SIPtest::field_specs{(FID_SCREEN_MSG)},
127 $SIPtest::field_specs{(FID_PRINT_LINE)},
128 { field => FID_PATRON_ID,
129 pat => qr/^berick$/,
130 required => 1, },
131 { field => FID_PERSONAL_NAME,
132 pat => qr/^$/,
133 required => 1, },
134 { field => FID_VALID_PATRON,
135 pat => qr/^N$/,
136 required => 1, },
138 push @tests, $test;
140 # Valid patron, invalid patron password
141 $test = clone($patron_info_test_template);
142 $test->{id} = "valid Patron Info, invalid password";
143 $test->{msg} .= (FID_PATRON_PWD) . 'badpwd|';
144 $test->{pat} = qr/^64[ Y]{14}\d{3}$datepat(\d{4}){6}/;
145 delete $test->{fields};
146 $test->{fields} = [
147 $SIPtest::field_specs{(FID_INST_ID)},
148 $SIPtest::field_specs{(FID_SCREEN_MSG)},
149 $SIPtest::field_specs{(FID_PRINT_LINE)},
150 { field => FID_PATRON_ID,
151 pat => qr/^$user_barcode$/,
152 required => 1, },
153 { field => FID_PERSONAL_NAME,
154 pat => qr/^$user_fullname$/,
155 required => 1, },
156 { field => FID_VALID_PATRON,
157 pat => qr/^Y$/,
158 required => 1, },
159 { field => FID_VALID_PATRON_PWD,
160 pat => qr/^N$/,
161 required => 1, },
163 push @tests, $test;
166 create_patron_summary_tests;
167 create_invalid_patron_tests;
168 SIPtest::run_sip_tests(@tests);