From 716dec0e43dcd283f3c7fb617bb383d345c9a36a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 29 Nov 2023 13:05:40 +0000 Subject: [PATCH] Bug 35431: Unit tests --- t/db_dependent/HoldsQueue.t | 73 ++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t index 7875c69eedd..78e27e67ecc 100755 --- a/t/db_dependent/HoldsQueue.t +++ b/t/db_dependent/HoldsQueue.t @@ -8,7 +8,7 @@ use Modern::Perl; -use Test::More tests => 61; +use Test::More tests => 62; use Data::Dumper; use C4::Calendar qw( new insert_single_holiday ); @@ -23,6 +23,8 @@ use Koha::CirculationRules; use t::lib::TestBuilder; use t::lib::Mocks; +use Test::MockModule; +use Test::Warn; BEGIN { use FindBin; @@ -38,6 +40,72 @@ $dbh->do("DELETE FROM circulation_rules"); my $builder = t::lib::TestBuilder->new; +subtest "MapItemsToHoldRequests tests" => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + subtest "TransportCostMatrix tests" => sub { + t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 ); + t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'homebranch' ); + my $HoldsQueue = Test::MockModule->new('C4::HoldsQueue'); + $HoldsQueue->mock( + 'least_cost_branch', + sub { + warn "Checking transport cost matrix"; + return; + } + ); + + my $branch_a = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); + my $branch_b = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); + my $item_1 = $builder->build_sample_item( + { homebranch => $branch_a->branchcode, holdingbranch => $branch_b->branchcode } ); + my $patron = $builder->build_object( + { + class => "Koha::Patrons", + value => { + branchcode => $branch_b->branchcode, + } + } + ); + my $hold = $builder->build_object( + { + class => 'Koha::Holds', + value => { + itemnumber => undef, + biblionumber => $item_1->biblionumber, + branchcode => $branch_b->branchcode, + item_level_hold => 0, + item_group_id => undef, + itemtype => undef, + borrowernumber => $patron->id, + } + } + ); + + my $tcm = { + $branch_b->branchcode => { + $branch_a->branchcode => { cost => 10 }, + } + }; + + my $hq_item = $item_1->unblessed; + $hq_item->{holdallowed} = 'from_any_library'; + $hq_item->{hold_fullfillment_policy} = 'any'; + my $hq_hold = $hold->unblessed; + $hq_hold->{borrowerbranch} = $branch_b->branchcode; + warning_is { + C4::HoldsQueue::MapItemsToHoldRequests( [$hq_hold], [$hq_item], [ $branch_a->branchcode ], $tcm ); + } + "Checking transport cost matrix", + "Transport cost matrix is checked when HoldsQueuePrioritizeBranch does not match"; + + }; + + $schema->storage->txn_rollback; +}; + t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' ); t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); @@ -2091,3 +2159,6 @@ subtest "GetItemsAvailableToFillHoldsRequestsForBib" => sub { is_deeply( [$items->[0]->{itemnumber},$items->[1]->{itemnumber}],[$item_2->itemnumber,$item_3->itemnumber],"Correct two items retrieved"); }; + + + -- 2.30.2