|
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 172-180
$schema->txn_begin;
Link Here
|
| 172 |
### Test holds queue builder does not violate holds policy ### |
174 |
### Test holds queue builder does not violate holds policy ### |
| 173 |
|
175 |
|
| 174 |
# Clear out existing rules relating to holdallowed |
176 |
# Clear out existing rules relating to holdallowed |
| 175 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
177 |
$dbh->do("DELETE FROM circulation_rules"); |
| 176 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
|
|
| 177 |
$dbh->do("DELETE FROM default_circ_rules"); |
| 178 |
|
178 |
|
| 179 |
t::lib::Mocks::mock_preference('UseTransportCostMatrix', 0); |
179 |
t::lib::Mocks::mock_preference('UseTransportCostMatrix', 0); |
| 180 |
|
180 |
|
|
Lines 287-294
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 )
Link Here
|
| 287 |
|
287 |
|
| 288 |
my $holds_queue; |
288 |
my $holds_queue; |
| 289 |
|
289 |
|
| 290 |
$dbh->do("DELETE FROM default_circ_rules"); |
290 |
$dbh->do("DELETE FROM circulation_rules"); |
| 291 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 1 )"); |
291 |
Koha::CirculationRules->set_rule( |
|
|
292 |
{ |
| 293 |
rule_name => 'holdallowed', |
| 294 |
rule_value => 1, |
| 295 |
branchcode => undef, |
| 296 |
categorycode => undef, |
| 297 |
itemtype => undef, |
| 298 |
} |
| 299 |
); |
| 292 |
C4::HoldsQueue::CreateQueue(); |
300 |
C4::HoldsQueue::CreateQueue(); |
| 293 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
301 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
| 294 |
is( @$holds_queue, 2, "Holds queue filling correct number for default holds policy 'from home library'" ); |
302 |
is( @$holds_queue, 2, "Holds queue filling correct number for default holds policy 'from home library'" ); |
|
Lines 317-324
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice
Link Here
|
| 317 |
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" ); |
325 |
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" ); |
| 318 |
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0); |
326 |
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0); |
| 319 |
|
327 |
|
| 320 |
$dbh->do("DELETE FROM default_circ_rules"); |
328 |
$dbh->do("DELETE FROM circulation_rules"); |
| 321 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); |
329 |
Koha::CirculationRules->set_rule( |
|
|
330 |
{ |
| 331 |
rule_name => 'holdallowed', |
| 332 |
rule_value => 2, |
| 333 |
branchcode => undef, |
| 334 |
categorycode => undef, |
| 335 |
itemtype => undef, |
| 336 |
} |
| 337 |
); |
| 322 |
C4::HoldsQueue::CreateQueue(); |
338 |
C4::HoldsQueue::CreateQueue(); |
| 323 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
339 |
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); |
| 324 |
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" ); |
340 |
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" ); |
|
Lines 337-344
t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 0 );
Link Here
|
| 337 |
## Test LocalHoldsPriority |
353 |
## Test LocalHoldsPriority |
| 338 |
t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); |
354 |
t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); |
| 339 |
|
355 |
|
| 340 |
$dbh->do("DELETE FROM default_circ_rules"); |
356 |
$dbh->do("DELETE FROM circulation_rules"); |
| 341 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); |
357 |
Koha::CirculationRules->set_rule( |
|
|
358 |
{ |
| 359 |
rule_name => 'holdallowed', |
| 360 |
rule_value => 2, |
| 361 |
branchcode => undef, |
| 362 |
categorycode => undef, |
| 363 |
itemtype => undef, |
| 364 |
} |
| 365 |
); |
| 342 |
$dbh->do("DELETE FROM issues"); |
366 |
$dbh->do("DELETE FROM issues"); |
| 343 |
|
367 |
|
| 344 |
# Test homebranch = patron branch |
368 |
# Test homebranch = patron branch |
|
Lines 427-436
$dbh->do("DELETE FROM biblioitems");
Link Here
|
| 427 |
$dbh->do("DELETE FROM transport_cost"); |
451 |
$dbh->do("DELETE FROM transport_cost"); |
| 428 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
452 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
| 429 |
$dbh->do("DELETE FROM hold_fill_targets"); |
453 |
$dbh->do("DELETE FROM hold_fill_targets"); |
| 430 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
| 431 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
| 432 |
$dbh->do("DELETE FROM default_circ_rules"); |
| 433 |
$dbh->do("DELETE FROM branch_item_rules"); |
| 434 |
|
454 |
|
| 435 |
$dbh->do(" |
455 |
$dbh->do(" |
| 436 |
INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01') |
456 |
INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01') |
|
Lines 455-464
$dbh->do("
Link Here
|
| 455 |
VALUES ($biblionumber, $biblioitemnumber, '$library_B', '$library_B', 0, 0, 0, 0, NULL, '$itemtype') |
475 |
VALUES ($biblionumber, $biblioitemnumber, '$library_B', '$library_B', 0, 0, 0, 0, NULL, '$itemtype') |
| 456 |
"); |
476 |
"); |
| 457 |
|
477 |
|
| 458 |
$dbh->do(" |
478 |
Koha::CirculationRules->set_rules( |
| 459 |
INSERT INTO branch_item_rules ( branchcode, itemtype, holdallowed, returnbranch ) VALUES |
479 |
{ |
| 460 |
( '$library_A', '$itemtype', 2, 'homebranch' ), ( '$library_B', '$itemtype', 1, 'homebranch' ); |
480 |
branchcode => $library_A, |
| 461 |
"); |
481 |
itemtype => $itemtype, |
|
|
482 |
categorycode => undef, |
| 483 |
rules => { |
| 484 |
holdallowed => 2, |
| 485 |
returnbranch => 'homebranch', |
| 486 |
} |
| 487 |
} |
| 488 |
); |
| 462 |
|
489 |
|
| 463 |
$dbh->do( "UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", |
490 |
$dbh->do( "UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", |
| 464 |
undef, join( ',', $library_B, $library_A, $library_C ) ); |
491 |
undef, join( ',', $library_B, $library_A, $library_C ) ); |
|
Lines 483-492
$dbh->do("DELETE FROM biblioitems");
Link Here
|
| 483 |
$dbh->do("DELETE FROM transport_cost"); |
510 |
$dbh->do("DELETE FROM transport_cost"); |
| 484 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
511 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
| 485 |
$dbh->do("DELETE FROM hold_fill_targets"); |
512 |
$dbh->do("DELETE FROM hold_fill_targets"); |
| 486 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
| 487 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
| 488 |
$dbh->do("DELETE FROM default_circ_rules"); |
| 489 |
$dbh->do("DELETE FROM branch_item_rules"); |
| 490 |
|
513 |
|
| 491 |
t::lib::Mocks::mock_preference("UseTransportCostMatrix",1); |
514 |
t::lib::Mocks::mock_preference("UseTransportCostMatrix",1); |
| 492 |
|
515 |
|
|
Lines 532-541
$dbh->do("DELETE FROM biblioitems");
Link Here
|
| 532 |
$dbh->do("DELETE FROM transport_cost"); |
555 |
$dbh->do("DELETE FROM transport_cost"); |
| 533 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
556 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
| 534 |
$dbh->do("DELETE FROM hold_fill_targets"); |
557 |
$dbh->do("DELETE FROM hold_fill_targets"); |
| 535 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
| 536 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
| 537 |
$dbh->do("DELETE FROM default_circ_rules"); |
| 538 |
$dbh->do("DELETE FROM branch_item_rules"); |
| 539 |
|
558 |
|
| 540 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')"); |
559 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')"); |
| 541 |
|
560 |
|
|
Lines 554-561
$dbh->do("
Link Here
|
| 554 |
"); |
573 |
"); |
| 555 |
|
574 |
|
| 556 |
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch |
575 |
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch |
| 557 |
$dbh->do("DELETE FROM default_circ_rules"); |
576 |
$dbh->do("DELETE FROM circulation_rules"); |
| 558 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'homebranch' )"); |
577 |
Koha::CirculationRules->set_rules( |
|
|
578 |
{ |
| 579 |
branchcode => undef, |
| 580 |
itemtype => undef, |
| 581 |
categorycode => undef, |
| 582 |
rules => { |
| 583 |
holdallowed => 2, |
| 584 |
hold_fulfillment_policy => 'homebranch', |
| 585 |
} |
| 586 |
} |
| 587 |
); |
| 559 |
|
588 |
|
| 560 |
# Home branch matches pickup branch |
589 |
# Home branch matches pickup branch |
| 561 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
590 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
|
Lines 579-586
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted
Link Here
|
| 579 |
Koha::Holds->find( $reserve_id )->cancel; |
608 |
Koha::Holds->find( $reserve_id )->cancel; |
| 580 |
|
609 |
|
| 581 |
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch |
610 |
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch |
| 582 |
$dbh->do("DELETE FROM default_circ_rules"); |
611 |
$dbh->do("DELETE FROM circulation_rules"); |
| 583 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'holdingbranch' )"); |
612 |
Koha::CirculationRules->set_rules( |
|
|
613 |
{ |
| 614 |
branchcode => undef, |
| 615 |
itemtype => undef, |
| 616 |
categorycode => undef, |
| 617 |
rules => { |
| 618 |
holdallowed => 2, |
| 619 |
hold_fulfillment_policy => 'holdingbranch', |
| 620 |
} |
| 621 |
} |
| 622 |
); |
| 584 |
|
623 |
|
| 585 |
# Home branch matches pickup branch |
624 |
# Home branch matches pickup branch |
| 586 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
625 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
|
Lines 604-611
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted
Link Here
|
| 604 |
Koha::Holds->find( $reserve_id )->cancel; |
643 |
Koha::Holds->find( $reserve_id )->cancel; |
| 605 |
|
644 |
|
| 606 |
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch |
645 |
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch |
| 607 |
$dbh->do("DELETE FROM default_circ_rules"); |
646 |
$dbh->do("DELETE FROM circulation_rules"); |
| 608 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'any' )"); |
647 |
Koha::CirculationRules->set_rules( |
|
|
648 |
{ |
| 649 |
branchcode => undef, |
| 650 |
itemtype => undef, |
| 651 |
categorycode => undef, |
| 652 |
rules => { |
| 653 |
holdallowed => 2, |
| 654 |
hold_fulfillment_policy => 'any', |
| 655 |
} |
| 656 |
} |
| 657 |
); |
| 609 |
|
658 |
|
| 610 |
# Home branch matches pickup branch |
659 |
# Home branch matches pickup branch |
| 611 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
660 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); |
|
Lines 644-653
$dbh->do("DELETE FROM biblioitems");
Link Here
|
| 644 |
$dbh->do("DELETE FROM transport_cost"); |
693 |
$dbh->do("DELETE FROM transport_cost"); |
| 645 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
694 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
| 646 |
$dbh->do("DELETE FROM hold_fill_targets"); |
695 |
$dbh->do("DELETE FROM hold_fill_targets"); |
| 647 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
| 648 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
| 649 |
$dbh->do("DELETE FROM default_circ_rules"); |
| 650 |
$dbh->do("DELETE FROM branch_item_rules"); |
| 651 |
|
696 |
|
| 652 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')"); |
697 |
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')"); |
| 653 |
|
698 |
|
|
Lines 666-673
$dbh->do("
Link Here
|
| 666 |
"); |
711 |
"); |
| 667 |
|
712 |
|
| 668 |
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch |
713 |
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch |
| 669 |
$dbh->do("DELETE FROM default_circ_rules"); |
714 |
$dbh->do("DELETE FROM circulation_rules"); |
| 670 |
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'any' )"); |
715 |
Koha::CirculationRules->set_rules( |
|
|
716 |
{ |
| 717 |
branchcode => undef, |
| 718 |
itemtype => undef, |
| 719 |
categorycode => undef, |
| 720 |
rules => { |
| 721 |
holdallowed => 2, |
| 722 |
hold_fulfillment_policy => 'any', |
| 723 |
} |
| 724 |
} |
| 725 |
); |
| 671 |
|
726 |
|
| 672 |
# Home branch matches pickup branch |
727 |
# Home branch matches pickup branch |
| 673 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $wrong_itemtype ); |
728 |
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $wrong_itemtype ); |
|
Lines 701-710
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'homebranch');
Link Here
|
| 701 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
756 |
$dbh->do("DELETE FROM tmp_holdsqueue"); |
| 702 |
$dbh->do("DELETE FROM hold_fill_targets"); |
757 |
$dbh->do("DELETE FROM hold_fill_targets"); |
| 703 |
$dbh->do("DELETE FROM reserves"); |
758 |
$dbh->do("DELETE FROM reserves"); |
| 704 |
$dbh->do("DELETE FROM default_branch_circ_rules"); |
|
|
| 705 |
$dbh->do("DELETE FROM default_branch_item_rules"); |
| 706 |
$dbh->do("DELETE FROM default_circ_rules"); |
| 707 |
$dbh->do("DELETE FROM branch_item_rules"); |
| 708 |
|
759 |
|
| 709 |
my $item = Koha::Items->find( { biblionumber => $biblionumber } ); |
760 |
my $item = Koha::Items->find( { biblionumber => $biblionumber } ); |
| 710 |
$item->holdingbranch( $item->homebranch ); |
761 |
$item->holdingbranch( $item->homebranch ); |