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