Merge remote-tracking branch 'origin/new/bug_6894'
[koha.git] / C4 / SIP / t / 09renew.t
1 #!/usr/bin/perl
2 # renew: test Renew 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 :item1);
11
12 my $checkout_template = {
13         id => "Renew:    prep: check out item ($item_barcode) to patron ($user_barcode)",
14         msg => "11YN20060329    203000                  AO$instid|AA$user_barcode|AB$item_barcode|AC|",
15         pat => qr/^121NNY$datepat/,
16         fields => [],
17 };
18
19 my $checkin_template = {
20         id => "Renew: cleanup: check in item ($item_barcode)",
21         msg => "09N20060102    08423620060113    084235AP$item_owner|AO$instid|AB$item_barcode|AC$password|",
22         pat => qr/^101YNN$datepat/,
23         fields => [],
24 };
25
26 # my $hold_template = {
27 # id => 'Renew: prep: place hold on item',
28 # msg =>"15+20060415    110158BW20060815    110158|BSTaylor|BY2|AO$instid|AAmiker|AB$item_barcode|",
29 # pat => qr/^161N$datepat/,
30 # fields => [],
31 # };
32 #
33 # my $cancel_hold_template = {
34 # id => 'Renew: cleanup: cancel hold on item',
35 # msg =>"15-20060415    110158BW20060815    110158|BSTaylor|BY2|AO$instid|AAmiker|AB$item_barcode|",
36 # pat => qr/^161[NY]$datepat/,
37 # fields => [],
38 # };
39 #
40
41 my $renew_test_template = {
42         id => "Renew: RENEW 1, item ($item_barcode) to patron ($user_barcode), renewal OK, no 3rd party, no fees",
43         msg => "29NN20060102    084236                  AO$instid|AA$user_barcode|AB$item_barcode|",
44         pat => qr/^301Y[UN][UN]$datepat/,
45         fields => [
46               $SIPtest::field_specs{(FID_INST_ID)},
47               $SIPtest::field_specs{(FID_SCREEN_MSG)},
48               $SIPtest::field_specs{(FID_PRINT_LINE)},
49               { field    => FID_PATRON_ID,
50                         pat      => qr/^$user_barcode$/,
51                         required => 1, },
52               { field    => FID_ITEM_ID,
53                         pat      => qr/^$item_barcode$/,
54                         required => 1, },
55               { field    => FID_TITLE_ID,
56                         pat      => qr/^$item_title\s*$/,
57                         required => 1, },
58               { field    => FID_DUE_DATE,
59                         pat      => qr/^$datepat$/,
60                         required => 1, },
61               { field    => FID_SECURITY_INHIBIT,
62                         pat      => qr/^[YN]$/,
63                         required => 0, },
64         ],
65 };
66
67 my @tests = (
68         $SIPtest::login_test,
69         $SIPtest::sc_status_test,
70         $checkout_template,
71         $renew_test_template,
72 );
73
74 SIPtest::run_sip_tests(@tests); exit;   # debug hack
75
76 my $test;
77
78 # Renew: item checked out, identify by title
79 #$test = clone($renew_test_template);
80 #$test->{id} = 'Renew: identify item by title';
81 #$test->{msg} =~ s/AB$item_barcode\|/AJ$item_title|/;
82 ## Everything else should be the same
83 #push @tests, $test;
84 #
85 ## Renew: Item checked out, but another patron has placed a hold
86 #$test = clone($renew_test_template);
87 #$test->{id} = 'Renew: Item has outstanding hold';
88 #$test->{pat} = qr/^300NUN$datepat/;
89 #foreach my $field (@{$test->{fields}}) {
90 #    if ($field->{field} eq FID_DUE_DATE || $field->{field} eq FID_TITLE_ID) {
91 #       $field->{pat} = qr/^$/;
92 #    }
93 #}
94 #
95 #push @tests, $hold_template, $test, $cancel_hold_template;
96 #
97 #
98 # Tests for impossible renewals.
99 #
100 # Renew: item not checked out.  Basically the same, except
101 # for the leader test.
102
103 $test = clone($renew_test_template);
104 $test->{id} = 'Renew: item not checked out at all';
105 $test->{pat} = qr/^300NUN$datepat/;
106 foreach my $field (@{$test->{fields}}) {
107         if ($field->{field} eq FID_DUE_DATE) {
108                 $field->{pat} = qr/^$/;
109         } elsif ($field->{field} eq FID_TITLE_ID) {
110                 $field->{pat} = qr/^($item_title\s*|)$/;
111         }
112 }
113
114 push @tests, $checkin_template, $test;
115
116 $test = clone($renew_test_template);
117 $test->{id} = 'Renew: Invalid item (bad-item)';
118 $test->{msg} =~ s/AB[^|]+/ABbad-item/;
119 $test->{pat} = qr/^300NUN$datepat/;
120 foreach my $field (@{$test->{fields}}) {
121         if ($field->{field} eq FID_TITLE_ID || $field->{field} eq FID_DUE_DATE) {
122                 $field->{pat} = qr/^$/;
123         } elsif ($field->{field} eq FID_ITEM_ID) {
124                 $field->{pat} = qr/^bad-item$/;
125         }
126 }
127
128 push @tests, $test;
129
130 $test = clone($renew_test_template);
131 $test->{id} = 'Renew: Invalid user (bad_barcode)';
132 $test->{msg} =~ s/AA$user_barcode/AAbad_barcode/;
133 $test->{pat} = qr/^300NUN$datepat/;
134 foreach my $field (@{$test->{fields}}) {
135         if ($field->{field} eq FID_DUE_DATE) {
136                 $field->{pat} = qr/^$/;
137         } elsif ($field->{field} eq FID_PATRON_ID) {
138                 $field->{pat} = qr/^bad_barcode$/;
139         } elsif ($field->{field} eq FID_TITLE_ID) {
140                 $field->{pat} = qr/^($item_title\s*|)$/;
141         }
142 }
143
144 push @tests, $test;
145
146 # Still need tests for
147 #     - renewing a for-fee item
148 #     - patrons that are not permitted to renew
149 #     - renewing item that has reached limit on number of renewals
150
151 SIPtest::run_sip_tests(@tests);
152
153 1;