Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2020 Hypernova Oy |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 1; |
23 |
|
24 |
use C4::Circulation; |
25 |
use Koha::Database; |
26 |
|
27 |
use t::lib::Mocks; |
28 |
use t::lib::TestBuilder; |
29 |
|
30 |
my $schema = Koha::Database->new->schema; |
31 |
my $builder = t::lib::TestBuilder->new; |
32 |
|
33 |
subtest 'test renewals' => sub { |
34 |
plan tests => 7; |
35 |
|
36 |
$schema->storage->txn_begin; |
37 |
|
38 |
t::lib::Mocks::mock_preference( 'OnSiteCheckouts', 1 ); |
39 |
t::lib::Mocks::mock_preference( 'SwitchOnSiteCheckouts', 0 ); |
40 |
|
41 |
Koha::CirculationRules->search->delete; |
42 |
Koha::CirculationRules->set_rule( |
43 |
{ |
44 |
categorycode => undef, |
45 |
branchcode => undef, |
46 |
itemtype => undef, |
47 |
rule_name => 'onsite_renewalsallowed', |
48 |
rule_value => '0', |
49 |
} |
50 |
); |
51 |
|
52 |
my $librarian = mock_librarian_env(); |
53 |
my $test_data = build_test_data(); |
54 |
my $patron = $test_data->{patron}; |
55 |
my $item = $test_data->{item}; |
56 |
my $library = $test_data->{library}; |
57 |
|
58 |
my $checkout = C4::Circulation::AddIssue( |
59 |
$patron->unblessed, $item->barcode, |
60 |
undef, undef, undef, undef, { onsite_checkout => 1 } |
61 |
); |
62 |
|
63 |
is( $checkout->onsite_checkout, 1, 'Created an on-site checkout' ); |
64 |
my ( $can_renew, $error ) = CanBookBeRenewed( |
65 |
$patron->borrowernumber, $item->itemnumber |
66 |
); |
67 |
is ( $can_renew, 0, 'Checkout cannot be renewed...' ); |
68 |
is ( $error, 'too_many', '..because onsite_renewalsallowed = 0' ); |
69 |
|
70 |
Koha::CirculationRules->set_rule( |
71 |
{ |
72 |
categorycode => undef, |
73 |
branchcode => undef, |
74 |
itemtype => undef, |
75 |
rule_name => 'onsite_renewalsallowed', |
76 |
rule_value => '1', |
77 |
} |
78 |
); |
79 |
|
80 |
( $can_renew, $error ) = CanBookBeRenewed( |
81 |
$patron->borrowernumber, $item->itemnumber |
82 |
); |
83 |
is ( $can_renew, 1, 'After onsite_renewalsallowed = 1, we can now renew' ); |
84 |
|
85 |
ok ( AddRenewal( $patron->id, $item->id, $library->id ), 'Renewal success' ); |
86 |
|
87 |
( $can_renew, $error ) = CanBookBeRenewed( |
88 |
$patron->borrowernumber, $item->itemnumber |
89 |
); |
90 |
is ( $can_renew, 0, 'Now, checkout cannot be renewed...' ); |
91 |
is ( $error, 'too_many', '..because we have exceeded max renewals' ); |
92 |
|
93 |
$schema->storage->txn_rollback; |
94 |
}; |
95 |
|
96 |
sub build_test_data { |
97 |
my $library = $builder->build_object({ |
98 |
class => 'Koha::Libraries', |
99 |
}); |
100 |
|
101 |
my $patron = $builder->build_object({ |
102 |
class => 'Koha::Patrons' |
103 |
}); |
104 |
|
105 |
my $itemtype = $builder->build_object({ |
106 |
class => 'Koha::ItemTypes', |
107 |
value => { |
108 |
notforloan => undef, |
109 |
rentalcharge => 0, |
110 |
rentalcharge_daily => 0, |
111 |
defaultreplacecost => undef, |
112 |
processfee => undef |
113 |
} |
114 |
}); |
115 |
|
116 |
my $biblio = $builder->build_sample_biblio(); |
117 |
my $item = $builder->build_sample_item({ |
118 |
biblionumber => $biblio->biblionumber, |
119 |
library => $library->branchcode, |
120 |
replacementprice => 12.00, |
121 |
itype => $itemtype->itemtype |
122 |
}); |
123 |
|
124 |
return { |
125 |
biblio => $biblio, |
126 |
item => $item, |
127 |
itemtype => $itemtype, |
128 |
library => $library, |
129 |
patron => $patron, |
130 |
}; |
131 |
} |
132 |
|
133 |
sub mock_librarian_env { |
134 |
my $librarian = $builder->build_object({ |
135 |
class => 'Koha::Patrons', |
136 |
value => { |
137 |
flags => 1 |
138 |
} |
139 |
}); |
140 |
t::lib::Mocks::mock_userenv({ |
141 |
patron => $librarian, |
142 |
branchcode => $librarian->branchcode |
143 |
}); |
144 |
return $librarian; |
145 |
} |