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