From 326386712f7b92c0b29ece06683040eb73490808 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 31 Oct 2019 12:17:04 +0000 Subject: [PATCH] Bug 23934: Unit test --- t/db_dependent/HoldsQueue.t | 66 ++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 8c8bb430dd..b88ec96565 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -794,33 +794,51 @@ Koha::Holds->find( $reserve_id )->cancel; # End testing hold itemtype limit -# Test Local Holds Priority - Bug 18001 -t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); -t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary'); -t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'homebranch'); - -$dbh->do("DELETE FROM tmp_holdsqueue"); -$dbh->do("DELETE FROM hold_fill_targets"); -$dbh->do("DELETE FROM reserves"); - -$item = Koha::Items->find( { biblionumber => $biblionumber } ); -$item->holdingbranch( $item->homebranch ); -$item->store(); - -my $item2 = Koha::Item->new( $item->unblessed ); -$item2->itemnumber( undef ); -$item2->store(); - -my $item3 = Koha::Item->new( $item->unblessed ); -$item3->itemnumber( undef ); -$item3->store(); +subtest "Test Local Holds Priority" => sub { + plan tests=>2; + + t::lib::Mocks::mock_preference('LocalHoldsPriority', 1); + t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary'); + t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'homebranch'); + my $branch = $builder->build_object({ class => 'Koha::Libraries' }); + my $branch2 = $builder->build_object({ class => 'Koha::Libraries' }); + my $local_patron = $builder->build_object({ class=>"Koha::Patrons", value=>{ + branchcode => $branch->branchcode + } + }); + my $other_patron = $builder->build_object({ class=>"Koha::Patrons", value=>{ + branchcode => $branch2->branchcode + } + }); + my $biblio = $builder->build_sample_biblio(); + my $item = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + homebranch => $branch->branchcode, + holdingbranch => $branch->branchcode, + }); + + my $item2 = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + homebranch => $branch->branchcode, + holdingbranch => $branch->branchcode, + }); + + my $item3 = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + homebranch => $branch->branchcode, + holdingbranch => $branch->branchcode, + }); + + my $reserve_id = AddReserve( $branch2->branchcode, $other_patron->borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef ); + my $reserve_id2 = AddReserve( $item->homebranch, $local_patron->borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef ); -$reserve_id = AddReserve( $item->homebranch, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef ); + C4::HoldsQueue::CreateQueue(); -C4::HoldsQueue::CreateQueue(); + my $queue_rs = $schema->resultset('TmpHoldsqueue'); + is( $queue_rs->count(), 1, "Hold queue contains one hold from chosen from three possible items" ); + is( $queue_rs->next->borrowernumber,$local_patron->borrowernumber,"We should pick the local hold over the next available"); -my $queue_rs = $schema->resultset('TmpHoldsqueue'); -is( $queue_rs->count(), 1, "Hold queue contains one hold from chosen from three possible items" ); +}; subtest 'Trivial test for UpdateTransportCostMatrix' => sub { plan tests => 1; -- 2.11.0