From 6a4954d659f61864e30f61e31d4813f38e0bd712 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 24 Aug 2018 11:11:19 +0000 Subject: [PATCH] Bug 18736: Unit tests doe GetBudgetHierarchy prove -v t/db_dependent/Budgets.t --- t/db_dependent/Budgets.t | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index b403145..72e6fd5 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -1,6 +1,6 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 146; +use Test::More tests => 147; BEGIN { use_ok('C4::Budgets') @@ -935,7 +935,7 @@ subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { - plan tests => 16; + plan tests => 24; #Let's build an order, we need a couple things though t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); @@ -953,8 +953,13 @@ subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { authorised_value => 'PICKLE', } }); + my $spent_budget_period = $builder->build({ source => 'Aqbudgetperiod', value => { + } + }); my $spent_budget = $builder->build({ source => 'Aqbudget', value => { sort1_authcat => $budget_authcat->{category_name}, + budget_period_id => $spent_budget_period->{budget_period_id}, + budget_parent_id => undef, } }); my $spent_orderinfo = { @@ -999,6 +1004,16 @@ subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); is($spent_ordered,'78.8',"We expect the ordered amount to be equal to the estimated price rounded times quantity"); + #Test GetBudgetHierarchy for rounding + t::lib::Mocks::mock_preference('OrderPriceRounding',''); + my $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id}); + is ( @$gbh[0]->{budget_spent}+0, 0, "We expect this to be an exact order cost * quantity"); + is ( @$gbh[0]->{budget_ordered}+0, 78.8336, "We expect this to be an exact order cost * quantity"); + t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); + $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id}); + is ( @$gbh[0]->{budget_spent}+0, 0, "We expect this to be an rounded order cost * quantity"); + is ( @$gbh[0]->{budget_ordered}+0, 78.8, "We expect this to be an exact order cost * quantity"); + #Let's test some budget planning #Regression tests for bug 18736 #We need an item to test by BRANCHES @@ -1063,7 +1078,7 @@ subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { }); my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo }); -#And receive +#And receive a copy of the order so we have both spent and ordered values ModReceiveOrder({ biblionumber => $spent_order->{biblionumber}, @@ -1084,6 +1099,16 @@ subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { $spent_spent = GetBudgetSpent( $spent_order->{budget_id} ); is($spent_spent,'78.8',"We expect the spent amount to be equal to the estimated price rounded times quantity"); + #Test GetBudgetHierarchy for rounding + t::lib::Mocks::mock_preference('OrderPriceRounding',''); + $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id}); + is ( @$gbh[0]->{budget_spent}, 78.8336, "We expect this to be an exact order cost * quantity"); + is ( @$gbh[0]->{budget_ordered}, 78.8336, "We expect this to be an exact order cost * quantity"); + t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); + $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id}); + is ( @$gbh[0]->{budget_spent}+0, 78.8, "We expect this to be a rounded order cost * quantity"); + is ( @$gbh[0]->{budget_ordered}, 78.8, "We expect this to be a rounded order cost * quantity"); + }; sub _get_dependencies { -- 2.1.4