Lines 18-23
use Koha::Database;
Link Here
|
18 |
use Koha::DateUtils; |
18 |
use Koha::DateUtils; |
19 |
use Koha::Items; |
19 |
use Koha::Items; |
20 |
use Koha::Holds; |
20 |
use Koha::Holds; |
|
|
21 |
use Koha::CirculationRules; |
21 |
|
22 |
|
22 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
23 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
Lines 32-37
BEGIN {
Link Here
|
32 |
my $schema = Koha::Database->schema; |
33 |
my $schema = Koha::Database->schema; |
33 |
$schema->storage->txn_begin; |
34 |
$schema->storage->txn_begin; |
34 |
my $dbh = C4::Context->dbh; |
35 |
my $dbh = C4::Context->dbh; |
|
|
36 |
$dbh->do("DELETE FROM circulation_rules"); |
35 |
|
37 |
|
36 |
my $builder = t::lib::TestBuilder->new; |
38 |
my $builder = t::lib::TestBuilder->new; |
37 |
|
39 |
|
Lines 175-183
$schema->txn_begin;
Link Here
|
175 |
### Test holds queue builder does not violate holds policy ### |
177 |
### Test holds queue builder does not violate holds policy ### |
176 |
|
178 |
|
177 |
# Clear out existing rules relating to holdallowed |
179 |
# Clear out existing rules relating to holdallowed |
178 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
180 |
$dbh->do("DELETE FROM circulation_rules"); |
179 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
|
|
180 |
$dbh->do("DELETE FROM default_circ_rules"); |
181 |
|
181 |
|
182 |
t::lib::Mocks::mock_preference('UseTransportCostMatrix', 0); |
182 |
t::lib::Mocks::mock_preference('UseTransportCostMatrix', 0); |
183 |
|
183 |
|
Lines 290-297
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 )
Link Here
|
290 |
|
290 |
|
291 |
my $holds_queue; |
291 |
my $holds_queue; |
292 |
|
292 |
|
293 |
$dbh->do("DELETE FROM default_circ_rules"); |
293 |
$dbh->do("DELETE FROM circulation_rules"); |
294 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 1 )"); |
294 |
Koha::CirculationRules->set_rule( |
|
|
295 |
{ |
296 |
rule_name => 'holdallowed', |
297 |
rule_value => 1, |
298 |
branchcode => undef, |
299 |
categorycode => undef, |
300 |
itemtype => undef, |
301 |
} |
302 |
); |
295 |
C4::HoldsQueue::CreateQueue(); |
303 |
C4::HoldsQueue::CreateQueue(); |
296 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
304 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
297 |
is( @$holds_queue, 2, "Holds queue filling correct number for default holds policy 'from home library'" ); |
305 |
is( @$holds_queue, 2, "Holds queue filling correct number for default holds policy 'from home library'" ); |
Lines 320-327
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice
Link Here
|
320 |
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" ); |
328 |
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" ); |
321 |
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0); |
329 |
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0); |
322 |
|
330 |
|
323 |
$dbh->do("DELETE FROM default_circ_rules"); |
331 |
$dbh->do("DELETE FROM circulation_rules"); |
324 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); |
332 |
Koha::CirculationRules->set_rule( |
|
|
333 |
{ |
334 |
rule_name => 'holdallowed', |
335 |
rule_value => 2, |
336 |
branchcode => undef, |
337 |
categorycode => undef, |
338 |
itemtype => undef, |
339 |
} |
340 |
); |
325 |
C4::HoldsQueue::CreateQueue(); |
341 |
C4::HoldsQueue::CreateQueue(); |
326 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
342 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
327 |
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" ); |
343 |
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" ); |
Lines 340-347
t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 0 );
Link Here
|
340 |
## Test LocalHoldsPriority |
356 |
## Test LocalHoldsPriority |
341 |
t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); |
357 |
t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); |
342 |
|
358 |
|
343 |
$dbh->do("DELETE FROM default_circ_rules"); |
359 |
$dbh->do("DELETE FROM circulation_rules"); |
344 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); |
360 |
Koha::CirculationRules->set_rule( |
|
|
361 |
{ |
362 |
rule_name => 'holdallowed', |
363 |
rule_value => 2, |
364 |
branchcode => undef, |
365 |
categorycode => undef, |
366 |
itemtype => undef, |
367 |
} |
368 |
); |
345 |
$dbh->do("DELETE FROM issues"); |
369 |
$dbh->do("DELETE FROM issues"); |
346 |
|
370 |
|
347 |
# Test homebranch = patron branch |
371 |
# Test homebranch = patron branch |
Lines 473-482
$dbh->do("DELETE FROM biblioitems");
Link Here
|
473 |
$dbh->do("DELETE FROM transport_cost"); |
497 |
$dbh->do("DELETE FROM transport_cost"); |
474 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
498 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
475 |
$dbh->do("DELETE FROM hold_fill_targets"); |
499 |
$dbh->do("DELETE FROM hold_fill_targets"); |
476 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
477 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
478 |
$dbh->do("DELETE FROM default_circ_rules"); |
479 |
$dbh->do("DELETE FROM branch_item_rules"); |
480 |
|
500 |
|
481 |
$dbh->do(" |
501 |
$dbh->do(" |
482 |
INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01') |
502 |
INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01') |
Lines 501-510
$dbh->do("
Link Here
|
501 |
VALUES ($biblionumber, $biblioitemnumber, '$library_B', '$library_B', 0, 0, 0, 0, NULL, '$itemtype') |
521 |
VALUES ($biblionumber, $biblioitemnumber, '$library_B', '$library_B', 0, 0, 0, 0, NULL, '$itemtype') |
502 |
"); |
522 |
"); |
503 |
|
523 |
|
504 |
$dbh->do(" |
524 |
Koha::CirculationRules->set_rules( |
505 |
INSERT INTO branch_item_rules ( branchcode, itemtype, holdallowed, returnbranch ) VALUES |
525 |
{ |
506 |
( '$library_A', '$itemtype', 2, 'homebranch' ), ( '$library_B', '$itemtype', 1, 'homebranch' ); |
526 |
branchcode => $library_A, |
507 |
"); |
527 |
itemtype => $itemtype, |
|
|
528 |
categorycode => undef, |
529 |
rules => { |
530 |
holdallowed => 2, |
531 |
returnbranch => 'homebranch', |
532 |
} |
533 |
} |
534 |
); |
508 |
|
535 |
|
509 |
$dbh->do( "UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", |
536 |
$dbh->do( "UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", |
510 |
undef, join( ',', $library_B, $library_A, $library_C ) ); |
537 |
undef, join( ',', $library_B, $library_A, $library_C ) ); |
Lines 529-538
$dbh->do("DELETE FROM biblioitems");
Link Here
|
529 |
$dbh->do("DELETE FROM transport_cost"); |
556 |
$dbh->do("DELETE FROM transport_cost"); |
530 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
557 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
531 |
$dbh->do("DELETE FROM hold_fill_targets"); |
558 |
$dbh->do("DELETE FROM hold_fill_targets"); |
532 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
533 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
534 |
$dbh->do("DELETE FROM default_circ_rules"); |
535 |
$dbh->do("DELETE FROM branch_item_rules"); |
536 |
|
559 |
|
537 |
t::lib::Mocks::mock_preference("UseTransportCostMatrix",1); |
560 |
t::lib::Mocks::mock_preference("UseTransportCostMatrix",1); |
538 |
|
561 |
|
Lines 578-587
$dbh->do("DELETE FROM biblioitems");
Link Here
|
578 |
$dbh->do("DELETE FROM transport_cost"); |
601 |
$dbh->do("DELETE FROM transport_cost"); |
579 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
602 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
580 |
$dbh->do("DELETE FROM hold_fill_targets"); |
603 |
$dbh->do("DELETE FROM hold_fill_targets"); |
581 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
582 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
583 |
$dbh->do("DELETE FROM default_circ_rules"); |
584 |
$dbh->do("DELETE FROM branch_item_rules"); |
585 |
|
604 |
|
586 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')"); |
605 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')"); |
587 |
|
606 |
|
Lines 600-607
$dbh->do("
Link Here
|
600 |
"); |
619 |
"); |
601 |
|
620 |
|
602 |
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch |
621 |
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch |
603 |
$dbh->do("DELETE FROM default_circ_rules"); |
622 |
$dbh->do("DELETE FROM circulation_rules"); |
604 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'homebranch' )"); |
623 |
Koha::CirculationRules->set_rules( |
|
|
624 |
{ |
625 |
branchcode => undef, |
626 |
itemtype => undef, |
627 |
categorycode => undef, |
628 |
rules => { |
629 |
holdallowed => 2, |
630 |
hold_fulfillment_policy => 'homebranch', |
631 |
} |
632 |
} |
633 |
); |
605 |
|
634 |
|
606 |
# Home branch matches pickup branch |
635 |
# Home branch matches pickup branch |
607 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
636 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
Lines 625-632
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted
Link Here
|
625 |
Koha::Holds->find( $reserve_id )->cancel; |
654 |
Koha::Holds->find( $reserve_id )->cancel; |
626 |
|
655 |
|
627 |
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch |
656 |
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch |
628 |
$dbh->do("DELETE FROM default_circ_rules"); |
657 |
$dbh->do("DELETE FROM circulation_rules"); |
629 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'holdingbranch' )"); |
658 |
Koha::CirculationRules->set_rules( |
|
|
659 |
{ |
660 |
branchcode => undef, |
661 |
itemtype => undef, |
662 |
categorycode => undef, |
663 |
rules => { |
664 |
holdallowed => 2, |
665 |
hold_fulfillment_policy => 'holdingbranch', |
666 |
} |
667 |
} |
668 |
); |
630 |
|
669 |
|
631 |
# Home branch matches pickup branch |
670 |
# Home branch matches pickup branch |
632 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
671 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
Lines 650-657
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted
Link Here
|
650 |
Koha::Holds->find( $reserve_id )->cancel; |
689 |
Koha::Holds->find( $reserve_id )->cancel; |
651 |
|
690 |
|
652 |
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch |
691 |
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch |
653 |
$dbh->do("DELETE FROM default_circ_rules"); |
692 |
$dbh->do("DELETE FROM circulation_rules"); |
654 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'any' )"); |
693 |
Koha::CirculationRules->set_rules( |
|
|
694 |
{ |
695 |
branchcode => undef, |
696 |
itemtype => undef, |
697 |
categorycode => undef, |
698 |
rules => { |
699 |
holdallowed => 2, |
700 |
hold_fulfillment_policy => 'any', |
701 |
} |
702 |
} |
703 |
); |
655 |
|
704 |
|
656 |
# Home branch matches pickup branch |
705 |
# Home branch matches pickup branch |
657 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
706 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
Lines 690-699
$dbh->do("DELETE FROM biblioitems");
Link Here
|
690 |
$dbh->do("DELETE FROM transport_cost"); |
739 |
$dbh->do("DELETE FROM transport_cost"); |
691 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
740 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
692 |
$dbh->do("DELETE FROM hold_fill_targets"); |
741 |
$dbh->do("DELETE FROM hold_fill_targets"); |
693 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
694 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
695 |
$dbh->do("DELETE FROM default_circ_rules"); |
696 |
$dbh->do("DELETE FROM branch_item_rules"); |
697 |
|
742 |
|
698 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')"); |
743 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')"); |
699 |
|
744 |
|
Lines 712-719
$dbh->do("
Link Here
|
712 |
"); |
757 |
"); |
713 |
|
758 |
|
714 |
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch |
759 |
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch |
715 |
$dbh->do("DELETE FROM default_circ_rules"); |
760 |
$dbh->do("DELETE FROM circulation_rules"); |
716 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'any' )"); |
761 |
Koha::CirculationRules->set_rules( |
|
|
762 |
{ |
763 |
branchcode => undef, |
764 |
itemtype => undef, |
765 |
categorycode => undef, |
766 |
rules => { |
767 |
holdallowed => 2, |
768 |
hold_fulfillment_policy => 'any', |
769 |
} |
770 |
} |
771 |
); |
717 |
|
772 |
|
718 |
# Home branch matches pickup branch |
773 |
# Home branch matches pickup branch |
719 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $wrong_itemtype ); |
774 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $wrong_itemtype ); |
Lines 747-756
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'homebranch');
Link Here
|
747 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
802 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
748 |
$dbh->do("DELETE FROM hold_fill_targets"); |
803 |
$dbh->do("DELETE FROM hold_fill_targets"); |
749 |
$dbh->do("DELETE FROM reserves"); |
804 |
$dbh->do("DELETE FROM reserves"); |
750 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
751 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
752 |
$dbh->do("DELETE FROM default_circ_rules"); |
753 |
$dbh->do("DELETE FROM branch_item_rules"); |
754 |
|
805 |
|
755 |
$item = Koha::Items->find( { biblionumber => $biblionumber } ); |
806 |
$item = Koha::Items->find( { biblionumber => $biblionumber } ); |
756 |
$item->holdingbranch( $item->homebranch ); |
807 |
$item->holdingbranch( $item->homebranch ); |