Bug 22357: Do not duplicate report rows if several reports exist
[koha.git] / C4 / SIP / t / 06patron_enable.t
1 #!/usr/bin/perl
2 # patron_enable: test  Patron Enable Response
3
4 use strict;
5 use warnings;
6 use FindBin qw($Bin);
7 use lib "$Bin";
8 use Clone qw(clone);
9
10 use C4::SIP::Sip::Constants qw(:all);
11
12 use SIPtest qw(:basic :user1);
13
14 my $patron_enable_test_template = {
15     id => 'Patron Enable: valid patron',
16     msg => "2520060102    084238AOUWOLS|AA$user_barcode|",
17     pat => qr/^26 {4}[ Y]{10}000$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_PERSONAL_NAME,
26                  pat      => qr/^$user_fullname$/,
27                  required => 1, },
28                { field    => FID_VALID_PATRON,
29                  pat      => qr/^Y$/,
30                  # Not required by the spec, but by the test
31                  required => 1, },
32                ], };
33
34 # We need to disable the valid patron before we can
35 # ensure that they were properly enabled.
36 my $patron_disable_test_template = {
37     id => 'Patron Enable: block patron (prep to test enabling)',
38     msg => "01N20060102    084238AO$instid|ALBlocked patron for SIP test.|AA$user_barcode|",
39     # response to block patron is a patron status message
40     pat => qr/^24Y{4}[ Y]{10}000$datepat/,
41     fields => [
42                $SIPtest::field_specs{(FID_INST_ID)},
43                { field    => FID_PATRON_ID,
44                  pat      => qr/^$user_barcode$/,
45                  required => 1, },
46                { field    => FID_PERSONAL_NAME,
47                  pat      => qr/^$user_fullname$/,
48                  required => 1, },
49                { field    => FID_VALID_PATRON,
50                  pat      => qr/^Y$/,
51                  # Not required by the spec, but by the test
52                  required => 1, },
53                ], };
54
55 my @tests = (
56              $SIPtest::login_test,
57              $SIPtest::sc_status_test,
58              $patron_disable_test_template,
59              clone($patron_enable_test_template),
60              );
61
62 my $test;
63
64 # Valid patron, valid password
65 $test = clone($patron_enable_test_template);
66 $test->{id} = "Patron Enable: valid patron, valid password";
67 $test->{msg} .= FID_PATRON_PWD . "$user_pin|";
68 $test->{pat} = qr/^26 {4}[ Y]{10}000$datepat/;
69 delete $test->{fields};
70 $test->{fields} = [
71                    $SIPtest::field_specs{(FID_INST_ID)},
72                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
73                    $SIPtest::field_specs{(FID_PRINT_LINE)},
74                    { field    => FID_PATRON_ID,
75                      pat      => qr/^$user_barcode$/,
76                      required => 1, },
77                    { field    => FID_PERSONAL_NAME,
78                      pat      => qr/^$user_fullname$/,
79                      required => 1, },
80                    { field    => FID_VALID_PATRON,
81                      pat      => qr/^Y$/,
82                      # Not required by the spec, but by the test
83                      required => 1, },
84                    { field    => FID_VALID_PATRON_PWD,
85                      pat      => qr/^Y$/,
86                      required => 1, },
87                    ];
88
89 push @tests, $patron_disable_test_template, $test;
90
91 # Valid patron, invalid password
92 $test = clone($patron_enable_test_template);
93 $test->{id} = "Patron Enable: valid patron, invalid password";
94 $test->{msg} .= FID_PATRON_PWD . 'bad password|';
95 $test->{pat} = qr/^26[ Y]{14}000$datepat/;
96 delete $test->{fields};
97 $test->{fields} = [
98                    $SIPtest::field_specs{(FID_INST_ID)},
99                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
100                    $SIPtest::field_specs{(FID_PRINT_LINE)},
101                    { field    => FID_PATRON_ID,
102                      pat      => qr/^$user_barcode$/,
103                      required => 1, },
104                    { field    => FID_PERSONAL_NAME,
105                      pat      => qr/^$user_fullname$/,
106                      required => 1, },
107                    { field    => FID_VALID_PATRON,
108                      pat      => qr/^Y$/,
109                      # Not required by the spec, but by the test
110                      required => 1, },
111                    { field    => FID_VALID_PATRON_PWD,
112                      pat      => qr/^N$/,
113                      required => 1, },
114                    ];
115
116 push @tests, $patron_disable_test_template, $test;
117 # After this test, the patron is left disabled, so re-enable
118 push @tests, $patron_enable_test_template;
119
120 # Invalid patron
121 $test = clone($patron_enable_test_template);
122 $test->{id} =~ s/valid/invalid/;
123 $test->{msg} =~ s/AA$user_barcode\|/AAbad_barcode|/;
124 $test->{pat} =  qr/^26Y{4}[ Y]{10}000$datepat/;
125 delete $test->{fields};
126 $test->{fields} = [
127                    $SIPtest::field_specs{(FID_INST_ID)},
128                    $SIPtest::field_specs{(FID_SCREEN_MSG)},
129                    $SIPtest::field_specs{(FID_PRINT_LINE)},
130                    { field    => FID_PATRON_ID,
131                      pat      => qr/^bad_barcode$/,
132                      required => 1, },
133                    { field    => FID_PERSONAL_NAME,
134                      pat      => qr/^$/,
135                      required => 1, },
136                    { field    => FID_VALID_PATRON,
137                      pat      => qr/^N$/,
138                      # Not required by the spec, but by the test
139                      required => 1, },
140                    ];
141
142 push @tests, $test;
143
144 SIPtest::run_sip_tests(@tests);
145
146 1;