From c5708ac04bc9577013b52f7e81bca9290aa32909 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 for 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 0b35e5f..336c7c9 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') @@ -934,7 +934,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'); @@ -952,8 +952,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 = { @@ -998,6 +1003,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 @@ -1062,7 +1077,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}, @@ -1083,6 +1098,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