Lines 8-14
Link Here
|
8 |
|
8 |
|
9 |
use Modern::Perl; |
9 |
use Modern::Perl; |
10 |
|
10 |
|
11 |
use Test::More tests => 44; |
11 |
use Test::More tests => 48; |
12 |
use Data::Dumper; |
12 |
use Data::Dumper; |
13 |
|
13 |
|
14 |
use C4::Calendar; |
14 |
use C4::Calendar; |
Lines 35-40
my $dbh = C4::Context->dbh;
Link Here
|
35 |
|
35 |
|
36 |
my $builder = t::lib::TestBuilder->new; |
36 |
my $builder = t::lib::TestBuilder->new; |
37 |
|
37 |
|
|
|
38 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' ); |
39 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
40 |
|
38 |
my $library1 = $builder->build({ |
41 |
my $library1 = $builder->build({ |
39 |
source => 'Branch', |
42 |
source => 'Branch', |
40 |
}); |
43 |
}); |
Lines 358-363
C4::HoldsQueue::CreateQueue();
Link Here
|
358 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
361 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
359 |
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library"); |
362 |
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library"); |
360 |
|
363 |
|
|
|
364 |
### Test branch transfer limits ### |
365 |
t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary'); |
366 |
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'holdingbranch'); |
367 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
368 |
C4::Context->clear_syspref_cache(); |
369 |
$dbh->do("DELETE FROM reserves"); |
370 |
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); |
371 |
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[1], 2 ); |
372 |
|
373 |
$dbh->do("DELETE FROM items"); |
374 |
# barcode, homebranch, holdingbranch, itemtype |
375 |
$items_insert_sth->execute( $barcode, $branchcodes[2], $branchcodes[2] ); |
376 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
377 |
|
378 |
my $limit1 = Koha::Item::Transfer::Limit->new( |
379 |
{ |
380 |
toBranch => $branchcodes[0], |
381 |
fromBranch => $branchcodes[2], |
382 |
itemtype => $item->effective_itemtype, |
383 |
} |
384 |
)->store(); |
385 |
|
386 |
C4::HoldsQueue::CreateQueue(); |
387 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
388 |
is( $holds_queue->[0]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue skips hold transfer that would violate branch transfer limits"); |
389 |
|
390 |
my $limit2 = Koha::Item::Transfer::Limit->new( |
391 |
{ |
392 |
toBranch => $branchcodes[1], |
393 |
fromBranch => $branchcodes[2], |
394 |
itemtype => $item->effective_itemtype, |
395 |
} |
396 |
)->store(); |
397 |
|
398 |
C4::HoldsQueue::CreateQueue(); |
399 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
400 |
is( $holds_queue->[0]->{cardnumber}, undef, "Holds queue doesn't fill hold where all available items would violate branch transfer limits"); |
401 |
|
402 |
$limit1->delete(); |
403 |
$limit2->delete(); |
404 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' ); |
405 |
### END Test branch transfer limits ### |
406 |
|
361 |
# Test holdingbranch = patron branch |
407 |
# Test holdingbranch = patron branch |
362 |
t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary'); |
408 |
t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary'); |
363 |
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'holdingbranch'); |
409 |
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'holdingbranch'); |
Lines 706-712
$dbh->do("DELETE FROM default_branch_item_rules");
Link Here
|
706 |
$dbh->do("DELETE FROM default_circ_rules"); |
752 |
$dbh->do("DELETE FROM default_circ_rules"); |
707 |
$dbh->do("DELETE FROM branch_item_rules"); |
753 |
$dbh->do("DELETE FROM branch_item_rules"); |
708 |
|
754 |
|
709 |
my $item = Koha::Items->find( { biblionumber => $biblionumber } ); |
755 |
$item = Koha::Items->find( { biblionumber => $biblionumber } ); |
710 |
$item->holdingbranch( $item->homebranch ); |
756 |
$item->holdingbranch( $item->homebranch ); |
711 |
$item->store(); |
757 |
$item->store(); |
712 |
|
758 |
|
Lines 759-764
sub test_queue {
Link Here
|
759 |
diag( "Wrong pick-up/hold for first target (pick_branch, hold_branch, reserves, hold_fill_targets, tmp_holdsqueue): " |
805 |
diag( "Wrong pick-up/hold for first target (pick_branch, hold_branch, reserves, hold_fill_targets, tmp_holdsqueue): " |
760 |
. Dumper ($pick_branch, $hold_branch, map dump_records($_), qw(reserves hold_fill_targets tmp_holdsqueue)) ) |
806 |
. Dumper ($pick_branch, $hold_branch, map dump_records($_), qw(reserves hold_fill_targets tmp_holdsqueue)) ) |
761 |
unless $ok; |
807 |
unless $ok; |
|
|
808 |
|
809 |
# Test enforcement of branch transfer limit |
810 |
if ( $r->{pickbranch} ne $r->{holdingbranch} ) { |
811 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
812 |
my $limit = Koha::Item::Transfer::Limit->new( |
813 |
{ |
814 |
toBranch => $r->{pickbranch}, |
815 |
fromBranch => $r->{holdingbranch}, |
816 |
itemtype => $r->{itype}, |
817 |
} |
818 |
)->store(); |
819 |
C4::Context->clear_syspref_cache(); |
820 |
C4::HoldsQueue::CreateQueue(); |
821 |
$results = $dbh->selectall_arrayref( $test_sth, { Slice => {} } ) |
822 |
; # should be only one |
823 |
my $s = $results->[0]; |
824 |
isnt( $r->{holdingbranch}, $s->{holdingbranch}, 'Hold is not trapped for pickup at a branch that cannot be transferred to'); |
825 |
|
826 |
$limit->delete(); |
827 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' ); |
828 |
C4::Context->clear_syspref_cache(); |
829 |
C4::HoldsQueue::CreateQueue(); |
830 |
} |
831 |
|
762 |
} |
832 |
} |
763 |
|
833 |
|
764 |
sub dump_records { |
834 |
sub dump_records { |