Lines 28-33
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 => 33; |
33 |
use Test::More tests => 33; |
33 |
use Test::Exception; |
34 |
use Test::Exception; |
Lines 286-288
subtest 'suspend() tests' => sub {
Link Here
|
286 |
|
287 |
|
287 |
$schema->storage->txn_rollback; |
288 |
$schema->storage->txn_rollback; |
288 |
}; |
289 |
}; |
289 |
- |
290 |
|
|
|
291 |
subtest "check_if_existing_hold_matches_issuingrules tests" => sub { |
292 |
plan tests => 9; |
293 |
|
294 |
$schema->storage->txn_begin(); |
295 |
|
296 |
#Create test data |
297 |
my $branchcode = $builder->build( { source => 'Branch' } )->{ branchcode }; |
298 |
my $categorycode1 = $builder->build({ source => 'Category' })->{categorycode}; |
299 |
my $categorycode2 = $builder->build({ source => 'Category' })->{categorycode}; |
300 |
my $patron1 = $builder->build({source => 'Borrower', value => { branchcode => $branchcode }}); |
301 |
|
302 |
my $item1 = $builder->build({ source => 'Item', value => { homebranch => $branchcode }}); |
303 |
my $item2 = $builder->build({ source => 'Item', value => { homebranch => $branchcode }}); |
304 |
|
305 |
my $itemtype1 = $item1->{'itype'}; |
306 |
my $itemtype2 = $item2->{'itype'}; |
307 |
|
308 |
Koha::IssuingRules->delete; |
309 |
|
310 |
#Get branchcode |
311 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
312 |
|
313 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
314 |
$branchcode = $item->{homebranch}; |
315 |
} |
316 |
elsif ( $controlbranch eq "PatronLibrary" ) { |
317 |
$branchcode = $patron1->{branchcode}; |
318 |
} |
319 |
|
320 |
#Test all cases when the check_return |
321 |
#check_if_existing_hold_matches_issuingrules() returns 'InvalidHold' when reservesallowed, holds_per_record and holds_per_day are all 0 |
322 |
my $rule1 = Koha::IssuingRule->new({ |
323 |
branchcode => $branchcode, |
324 |
categorycode => $patron1->{'categorycode'}, |
325 |
itemtype => $item1->{'itype'}, |
326 |
reservesallowed => 0, |
327 |
holds_per_record => 0, |
328 |
holds_per_day => 0, |
329 |
})->store; |
330 |
my $checkreserve1 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
331 |
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' ); |
332 |
|
333 |
#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 |
334 |
|
335 |
#check_if_existing_hold_matches_issuingrules() returns 'InvalidHold' when reservesallowed is 0 for the patron category/itemtype combination |
336 |
$rule1->set({ reservesallowed => 0, holds_per_record => 1, holds_per_day => 1 })->store; |
337 |
my $checkreserve2 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
338 |
is( $checkreserve2, 'InvalidHold', 'Allocating item1 to a bib-reserve is not allowed as the issuingrules reservesallowed is 0 for this patron category/itemtype combination' ); |
339 |
|
340 |
#Now change to reservesallowed = 1, holds_per_record = 0, holds_per_day = 1 |
341 |
$rule1->set({ reservesallowed => 1, holds_per_record => 0, holds_per_day => 1 })->store; |
342 |
my $checkreserve3 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
343 |
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' ); |
344 |
|
345 |
#Now change to reservesallowed = 1, holds_per_record = 1, holds_per_day = 0 |
346 |
$rule1->set({ reservesallowed => 1, holds_per_record => 1, holds_per_day => 0 })->store; |
347 |
my $checkreserve4 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
348 |
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' ); |
349 |
|
350 |
#Now change to reservesallowed = 1, holds_per_record = 1, holds_per_day = 1 and confirm 'OK' is returned |
351 |
$rule1->set({ reservesallowed => 1, holds_per_record => 1, holds_per_day => 1 })->store; |
352 |
my $checkreserve5 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item1->{'itemnumber'} ); |
353 |
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' ); |
354 |
|
355 |
#Create a default rule (patron categories: ALL, itemtypes: ALL) |
356 |
my $rule3 = Koha::IssuingRule->new({ |
357 |
branchcode => $branchcode, |
358 |
categorycode => '*', |
359 |
itemtype => '*', |
360 |
reservesallowed => 1, |
361 |
holds_per_record => 1, |
362 |
holds_per_day => 1, |
363 |
})->store; |
364 |
|
365 |
#Check that when no specific patron category/item type issuingrule combo exists we revert to using the default ALL categories/ALL |
366 |
#itemtypes issuingrule. When generic rule is reservesallowed, holds_per_record and holds_per_day = 1 then 'OK' is returned |
367 |
my $checkreserve6 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item2->{'itemnumber'} ); |
368 |
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' ); |
369 |
|
370 |
#When default rule is reservesallowed = 0, holds_per_record = 1, holds_per_day = 1 then 'InvalidHold is returned |
371 |
$rule3->set({ reservesallowed => 0, holds_per_record => 1, holds_per_day => 1 })->store; |
372 |
my $checkreserve7 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item2->{'itemnumber'} ); |
373 |
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' ); |
374 |
|
375 |
#When default rule is reservesallowed = 1, holds_per_record = 0, holds_per_day = 1 then 'InvalidHold' is returned |
376 |
$rule3->set({ reservesallowed => 1, holds_per_record => 0, holds_per_day => 1 })->store; |
377 |
my $checkreserve8 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item2->{'itemnumber'} ); |
378 |
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' ); |
379 |
|
380 |
#When default rule is reservesallowed = 1, holds_per_record = 1, holds_per_day = 0 then 'InvalidHold' is returned |
381 |
$rule3->set({ reservesallowed => 1, holds_per_record => 1, holds_per_day => 0 })->store; |
382 |
my $checkreserve9 = Koha::Hold->check_if_existing_hold_matches_issuingrules($patron1->{'borrowernumber'}, $item2->{'itemnumber'} ); |
383 |
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' ); |
384 |
|
385 |
$schema->storage->txn_rollback; |
386 |
}; |