| Lines 18-23
          use Koha::Database;
      
      
        Link Here | 
        
          | 18 | use Koha::DateUtils; | 18 | use Koha::DateUtils; | 
        
          | 19 |  | 19 |  | 
        
          | 20 | use t::lib::TestBuilder; | 20 | use t::lib::TestBuilder; | 
            
              |  |  | 21 | use t::lib::Mocks; | 
        
          | 21 |  | 22 |  | 
        
          | 22 | BEGIN { | 23 | BEGIN { | 
        
          | 23 |     use FindBin; | 24 |     use FindBin; | 
  
    | Lines 61-68
          my $itemtype = $builder->build({ source => 'Itemtype', value => { notforloan =>
      
      
        Link Here | 
        
          | 61 |  | 62 |  | 
        
          | 62 | #Set up the stage | 63 | #Set up the stage | 
        
          | 63 | # Sysprefs and cost matrix | 64 | # Sysprefs and cost matrix | 
          
            
              | 64 | C4::Context->set_preference('HoldsQueueSkipClosed', 0); | 65 | t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0); | 
            
              | 65 | C4::Context->set_preference('LocalHoldsPriority', 0); | 66 | t::lib::Mocks::mock_preference('LocalHoldsPriority', 0); | 
        
          | 66 | $dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef, | 67 | $dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef, | 
        
          | 67 |          join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code)); | 68 |          join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code)); | 
        
          | 68 | $dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'"); | 69 | $dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'"); | 
  
    | Lines 118-124
          my $test_sth = $dbh->prepare("SELECT * FROM hold_fill_targets
      
      
        Link Here | 
        
          | 118 |                               WHERE borrowernumber = $borrowernumber"); | 119 |                               WHERE borrowernumber = $borrowernumber"); | 
        
          | 119 |  | 120 |  | 
        
          | 120 | # We have a book available homed in borrower branch, no point fiddling with AutomaticItemReturn | 121 | # We have a book available homed in borrower branch, no point fiddling with AutomaticItemReturn | 
          
            
              | 121 | C4::Context->set_preference('AutomaticItemReturn', 0); | 122 | t::lib::Mocks::mock_preference('AutomaticItemReturn', 0); | 
        
          | 122 | test_queue ('take from homebranch',  0, $borrower_branchcode, $borrower_branchcode); | 123 | test_queue ('take from homebranch',  0, $borrower_branchcode, $borrower_branchcode); | 
        
          | 123 | test_queue ('take from homebranch',  1, $borrower_branchcode, $borrower_branchcode); | 124 | test_queue ('take from homebranch',  1, $borrower_branchcode, $borrower_branchcode); | 
        
          | 124 |  | 125 |  | 
  
    | Lines 127-140
          $dbh->do("DELETE FROM hold_fill_targets");
      
      
        Link Here | 
        
          | 127 | $dbh->do("DELETE FROM issues WHERE itemnumber IN (SELECT itemnumber FROM items WHERE homebranch = '$borrower_branchcode' AND holdingbranch = '$borrower_branchcode')"); | 128 | $dbh->do("DELETE FROM issues WHERE itemnumber IN (SELECT itemnumber FROM items WHERE homebranch = '$borrower_branchcode' AND holdingbranch = '$borrower_branchcode')"); | 
        
          | 128 | $dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode' AND holdingbranch = '$borrower_branchcode'"); | 129 | $dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode' AND holdingbranch = '$borrower_branchcode'"); | 
        
          | 129 | # test_queue will flush | 130 | # test_queue will flush | 
          
            
              | 130 | C4::Context->set_preference('AutomaticItemReturn', 1); | 131 | t::lib::Mocks::mock_preference('AutomaticItemReturn', 1); | 
        
          | 131 | # Not sure how to make this test more difficult - holding branch does not matter | 132 | # Not sure how to make this test more difficult - holding branch does not matter | 
        
          | 132 |  | 133 |  | 
        
          | 133 | $dbh->do("DELETE FROM tmp_holdsqueue"); | 134 | $dbh->do("DELETE FROM tmp_holdsqueue"); | 
        
          | 134 | $dbh->do("DELETE FROM hold_fill_targets"); | 135 | $dbh->do("DELETE FROM hold_fill_targets"); | 
        
          | 135 | $dbh->do("DELETE FROM issues WHERE itemnumber IN (SELECT itemnumber FROM items WHERE homebranch = '$borrower_branchcode')"); | 136 | $dbh->do("DELETE FROM issues WHERE itemnumber IN (SELECT itemnumber FROM items WHERE homebranch = '$borrower_branchcode')"); | 
        
          | 136 | $dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode'"); | 137 | $dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode'"); | 
          
            
              | 137 | C4::Context->set_preference('AutomaticItemReturn', 0); | 138 | t::lib::Mocks::mock_preference('AutomaticItemReturn', 0); | 
        
          | 138 | # We have a book available held in borrower branch | 139 | # We have a book available held in borrower branch | 
        
          | 139 | test_queue ('take from holdingbranch', 0, $borrower_branchcode, $borrower_branchcode); | 140 | test_queue ('take from holdingbranch', 0, $borrower_branchcode, $borrower_branchcode); | 
        
          | 140 | test_queue ('take from holdingbranch', 1, $borrower_branchcode, $borrower_branchcode); | 141 | test_queue ('take from holdingbranch', 1, $borrower_branchcode, $borrower_branchcode); | 
  
    | Lines 173-179
          $dbh->do("DELETE FROM default_branch_circ_rules");
      
      
        Link Here | 
        
          | 173 | $dbh->do("DELETE FROM default_branch_item_rules"); | 174 | $dbh->do("DELETE FROM default_branch_item_rules"); | 
        
          | 174 | $dbh->do("DELETE FROM default_circ_rules"); | 175 | $dbh->do("DELETE FROM default_circ_rules"); | 
        
          | 175 |  | 176 |  | 
          
            
              | 176 | C4::Context->set_preference('UseTransportCostMatrix', 0); | 177 | t::lib::Mocks::mock_preference('UseTransportCostMatrix', 0); | 
        
          | 177 |  | 178 |  | 
        
          | 178 | $itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 } })->{itemtype}; | 179 | $itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 } })->{itemtype}; | 
        
          | 179 |  | 180 |  | 
  
    | Lines 299-305
          is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue fill
      
      
        Link Here | 
        
          | 299 | # 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed | 300 | # 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed | 
        
          | 300 | # and make today a holiday for MPL. When we run it again we should only | 301 | # and make today a holiday for MPL. When we run it again we should only | 
        
          | 301 | # have 1 row in the holds queue | 302 | # have 1 row in the holds queue | 
          
            
              | 302 | C4::Context->set_preference('HoldsQueueSkipClosed', 1); | 303 | t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 1); | 
        
          | 303 | my $today = dt_from_string(); | 304 | my $today = dt_from_string(); | 
        
          | 304 | C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday( | 305 | C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday( | 
        
          | 305 |     day         => $today->day(), | 306 |     day         => $today->day(), | 
  
    | Lines 314-320
          is( Koha::Calendar->new( branchcode => $branchcodes[0] )->is_holiday( $today ),
      
      
        Link Here | 
        
          | 314 | C4::HoldsQueue::CreateQueue(); | 315 | C4::HoldsQueue::CreateQueue(); | 
        
          | 315 | $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); | 316 | $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); | 
        
          | 316 | is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" ); | 317 | is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" ); | 
          
            
              | 317 | C4::Context->set_preference('HoldsQueueSkipClosed', 0); | 318 | t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 0); | 
        
          | 318 |  | 319 |  | 
        
          | 319 | $dbh->do("DELETE FROM default_circ_rules"); | 320 | $dbh->do("DELETE FROM default_circ_rules"); | 
        
          | 320 | $dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); | 321 | $dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); | 
  
    | Lines 327-348
          is( @$holds_queue, 3, "Holds queue filling correct number for holds for default
      
      
        Link Here | 
        
          | 327 | # one of which is coming from MPL. Let's enable HoldsQueueSkipClosed | 328 | # one of which is coming from MPL. Let's enable HoldsQueueSkipClosed | 
        
          | 328 | # and use our previously created holiday for MPL | 329 | # and use our previously created holiday for MPL | 
        
          | 329 | # When we run it again we should only have 2 rows in the holds queue | 330 | # When we run it again we should only have 2 rows in the holds queue | 
          
            
              | 330 | C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 ); | 331 | t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 1 ); | 
        
          | 331 | C4::HoldsQueue::CreateQueue(); | 332 | C4::HoldsQueue::CreateQueue(); | 
        
          | 332 | $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); | 333 | $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); | 
        
          | 333 | is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" ); | 334 | is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" ); | 
          
            
              | 334 | C4::Context->set_preference( 'HoldsQueueSkipClosed', 0 ); | 335 | t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 0 ); | 
        
          | 335 |  | 336 |  | 
        
          | 336 | ## Test LocalHoldsPriority | 337 | ## Test LocalHoldsPriority | 
          
            
              | 337 | C4::Context->set_preference('LocalHoldsPriority', 1); | 338 | t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); | 
        
          | 338 |  | 339 |  | 
        
          | 339 | $dbh->do("DELETE FROM default_circ_rules"); | 340 | $dbh->do("DELETE FROM default_circ_rules"); | 
        
          | 340 | $dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); | 341 | $dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )"); | 
        
          | 341 | $dbh->do("DELETE FROM issues"); | 342 | $dbh->do("DELETE FROM issues"); | 
        
          | 342 |  | 343 |  | 
        
          | 343 | # Test homebranch = patron branch | 344 | # Test homebranch = patron branch | 
          
            
              | 344 | C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary'); | 345 | t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary'); | 
            
              | 345 | C4::Context->set_preference('LocalHoldsPriorityItemControl', 'homebranch'); | 346 | t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'homebranch'); | 
        
          | 346 | C4::Context->clear_syspref_cache(); | 347 | C4::Context->clear_syspref_cache(); | 
        
          | 347 | $dbh->do("DELETE FROM reserves"); | 348 | $dbh->do("DELETE FROM reserves"); | 
        
          | 348 | $sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); | 349 | $sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); | 
  
    | Lines 358-365
          $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice
      
      
        Link Here | 
        
          | 358 | is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library"); | 359 | is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library"); | 
        
          | 359 |  | 360 |  | 
        
          | 360 | # Test holdingbranch = patron branch | 361 | # Test holdingbranch = patron branch | 
          
            
              | 361 | C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary'); | 362 | t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary'); | 
            
              | 362 | C4::Context->set_preference('LocalHoldsPriorityItemControl', 'holdingbranch'); | 363 | t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'holdingbranch'); | 
        
          | 363 | C4::Context->clear_syspref_cache(); | 364 | C4::Context->clear_syspref_cache(); | 
        
          | 364 | $dbh->do("DELETE FROM reserves"); | 365 | $dbh->do("DELETE FROM reserves"); | 
        
          | 365 | $sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); | 366 | $sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); | 
  
    | Lines 375-382
          $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice
      
      
        Link Here | 
        
          | 375 | is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library"); | 376 | is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library"); | 
        
          | 376 |  | 377 |  | 
        
          | 377 | # Test holdingbranch = pickup branch | 378 | # Test holdingbranch = pickup branch | 
          
            
              | 378 | C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary'); | 379 | t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary'); | 
            
              | 379 | C4::Context->set_preference('LocalHoldsPriorityItemControl', 'holdingbranch'); | 380 | t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'holdingbranch'); | 
        
          | 380 | C4::Context->clear_syspref_cache(); | 381 | C4::Context->clear_syspref_cache(); | 
        
          | 381 | $dbh->do("DELETE FROM reserves"); | 382 | $dbh->do("DELETE FROM reserves"); | 
        
          | 382 | $sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); | 383 | $sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); | 
  
    | Lines 392-399
          $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice
      
      
        Link Here | 
        
          | 392 | is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library"); | 393 | is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library"); | 
        
          | 393 |  | 394 |  | 
        
          | 394 | # Test homebranch = pickup branch | 395 | # Test homebranch = pickup branch | 
          
            
              | 395 | C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary'); | 396 | t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary'); | 
            
              | 396 | C4::Context->set_preference('LocalHoldsPriorityItemControl', 'homebranch'); | 397 | t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'homebranch'); | 
        
          | 397 | C4::Context->clear_syspref_cache(); | 398 | C4::Context->clear_syspref_cache(); | 
        
          | 398 | $dbh->do("DELETE FROM reserves"); | 399 | $dbh->do("DELETE FROM reserves"); | 
        
          | 399 | $sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); | 400 | $sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 ); | 
  
    | Lines 408-414
          C4::HoldsQueue::CreateQueue();
      
      
        Link Here | 
        
          | 408 | $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); | 409 | $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} }); | 
        
          | 409 | is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library"); | 410 | is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library"); | 
        
          | 410 |  | 411 |  | 
          
            
              | 411 | C4::Context->set_preference('LocalHoldsPriority', 0); | 412 | t::lib::Mocks::mock_preference('LocalHoldsPriority', 0); | 
        
          | 412 | ## End testing of LocalHoldsPriority | 413 | ## End testing of LocalHoldsPriority | 
        
          | 413 |  | 414 |  | 
        
          | 414 |  | 415 |  | 
  
    | Lines 487-493
          $dbh->do("DELETE FROM default_branch_item_rules");
      
      
        Link Here | 
        
          | 487 | $dbh->do("DELETE FROM default_circ_rules"); | 488 | $dbh->do("DELETE FROM default_circ_rules"); | 
        
          | 488 | $dbh->do("DELETE FROM branch_item_rules"); | 489 | $dbh->do("DELETE FROM branch_item_rules"); | 
        
          | 489 |  | 490 |  | 
          
            
              | 490 | C4::Context->set_preference("UseTransportCostMatrix",1); | 491 | t::lib::Mocks::mock_preference("UseTransportCostMatrix",1); | 
        
          | 491 |  | 492 |  | 
        
          | 492 | my $tc_rs = $schema->resultset('TransportCost'); | 493 | my $tc_rs = $schema->resultset('TransportCost'); | 
        
          | 493 | $tc_rs->create({ frombranch => $library_A, tobranch => $library_B, cost => 0, disable_transfer => 1 }); | 494 | $tc_rs->create({ frombranch => $library_A, tobranch => $library_B, cost => 0, disable_transfer => 1 }); | 
  
    | Lines 518-524
          is( @$holds_queue, 0, "Bug 15062 - Holds queue with Transport Cost Matrix will t
      
      
        Link Here | 
        
          | 518 | # End Bug 15062 | 519 | # End Bug 15062 | 
        
          | 519 |  | 520 |  | 
        
          | 520 | # Test hold_fulfillment_policy | 521 | # Test hold_fulfillment_policy | 
          
            
              | 521 | C4::Context->set_preference( "UseTransportCostMatrix", 0 ); | 522 | t::lib::Mocks::mock_preference( "UseTransportCostMatrix", 0 ); | 
        
          | 522 | $borrowernumber = $borrower3->{borrowernumber}; | 523 | $borrowernumber = $borrower3->{borrowernumber}; | 
        
          | 523 | $library_A = $library1->{branchcode}; | 524 | $library_A = $library1->{branchcode}; | 
        
          | 524 | $library_B = $library2->{branchcode}; | 525 | $library_B = $library2->{branchcode}; | 
  
    | Lines 630-636
          CancelReserve( { reserve_id => $reserve_id } );
      
      
        Link Here | 
        
          | 630 | # End testing hold_fulfillment_policy | 631 | # End testing hold_fulfillment_policy | 
        
          | 631 |  | 632 |  | 
        
          | 632 | # Test hold itemtype limit | 633 | # Test hold itemtype limit | 
          
            
              | 633 | C4::Context->set_preference( "UseTransportCostMatrix", 0 ); | 634 | t::lib::Mocks::mock_preference( "UseTransportCostMatrix", 0 ); | 
        
          | 634 | my $wrong_itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 } })->{itemtype}; | 635 | my $wrong_itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 } })->{itemtype}; | 
        
          | 635 | my $right_itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 } })->{itemtype}; | 636 | my $right_itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 } })->{itemtype}; | 
        
          | 636 | $borrowernumber = $borrower3->{borrowernumber}; | 637 | $borrowernumber = $borrower3->{borrowernumber}; |