View | Details | Raw Unified | Return to bug 11998
Collapse All | Expand All

(-)a/t/db_dependent/HoldsQueue.t (-17 / +19 lines)
Lines 19-25 use Koha::Database; Link Here
19
use Koha::DateUtils;
19
use Koha::DateUtils;
20
use Koha::ItemType;
20
use Koha::ItemType;
21
21
22
use t::lib::Mocks;
23
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
24
23
25
use Koha::ItemTypes;
24
use Koha::ItemTypes;
Lines 68-76 $itemtype or BAIL_OUT("No adequate itemtype"); #FIXME Should be $itemtype = $ite Link Here
68
67
69
#Set up the stage
68
#Set up the stage
70
# Sysprefs and cost matrix
69
# Sysprefs and cost matrix
71
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0);
70
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
72
t::lib::Mocks::mock_preference('StaticHoldsQueueWeight', join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
71
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
73
t::lib::Mocks::mock_preference('RandomizeHoldsQueueWeight', 0);
72
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
73
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
74
74
75
$dbh->do("DELETE FROM transport_cost");
75
$dbh->do("DELETE FROM transport_cost");
76
my $transport_cost_insert_sth = $dbh->prepare("insert into transport_cost (frombranch, tobranch, cost) values (?, ?, ?)");
76
my $transport_cost_insert_sth = $dbh->prepare("insert into transport_cost (frombranch, tobranch, cost) values (?, ?, ?)");
Lines 116-128 AddReserve ( $borrower_branchcode, $borrowernumber, $biblionumber, $bibitems, $ Link Here
116
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )");
116
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )");
117
117
118
# Tests
118
# Tests
119
my $use_cost_matrix_sth = $dbh->prepare("UPDATE systempreferences SET value = ? WHERE variable = 'UseTransportCostMatrix'");
119
my $test_sth = $dbh->prepare("SELECT * FROM hold_fill_targets
120
my $test_sth = $dbh->prepare("SELECT * FROM hold_fill_targets
120
                              JOIN tmp_holdsqueue USING (borrowernumber, biblionumber, itemnumber)
121
                              JOIN tmp_holdsqueue USING (borrowernumber, biblionumber, itemnumber)
121
                              JOIN items USING (itemnumber)
122
                              JOIN items USING (itemnumber)
122
                              WHERE borrowernumber = $borrowernumber");
123
                              WHERE borrowernumber = $borrowernumber");
123
124
124
# We have a book available homed in borrower branch, no point fiddling with AutomaticItemReturn
125
# We have a book available homed in borrower branch, no point fiddling with AutomaticItemReturn
125
t::lib::Mocks::mock_preference('AutomaticItemReturn', 0);
126
C4::Context->set_preference('AutomaticItemReturn', 0);
126
test_queue ('take from homebranch',  0, $borrower_branchcode, $borrower_branchcode);
127
test_queue ('take from homebranch',  0, $borrower_branchcode, $borrower_branchcode);
127
test_queue ('take from homebranch',  1, $borrower_branchcode, $borrower_branchcode);
128
test_queue ('take from homebranch',  1, $borrower_branchcode, $borrower_branchcode);
128
129
Lines 131-144 $dbh->do("DELETE FROM hold_fill_targets"); Link Here
131
$dbh->do("DELETE FROM issues WHERE itemnumber IN (SELECT itemnumber FROM items WHERE homebranch = '$borrower_branchcode' AND holdingbranch = '$borrower_branchcode')");
132
$dbh->do("DELETE FROM issues WHERE itemnumber IN (SELECT itemnumber FROM items WHERE homebranch = '$borrower_branchcode' AND holdingbranch = '$borrower_branchcode')");
132
$dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode' AND holdingbranch = '$borrower_branchcode'");
133
$dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode' AND holdingbranch = '$borrower_branchcode'");
133
# test_queue will flush
134
# test_queue will flush
134
t::lib::Mocks::mock_preference('AutomaticItemReturn', 1);
135
C4::Context->set_preference('AutomaticItemReturn', 1);
135
# Not sure how to make this test more difficult - holding branch does not matter
136
# Not sure how to make this test more difficult - holding branch does not matter
136
137
137
$dbh->do("DELETE FROM tmp_holdsqueue");
138
$dbh->do("DELETE FROM tmp_holdsqueue");
138
$dbh->do("DELETE FROM hold_fill_targets");
139
$dbh->do("DELETE FROM hold_fill_targets");
139
$dbh->do("DELETE FROM issues WHERE itemnumber IN (SELECT itemnumber FROM items WHERE homebranch = '$borrower_branchcode')");
140
$dbh->do("DELETE FROM issues WHERE itemnumber IN (SELECT itemnumber FROM items WHERE homebranch = '$borrower_branchcode')");
140
$dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode'");
141
$dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode'");
141
t::lib::Mocks::mock_preference('AutomaticItemReturn', 0);
142
C4::Context->set_preference('AutomaticItemReturn', 0);
142
# We have a book available held in borrower branch
143
# We have a book available held in borrower branch
143
test_queue ('take from holdingbranch', 0, $borrower_branchcode, $borrower_branchcode);
144
test_queue ('take from holdingbranch', 0, $borrower_branchcode, $borrower_branchcode);
144
test_queue ('take from holdingbranch', 1, $borrower_branchcode, $borrower_branchcode);
145
test_queue ('take from holdingbranch', 1, $borrower_branchcode, $borrower_branchcode);
Lines 177-183 $dbh->do("DELETE FROM default_branch_circ_rules"); Link Here
177
$dbh->do("DELETE FROM default_branch_item_rules");
178
$dbh->do("DELETE FROM default_branch_item_rules");
178
$dbh->do("DELETE FROM default_circ_rules");
179
$dbh->do("DELETE FROM default_circ_rules");
179
180
180
t::lib::Mocks::mock_preference('UseTransportCostMatrix', 0);
181
C4::Context->set_preference('UseTransportCostMatrix', 0);
181
182
182
$itemtype = Koha::ItemTypes->search->next->itemtype;
183
$itemtype = Koha::ItemTypes->search->next->itemtype;
183
184
Lines 306-312 is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue fill Link Here
306
# 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed
307
# 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed
307
# and make today a holiday for MPL. When we run it again we should only
308
# and make today a holiday for MPL. When we run it again we should only
308
# have 1 row in the holds queue
309
# have 1 row in the holds queue
309
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 1);
310
C4::Context->set_preference('HoldsQueueSkipClosed', 1);
310
my $today = dt_from_string();
311
my $today = dt_from_string();
311
C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday(
312
C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday(
312
    day         => $today->day(),
313
    day         => $today->day(),
Lines 321-327 is( Koha::Calendar->new( branchcode => $branchcodes[0] )->is_holiday( $today ), Link Here
321
C4::HoldsQueue::CreateQueue();
322
C4::HoldsQueue::CreateQueue();
322
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
323
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
323
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" );
324
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0);
325
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
325
326
326
$dbh->do("DELETE FROM default_circ_rules");
327
$dbh->do("DELETE FROM default_circ_rules");
327
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
328
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
Lines 334-344 is( @$holds_queue, 3, "Holds queue filling correct number for holds for default Link Here
334
# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed
335
# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed
335
# and use our previously created holiday for MPL
336
# and use our previously created holiday for MPL
336
# When we run it again we should only have 2 rows in the holds queue
337
# When we run it again we should only have 2 rows in the holds queue
337
t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 1 );
338
C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 );
338
C4::HoldsQueue::CreateQueue();
339
C4::HoldsQueue::CreateQueue();
339
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
340
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
340
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
341
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
341
t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 0 );
342
C4::Context->set_preference( 'HoldsQueueSkipClosed', 0 );
342
343
343
# Bug 14297
344
# Bug 14297
344
$itemtype = Koha::ItemTypes->search->next->itemtype;
345
$itemtype = Koha::ItemTypes->search->next->itemtype;
Lines 387-394 $dbh->do(" Link Here
387
    ( '$library_A', '$itemtype', 2, 'homebranch' ), ( '$library_B', '$itemtype', 1, 'homebranch' );
388
    ( '$library_A', '$itemtype', 2, 'homebranch' ), ( '$library_B', '$itemtype', 1, 'homebranch' );
388
");
389
");
389
390
390
t::lib::Mocks::mock_preference('StaticHoldsQueueWeight', join( ',', $library_B, $library_A, $library_C ) );
391
$dbh->do( "UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'",
391
t::lib::Mocks::mock_preference('RandomizeHoldsQueueWeight', 0 );
392
    undef, join( ',', $library_B, $library_A, $library_C ) );
393
$dbh->do( "UPDATE systempreferences SET value = 0 WHERE variable = 'RandomizeHoldsQueueWeight'" );
392
394
393
my $reserve_id = AddReserve ( $library_C, $borrowernumber, $biblionumber, '', 1 );
395
my $reserve_id = AddReserve ( $library_C, $borrowernumber, $biblionumber, '', 1 );
394
C4::HoldsQueue::CreateQueue();
396
C4::HoldsQueue::CreateQueue();
Lines 414-420 $dbh->do("DELETE FROM default_branch_item_rules"); Link Here
414
$dbh->do("DELETE FROM default_circ_rules");
416
$dbh->do("DELETE FROM default_circ_rules");
415
$dbh->do("DELETE FROM branch_item_rules");
417
$dbh->do("DELETE FROM branch_item_rules");
416
418
417
t::lib::Mocks::mock_preference("UseTransportCostMatrix",1);
419
C4::Context->set_preference("UseTransportCostMatrix",1);
418
420
419
my $tc_rs = $schema->resultset('TransportCost');
421
my $tc_rs = $schema->resultset('TransportCost');
420
$tc_rs->create({ frombranch => $library_A, tobranch => $library_B, cost => 0, disable_transfer => 1 });
422
$tc_rs->create({ frombranch => $library_A, tobranch => $library_B, cost => 0, disable_transfer => 1 });
Lines 454-460 sub test_queue { Link Here
454
456
455
    $test_name = "$test_name (".($use_cost_matrix ? "" : "don't ")."use cost matrix)";
457
    $test_name = "$test_name (".($use_cost_matrix ? "" : "don't ")."use cost matrix)";
456
458
457
    t::lib::Mocks::mock_preference('UseTransportCostMatrix', $use_cost_matrix);
459
    $use_cost_matrix_sth->execute($use_cost_matrix);
460
    C4::Context->clear_syspref_cache();
458
    C4::HoldsQueue::CreateQueue();
461
    C4::HoldsQueue::CreateQueue();
459
462
460
    my $results = $dbh->selectall_arrayref($test_sth, { Slice => {} }); # should be only one
463
    my $results = $dbh->selectall_arrayref($test_sth, { Slice => {} }); # should be only one
461
- 

Return to bug 11998