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