Lines 28-35
use Koha::Holds;
Link Here
|
28 |
use Koha::Item; |
28 |
use Koha::Item; |
29 |
use Koha::DateUtils; |
29 |
use Koha::DateUtils; |
30 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
|
|
31 |
use Koha::IssuingRules; |
31 |
|
32 |
|
32 |
use Test::More tests => 29; |
33 |
use Test::More tests => 30; |
33 |
use Test::Exception; |
34 |
use Test::Exception; |
34 |
use Test::Warn; |
35 |
use Test::Warn; |
35 |
|
36 |
|
Lines 270-272
subtest 'suspend() tests' => sub {
Link Here
|
270 |
|
271 |
|
271 |
$schema->storage->txn_rollback; |
272 |
$schema->storage->txn_rollback; |
272 |
}; |
273 |
}; |
273 |
- |
274 |
|
|
|
275 |
subtest "check_if_existing_hold_matches_issuingrules tests" => sub { |
276 |
plan tests => 9; |
277 |
|
278 |
$schema->storage->txn_begin(); |
279 |
|
280 |
#Create test data |
281 |
my $branchcode = $builder->build( { source => 'Branch' } )->{ branchcode }; |
282 |
my $categorycode1 = $builder->build({ source => 'Category' })->{categorycode}; |
283 |
my $categorycode2 = $builder->build({ source => 'Category' })->{categorycode}; |
284 |
my $patron1 = $builder->build({source => 'Borrower', value => { branchcode => $branchcode }}); |
285 |
|
286 |
my $item1 = $builder->build({ source => 'Item', value => { homebranch => $branchcode }}); |
287 |
my $item2 = $builder->build({ source => 'Item', value => { homebranch => $branchcode }}); |
288 |
|
289 |
my $itemtype1 = $item1->{'itype'}; |
290 |
my $itemtype2 = $item2->{'itype'}; |
291 |
|
292 |
Koha::IssuingRules->delete; |
293 |
|
294 |
#Get branchcode |
295 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
296 |
|
297 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
298 |
$branchcode = $item->{homebranch}; |
299 |
} |
300 |
elsif ( $controlbranch eq "PatronLibrary" ) { |
301 |
$branchcode = $patron1->{branchcode}; |
302 |
} |
303 |
|
304 |
#Test all cases when the check_return |
305 |
#check_if_existing_hold_matches_issuingrules() returns 'InvalidHold' when reservesallowed, holds_per_record and holds_per_day are all 0 |
306 |
my $rule1 = Koha::IssuingRule->new({ |
307 |
branchcode => $branchcode, |
308 |
categorycode => $patron1->{'categorycode'}, |
309 |
itemtype => $item1->{'itype'}, |
310 |
reservesallowed => 0, |
311 |
holds_per_record => 0, |
312 |
holds_per_day => 0, |
313 |
})->store; |
314 |
my $checkreserve1 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
315 |
is( $checkreserve1, 'InvalidHold', 'Allocating item1 to a bib-reserve is not allowed as the issuingrules reservesallowed, holds_per_record and holds_per_day is 0 for this patron category/itemtype combination' ); |
316 |
|
317 |
#Confirm that when any of the 4 reserves related issuingrules fields (reservesallowed, holds_per_record, holds_per_day) are set to 0 then check_if_existing_hold_matches_issuingrules() returns 'InvalidHold' and so a newly returned item is not allocated to a specific bib-level reserve |
318 |
|
319 |
#check_if_existing_hold_matches_issuingrules() returns 'InvalidHold' when reservesallowed is 0 for the patron category/itemtype combination |
320 |
$rule1->set({ reservesallowed => 0, holds_per_record => 1, holds_per_day => 1 })->store; |
321 |
my $checkreserve2 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
322 |
is( $checkreserve2, 'InvalidHold', 'Allocating item1 to a bib-reserve is not allowed as the issuingrules reservesallowed is 0 for this patron category/itemtype combination' ); |
323 |
|
324 |
#Now change to reservesallowed = 1, holds_per_record = 0, holds_per_day = 1 |
325 |
$rule1->set({ reservesallowed => 1, holds_per_record => 0, holds_per_day => 1 })->store; |
326 |
my $checkreserve3 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
327 |
is( $checkreserve3, 'InvalidHold', 'Allocating item1 to a bib-reserve is not allowed as the issuingrules holds_per_record is set to 0 for this patron category/itemtype combination' ); |
328 |
|
329 |
#Now change to reservesallowed = 1, holds_per_record = 1, holds_per_day = 0 |
330 |
$rule1->set({ reservesallowed => 1, holds_per_record => 1, holds_per_day => 0 })->store; |
331 |
my $checkreserve4 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
332 |
is( $checkreserve4, 'InvalidHold', 'Allocating item1 to a bib-reserve is not allowed as the issuingrules holds_per_record is set to0 for this patron category/itemtype combination' ); |
333 |
|
334 |
#Now change to reservesallowed = 1, holds_per_record = 1, holds_per_day = 1 and confirm 'OK' is returned |
335 |
$rule1->set({ reservesallowed => 1, holds_per_record => 1, holds_per_day => 1 })->store; |
336 |
my $checkreserve5 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
337 |
is( $checkreserve5, 'OK', 'Allocating item2 to a bib-reserve is allowed as there is no specific issuingrule for this patron category/itemtype combination and so we default to the all patron category/all item type rule which allows reserves' ); |
338 |
|
339 |
#Create a default rule (patron categories: ALL, itemtypes: ALL) |
340 |
my $rule3 = Koha::IssuingRule->new({ |
341 |
branchcode => $branchcode, |
342 |
categorycode => '*', |
343 |
itemtype => '*', |
344 |
reservesallowed => 1, |
345 |
holds_per_record => 1, |
346 |
holds_per_day => 1, |
347 |
})->store; |
348 |
|
349 |
#Check that when no specific patron category/item type issuingrule combo exists we revert to using the default ALL categories/ALL |
350 |
#itemtypes issuingrule. When generic rule is reservesallowed, holds_per_record and holds_per_day = 1 then 'OK' is returned |
351 |
my $checkreserve6 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item2->{'itemnumber'} ); |
352 |
is( $checkreserve6, 'OK', 'Allocating item2 to a bib-reserve is allowed as there is no specific issuingrule for this patron category/itemtype combination and so we default to the all patron category/all item type rule which allows reserves' ); |
353 |
|
354 |
#When default rule is reservesallowed = 0, holds_per_record = 1, holds_per_day = 1 then 'InvalidHold is returned |
355 |
$rule3->set({ reservesallowed => 0, holds_per_record => 1, holds_per_day => 1 })->store; |
356 |
my $checkreserve7 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item2->{'itemnumber'} ); |
357 |
is( $checkreserve7, 'InvalidHold', 'Allocating item2 to a bib-reserve is not allowed as there is no specific issuingrule for this patron category/itemtype combination and so we default to the all patron category/all item type rule which doesnt allows reserves as reservesallowed is 0' ); |
358 |
|
359 |
#When default rule is reservesallowed = 1, holds_per_record = 0, holds_per_day = 1 then 'InvalidHold' is returned |
360 |
$rule3->set({ reservesallowed => 1, holds_per_record => 0, holds_per_day => 1 })->store; |
361 |
my $checkreserve8 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item2->{'itemnumber'} ); |
362 |
is( $checkreserve8, 'InvalidHold', 'Allocating item2 to a bib-reserve is not allowed as there is no specific issuingrule for this patron category/itemtype combination and so we default to the all patron category/all item type rule which doesnt allows reserves as holds_per_record is 0' ); |
363 |
|
364 |
#When default rule is reservesallowed = 1, holds_per_record = 1, holds_per_day = 0 then 'InvalidHold' is returned |
365 |
$rule3->set({ reservesallowed => 1, holds_per_record => 1, holds_per_day => 0 })->store; |
366 |
my $checkreserve9 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item2->{'itemnumber'} ); |
367 |
is( $checkreserve9, 'InvalidHold', 'Allocating item2 to a bib-reserve is not allowed as there is no specific issuingrule for this patron category/itemtype combination and so we default to the all patron category/all item type rule which doesnt allows reserves as holds_per_day is 0' ); |
368 |
|
369 |
$schema->storage->txn_rollback; |
370 |
}; |