Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright Koha-Suomi Oy 2016 |
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 |
use Test::More tests => 20; |
22 |
use t::lib::Mocks; |
23 |
use t::lib::TestBuilder; |
24 |
require t::db_dependent::Koha::Availability::Helpers; |
25 |
|
26 |
use C4::Members; |
27 |
|
28 |
use Koha::Account::Lines; |
29 |
use Koha::Biblioitems; |
30 |
use Koha::Database; |
31 |
use Koha::DateUtils; |
32 |
use Koha::Items; |
33 |
|
34 |
use Koha::Availability::Checks::Patron; |
35 |
|
36 |
my $schema = Koha::Database->new->schema; |
37 |
$schema->storage->txn_begin; |
38 |
|
39 |
my $dbh = C4::Context->dbh; |
40 |
$dbh->{RaiseError} = 1; |
41 |
|
42 |
my $builder = t::lib::TestBuilder->new; |
43 |
|
44 |
set_default_system_preferences(); |
45 |
set_default_circulation_rules(); |
46 |
|
47 |
subtest 'debarred, given patron is not debarred' => \&t_not_debarred; |
48 |
sub t_not_debarred { |
49 |
plan tests => 3; |
50 |
|
51 |
my $patron = build_a_test_patron(); |
52 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
53 |
my $expecting = 'Koha::Exceptions::Patron::Debarred'; |
54 |
|
55 |
is($patron->debarred, undef, 'Patron is not debarred.'); |
56 |
is($patron->debarredcomment, undef, 'Patron does not have debarment comment.'); |
57 |
ok(!$patroncalc->debarred, 'When I check patron debarment, then no exception is given.'); |
58 |
}; |
59 |
|
60 |
subtest 'debarred, given patron is debarred' => \&t_debarred; |
61 |
sub t_debarred { |
62 |
plan tests => 5; |
63 |
|
64 |
my $patron = build_a_test_patron(); |
65 |
my $hundred_days = output_pref({ dt => dt_from_string()->add_duration( |
66 |
DateTime::Duration->new(days => 100)), dateformat => 'iso', dateonly => 1 }); |
67 |
$patron->set({ debarred => $hundred_days, debarredcomment => 'DONT EVER COME BACK' })->store; |
68 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
69 |
my $expecting = 'Koha::Exceptions::Patron::Debarred'; |
70 |
my $debarred = $patroncalc->debarred; |
71 |
|
72 |
is($patron->debarred, $hundred_days, "Patron is debarred until $hundred_days."); |
73 |
is($patron->debarredcomment, 'DONT EVER COME BACK', 'Library does not want them to ever come back.'); |
74 |
is(ref($debarred), $expecting, "When I check patron debarment, then $expecting is given."); |
75 |
is($debarred->expiration, $patron->debarred, 'Then, from the status, I can see the expiration date.'); |
76 |
is($debarred->comment, $patron->debarredcomment, 'Then, from the status, I can see that patron should never come back.'); |
77 |
}; |
78 |
|
79 |
subtest 'debt_checkout, given patron has less than noissuescharge' => \&t_fines_checkout_less_than_max; |
80 |
sub t_fines_checkout_less_than_max { |
81 |
plan tests => 8; |
82 |
|
83 |
t::lib::Mocks::mock_preference('noissuescharge', 9001); |
84 |
t::lib::Mocks::mock_preference('AllFinesNeedOverride', 0); |
85 |
|
86 |
my $patron = build_a_test_patron(); |
87 |
my $line = Koha::Account::Line->new({ |
88 |
borrowernumber => $patron->borrowernumber, |
89 |
amountoutstanding => 9000, |
90 |
})->store; |
91 |
my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber); |
92 |
my $maxoutstanding = C4::Context->preference('noissuescharge'); |
93 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
94 |
my $debt = $patroncalc->debt_checkout; |
95 |
|
96 |
is(C4::Context->preference('AllFinesNeedOverride'), 0, 'Not all fines need override.'); |
97 |
ok($maxoutstanding, 'When I look at system preferences, I see that maximum allowed outstanding fines is set.'); |
98 |
ok($maxoutstanding > $outstanding, 'When I check patron\'s balance, I found out they have less outstanding fines than maximum allowed.'); |
99 |
ok(!$debt, 'When I check patron debt, then no exception is given.'); |
100 |
t::lib::Mocks::mock_preference('AllFinesNeedOverride', 1); |
101 |
is(C4::Context->preference('AllFinesNeedOverride'), 1, 'Given we configure' |
102 |
.' all fines needing override.'); |
103 |
$debt = $patroncalc->debt_checkout; |
104 |
my $expecting = 'Koha::Exceptions::Patron::Debt'; |
105 |
is(ref($debt), $expecting, "When I check patron debt, then $expecting is given."); |
106 |
is($debt->max_outstanding, $maxoutstanding, 'Then I can see the status showing me how much' |
107 |
.' outstanding total can be at maximum.'); |
108 |
is($debt->current_outstanding, $outstanding, 'Then I can see the status showing me how much' |
109 |
.' outstanding fines patron has right now.'); |
110 |
}; |
111 |
|
112 |
subtest 'debt_checkout, given patron has more than noissuescharge' => \&t_fines_checkout_more_than_max; |
113 |
sub t_fines_checkout_more_than_max { |
114 |
plan tests => 5; |
115 |
|
116 |
t::lib::Mocks::mock_preference('noissuescharge', 5); |
117 |
|
118 |
my $patron = build_a_test_patron(); |
119 |
my $line = Koha::Account::Line->new({ |
120 |
borrowernumber => $patron->borrowernumber, |
121 |
amountoutstanding => 9001, |
122 |
})->store; |
123 |
my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber); |
124 |
my $maxoutstanding = C4::Context->preference('noissuescharge'); |
125 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
126 |
my $debt = $patroncalc->debt_checkout; |
127 |
my $expecting = 'Koha::Exceptions::Patron::Debt'; |
128 |
|
129 |
ok($maxoutstanding, 'When I look at system preferences, I see that maximum allowed outstanding fines is set.'); |
130 |
ok($maxoutstanding < $outstanding, 'When I check patron\'s balance, I found out they have more outstanding fines than allowed.'); |
131 |
is(ref($debt), $expecting, "When I check patron debt, then $expecting is given."); |
132 |
is($debt->max_outstanding, $maxoutstanding, 'Then I can see the status showing me how much' |
133 |
.' outstanding total can be at maximum.'); |
134 |
is($debt->current_outstanding, $outstanding, 'Then I can see the status showing me how much' |
135 |
.' outstanding fines patron has right now.'); |
136 |
}; |
137 |
|
138 |
subtest 'debt_hold, given patron has less than maxoutstanding' => \&t_fines_hold_less_than_max; |
139 |
sub t_fines_hold_less_than_max { |
140 |
plan tests => 3; |
141 |
|
142 |
t::lib::Mocks::mock_preference('maxoutstanding', 9001); |
143 |
|
144 |
my $patron = build_a_test_patron(); |
145 |
my $line = Koha::Account::Line->new({ |
146 |
borrowernumber => $patron->borrowernumber, |
147 |
amountoutstanding => 9000, |
148 |
})->store; |
149 |
my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber); |
150 |
my $maxoutstanding = C4::Context->preference('maxoutstanding'); |
151 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
152 |
my $debt = $patroncalc->debt_hold; |
153 |
|
154 |
ok($maxoutstanding, 'When I look at system preferences, I see that maximum allowed outstanding fines is set.'); |
155 |
ok($maxoutstanding > $outstanding, 'When I check patron\'s balance, I found out they have less outstanding fines than maximum allowed.'); |
156 |
ok(!$debt, 'When I check patron debt, then no exception is given.'); |
157 |
}; |
158 |
|
159 |
subtest 'debt_hold, given patron has more than maxoutstanding' => \&t_fines_hold_more_than_max; |
160 |
sub t_fines_hold_more_than_max { |
161 |
plan tests => 5; |
162 |
|
163 |
t::lib::Mocks::mock_preference('maxoutstanding', 5); |
164 |
|
165 |
my $patron = build_a_test_patron(); |
166 |
my $line = Koha::Account::Line->new({ |
167 |
borrowernumber => $patron->borrowernumber, |
168 |
amountoutstanding => 9001, |
169 |
})->store; |
170 |
my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber); |
171 |
my $maxoutstanding = C4::Context->preference('maxoutstanding'); |
172 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
173 |
my $debt = $patroncalc->debt_hold; |
174 |
my $expecting = 'Koha::Exceptions::Patron::Debt'; |
175 |
|
176 |
ok($maxoutstanding, 'When I look at system preferences, I see that maximum allowed outstanding fines is set.'); |
177 |
ok($maxoutstanding < $outstanding, 'When I check patron\'s balance, I found out they have more outstanding fines than allowed.'); |
178 |
is(ref($debt), $expecting, "When I check patron debt, then $expecting is given."); |
179 |
is($debt->max_outstanding, $maxoutstanding, 'Then I can see the status showing me how much' |
180 |
.' outstanding total can be at maximum.'); |
181 |
is($debt->current_outstanding, $outstanding, 'Then I can see the status showing me how much' |
182 |
.' outstanding fines patron has right now.'); |
183 |
}; |
184 |
|
185 |
subtest 'debt_renew_opac, given patron has less than OPACFineNoRenewals' => \&t_fines_renew_opac_less_than_max; |
186 |
sub t_fines_renew_opac_less_than_max { |
187 |
plan tests => 3; |
188 |
|
189 |
t::lib::Mocks::mock_preference('OPACFineNoRenewals', 9001); |
190 |
|
191 |
my $patron = build_a_test_patron(); |
192 |
my $line = Koha::Account::Line->new({ |
193 |
borrowernumber => $patron->borrowernumber, |
194 |
amountoutstanding => 9000, |
195 |
})->store; |
196 |
my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber); |
197 |
my $maxoutstanding = C4::Context->preference('OPACFineNoRenewals'); |
198 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
199 |
my $debt = $patroncalc->debt_renew_opac; |
200 |
|
201 |
ok($maxoutstanding, 'When I look at system preferences, I see that maximum allowed outstanding fines is set.'); |
202 |
ok($maxoutstanding > $outstanding, 'When I check patron\'s balance, I found out they have less outstanding fines than maximum allowed.'); |
203 |
ok(!$debt, 'When I check patron debt, then no exception is given.'); |
204 |
}; |
205 |
|
206 |
subtest 'debt_renew_opac, given patron has more than OPACFineNoRenewals' => \&t_fines_renew_opac_more_than_max; |
207 |
sub t_fines_renew_opac_more_than_max { |
208 |
plan tests => 5; |
209 |
|
210 |
t::lib::Mocks::mock_preference('OPACFineNoRenewals', 5); |
211 |
|
212 |
my $patron = build_a_test_patron(); |
213 |
my $line = Koha::Account::Line->new({ |
214 |
borrowernumber => $patron->borrowernumber, |
215 |
amountoutstanding => 9001, |
216 |
})->store; |
217 |
my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber); |
218 |
my $maxoutstanding = C4::Context->preference('OPACFineNoRenewals'); |
219 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
220 |
my $debt = $patroncalc->debt_renew_opac; |
221 |
my $expecting = 'Koha::Exceptions::Patron::Debt'; |
222 |
|
223 |
ok($maxoutstanding, 'When I look at system preferences, I see that maximum allowed outstanding fines is set.'); |
224 |
ok($maxoutstanding < $outstanding, 'When I check patron\'s balance, I found out they have more outstanding fines than allowed.'); |
225 |
is(ref($debt), $expecting, "When I check patron debt, then $expecting is given."); |
226 |
is($debt->max_outstanding, $maxoutstanding, 'Then I can see the status showing me how much' |
227 |
.' outstanding total can be at maximum.'); |
228 |
is($debt->current_outstanding, $outstanding, 'Then I can see the status showing me how much' |
229 |
.' outstanding fines patron has right now.'); |
230 |
}; |
231 |
|
232 |
subtest 'debt_checkout_guarantees, given patron\'s guarantees have less than NoIssuesChargeGuarantees' => \&t_guarantees_fines_checkout_less_than_max; |
233 |
sub t_guarantees_fines_checkout_less_than_max { |
234 |
plan tests => 3; |
235 |
|
236 |
t::lib::Mocks::mock_preference('NoIssuesChargeGuarantees', 5); |
237 |
|
238 |
my $patron = build_a_test_patron(); |
239 |
my $guarantee1 = build_a_test_patron(); |
240 |
$guarantee1->guarantorid($patron->borrowernumber)->store; |
241 |
my $guarantee2 = build_a_test_patron(); |
242 |
$guarantee2->guarantorid($patron->borrowernumber)->store; |
243 |
my $line1 = Koha::Account::Line->new({ |
244 |
borrowernumber => $guarantee1->borrowernumber, |
245 |
amountoutstanding => 2, |
246 |
})->store; |
247 |
my $line2 = Koha::Account::Line->new({ |
248 |
borrowernumber => $guarantee2->borrowernumber, |
249 |
amountoutstanding => 2, |
250 |
})->store; |
251 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
252 |
my $debt = $patroncalc->debt_checkout_guarantees; |
253 |
|
254 |
ok($line1, 'We have added very small fines to patron\'s guarantees.'); |
255 |
ok($line1->amountoutstanding+$line2->amountoutstanding < C4::Context->preference('NoIssuesChargeGuarantees'), |
256 |
'These fines total is less than NoIssuesChargeGuarantees'); |
257 |
ok(!$debt, 'When I check patron guarantees debt, then no exception is given.'); |
258 |
}; |
259 |
|
260 |
subtest 'debt_checkout_guarantees, given patron\s guarantees have more than NoIssuesChargeGuarantees' => \&t_guarantees_fines_checkout_more_than_max; |
261 |
sub t_guarantees_fines_checkout_more_than_max { |
262 |
plan tests => 5; |
263 |
|
264 |
t::lib::Mocks::mock_preference('NoIssuesChargeGuarantees', 5); |
265 |
|
266 |
my $patron = build_a_test_patron(); |
267 |
my $guarantee1 = build_a_test_patron(); |
268 |
$guarantee1->guarantorid($patron->borrowernumber)->store; |
269 |
my $guarantee2 = build_a_test_patron(); |
270 |
$guarantee2->guarantorid($patron->borrowernumber)->store; |
271 |
my $line1 = Koha::Account::Line->new({ |
272 |
borrowernumber => $guarantee1->borrowernumber, |
273 |
amountoutstanding => 3, |
274 |
})->store; |
275 |
my $line2 = Koha::Account::Line->new({ |
276 |
borrowernumber => $guarantee2->borrowernumber, |
277 |
amountoutstanding => 3, |
278 |
})->store; |
279 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
280 |
my $debt = $patroncalc->debt_checkout_guarantees; |
281 |
my $expecting = 'Koha::Exceptions::Patron::DebtGuarantees'; |
282 |
|
283 |
ok($line1, 'We have added very small fines to patron\'s guarantees.'); |
284 |
ok($line1->amountoutstanding+$line2->amountoutstanding > C4::Context->preference('NoIssuesChargeGuarantees'), |
285 |
'These fines total is more than NoIssuesChargeGuarantees'); |
286 |
is(ref($debt), $expecting, "When I check patron guarantees debt, then $expecting is given."); |
287 |
is($debt->max_outstanding, 5, 'Then I can see the status showing me how much' |
288 |
.' outstanding total can be at maximum.'); |
289 |
is($debt->current_outstanding, 6, 'Then I can see the status showing me how much' |
290 |
.' outstanding fines patron guarantees have right now.'); |
291 |
}; |
292 |
|
293 |
subtest 'exceeded_maxreserves, given patron not exceeding max reserves' => \&t_exceeded_maxreserves_not; |
294 |
sub t_exceeded_maxreserves_not { |
295 |
plan tests => 2; |
296 |
|
297 |
my $patron = build_a_test_patron(); |
298 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
299 |
my $holds = Koha::Holds->search({ borrowernumber => $patron->borrowernumber }); |
300 |
|
301 |
is($holds->count, 0, 'Patron has no holds.'); |
302 |
ok(!$patroncalc->exceeded_maxreserves, 'When I check if patron exceeded maxreserves, then no exception is given.'); |
303 |
}; |
304 |
|
305 |
subtest 'exceeded_maxreserves, given patron exceeding max reserves' => \&t_exceeded_maxreserves; |
306 |
sub t_exceeded_maxreserves { |
307 |
plan tests => 5; |
308 |
|
309 |
t::lib::Mocks::mock_preference('maxreserves', 1); |
310 |
|
311 |
my $item = build_a_test_item(); |
312 |
my $item2 = build_a_test_item(); |
313 |
my $patron = build_a_test_patron(); |
314 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
315 |
add_biblio_level_hold($item, $patron, $patron->branchcode); |
316 |
add_biblio_level_hold($item2, $patron, $patron->branchcode); |
317 |
my $holds = Koha::Holds->search({ borrowernumber => $patron->borrowernumber }); |
318 |
my $expecting = 'Koha::Exceptions::Hold::MaximumHoldsReached'; |
319 |
my $exceeded = $patroncalc->exceeded_maxreserves; |
320 |
|
321 |
is(C4::Context->preference('maxreserves'), 1, 'Maximum number of holds allowed is one.'); |
322 |
is($holds->count, 2, 'Patron has two holds.'); |
323 |
is(ref($exceeded), $expecting, "When I check patron expiration, then $expecting is given."); |
324 |
is($exceeded->max_holds_allowed, 1, 'Then I can see the status showing me how many' |
325 |
.' holds are allowed at max.'); |
326 |
is($exceeded->current_hold_count, 2, 'Then I can see the status showing me how many' |
327 |
.' holds patron has right now.'); |
328 |
}; |
329 |
|
330 |
subtest 'expired, given patron is not expired' => \&t_not_expired; |
331 |
sub t_not_expired { |
332 |
plan tests => 2; |
333 |
|
334 |
my $patron = build_a_test_patron(); |
335 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
336 |
my $dt_expiry = dt_from_string($patron->dateexpiry); |
337 |
my $now = DateTime->now(time_zone => C4::Context->tz); |
338 |
|
339 |
is(DateTime->compare($dt_expiry, $now), 1, 'Patron is not expired.'); |
340 |
ok(!$patroncalc->expired, 'When I check patron expiration, then no exception is given.'); |
341 |
}; |
342 |
|
343 |
subtest 'expired, given patron is expired' => \&t_expired; |
344 |
sub t_expired { |
345 |
plan tests => 2; |
346 |
|
347 |
my $patron = build_a_test_patron(); |
348 |
$patron->dateexpiry('1999-10-10')->store; |
349 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
350 |
my $dt_expiry = dt_from_string($patron->dateexpiry); |
351 |
my $now = DateTime->now(time_zone => C4::Context->tz); |
352 |
my $expecting = 'Koha::Exceptions::Patron::CardExpired'; |
353 |
|
354 |
is(DateTime->compare($now, $dt_expiry), 1, 'Patron finds out their card is expired.'); |
355 |
is(ref($patroncalc->expired), $expecting, "When I check patron expiration, then $expecting is given."); |
356 |
}; |
357 |
|
358 |
subtest 'gonenoaddress, patron not gonenoaddress' => \&t_not_gonenoaddress; |
359 |
sub t_not_gonenoaddress { |
360 |
plan tests => 2; |
361 |
|
362 |
my $patron = build_a_test_patron(); |
363 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
364 |
|
365 |
ok(!$patron->gonenoaddress, 'Patron is not gonenoaddress.'); |
366 |
ok(!$patroncalc->gonenoaddress, 'When I check patron gonenoaddress, then no exception is given.'); |
367 |
}; |
368 |
|
369 |
subtest 'gonenoaddress, patron gonenoaddress' => \&t_gonenoaddress; |
370 |
sub t_gonenoaddress { |
371 |
plan tests => 2; |
372 |
|
373 |
my $patron = build_a_test_patron(); |
374 |
$patron->gonenoaddress('1')->store; |
375 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
376 |
my $expecting = 'Koha::Exceptions::Patron::GoneNoAddress'; |
377 |
|
378 |
is($patron->gonenoaddress, 1, 'Patron is gonenoaddress.'); |
379 |
is(ref($patroncalc->gonenoaddress), $expecting, "When I check patron gonenoaddress, then $expecting is given."); |
380 |
}; |
381 |
|
382 |
subtest 'lost, patron card not lost' => \&t_not_lost; |
383 |
sub t_not_lost { |
384 |
plan tests => 2; |
385 |
|
386 |
my $patron = build_a_test_patron(); |
387 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
388 |
|
389 |
ok(!$patron->lost, 'Patron card is not lost.'); |
390 |
ok(!$patroncalc->lost, 'When I check if patron card is lost, then no exception is given.'); |
391 |
}; |
392 |
|
393 |
subtest 'lost, patron card lost' => \&t_lost; |
394 |
sub t_lost { |
395 |
plan tests => 2; |
396 |
|
397 |
my $patron = build_a_test_patron(); |
398 |
$patron->lost('1')->store; |
399 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
400 |
my $expecting = 'Koha::Exceptions::Patron::CardLost'; |
401 |
|
402 |
is($patron->lost, 1, 'Patron card is lost.'); |
403 |
is(ref($patroncalc->lost), $expecting, "When I check if patron card is lost, then $expecting is given."); |
404 |
}; |
405 |
|
406 |
subtest 'from_another_library, patron from same branch than me' => \&t_from_another_library_same_branch; |
407 |
sub t_from_another_library_same_branch { |
408 |
plan tests => 2; |
409 |
|
410 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
411 |
|
412 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
413 |
|
414 |
C4::Context->_new_userenv('xxx'); |
415 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $branchcode, 'Midway Public Library', '', '', ''); |
416 |
|
417 |
my $patron = build_a_test_patron(); |
418 |
$patron->branchcode($branchcode)->store; |
419 |
|
420 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
421 |
|
422 |
is(C4::Context->userenv->{branch}, $patron->branchcode, 'Patron is from same branch as me.'); |
423 |
ok(!$patroncalc->from_another_library, 'When I check if patron is' |
424 |
.' from same branch as me, then no exception is given.'); |
425 |
} |
426 |
|
427 |
subtest 'from_another_library, patron from different branch than me' => \&t_from_another_library; |
428 |
sub t_from_another_library { |
429 |
plan tests => 2; |
430 |
|
431 |
t::lib::Mocks::mock_preference('IndependentBranches', 1); |
432 |
|
433 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
434 |
my $branchcode2 = $builder->build({ source => 'Branch' })->{'branchcode'}; |
435 |
|
436 |
C4::Context->_new_userenv('xxx'); |
437 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $branchcode, 'Midway Public Library', undef, '', ''); |
438 |
|
439 |
my $patron = build_a_test_patron(); |
440 |
$patron->branchcode($branchcode2)->store; |
441 |
|
442 |
my $patroncalc = Koha::Availability::Checks::Patron->new($patron); |
443 |
my $expecting = 'Koha::Exceptions::Patron::FromAnotherLibrary'; |
444 |
|
445 |
isnt(C4::Context->userenv->{branch}, $patron->branchcode, 'Patron is not from same branch as me.'); |
446 |
is(ref($patroncalc->from_another_library), $expecting, "When I check if patron is" |
447 |
." from same branch as me, then $expecting is given."); |
448 |
} |
449 |
|
450 |
$schema->storage->txn_rollback; |
451 |
|
452 |
1; |