From d2c3a7796ff4e1c2203d7dc2d0cba00534772c2e Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Tue, 17 Apr 2018 23:39:57 +0000 Subject: [PATCH] Bug 18736: Add missing test cases [BUGGY] The ELSE case is flawed. This needs fixing. The third parameter is budgets, and needs to be valid. It currently is passing, because undef+0= 0, and the expected values are set to zero. They should be non-zero! --- t/db_dependent/Budgets.t | 58 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 7dd22d4..c697300 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -807,12 +807,14 @@ is( scalar @{$authCat}, 0, "GetBudgetAuthCats returns only non-empty sorting cat subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { - plan tests => 12; + plan tests => 16; #Let's build an order, we need a couple things though t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); my $spent_biblio = $builder->build({ source => 'Biblio' }); + my $item_1 = $builder->build({ source => 'Item', value => { biblionumber => $spent_biblio->{biblionumber} } }); + my $biblioitem_1 = $builder->build({ source => 'Biblioitem', value => { biblionumber => $spent_biblio->{biblionumber}, itemnumber => $item_1->{itemnumber} } }); my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } }); my $spent_invoice = $builder->build({ source => 'Aqinvoice'}); my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' } }); @@ -860,7 +862,6 @@ subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { #Let's test some budget planning #Regression tests for bug 18736 #We need an item to test by BRANCHES - my $item_1 = $builder->build({ source => 'Item' }); my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber} } }); my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} ); my $cell = { @@ -868,23 +869,46 @@ subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here budget_id => $spent_order->{budget_id}, budget_period_id => $spent_fund->budget_period_id, + sort1_authcat => $spent_order->{sort1_authcat}, + sort2_authcat => $spent_order->{sort1_authcat}, + }; + my $test_values = { + 'MONTHS' => { + authvalue => $spent_order->{entrydate}, + expected_rounded => 9.85, + expected_exact => 9.8542, + }, + 'BRANCHES' => { + authvalue => $item_1->{homebranch}, + expected_rounded => 9.85, + expected_exact => 9.8542, + }, + 'ITEMTYPES' => { + authvalue => $biblioitem_1->{itemtype}, + expected_rounded => 78.80, + expected_exact => 78.8336, + }, + 'ELSE' => { + authvalue => 'purposefully_bad_but_needs_to_be_good', + expected_rounded => 0, + expected_exact => 0, + }, }; - t::lib::Mocks::mock_preference('OrderPriceRounding',''); - my ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now - is ( $actual, '9.854200', "We expect this to be an exact order cost"); #really we should expect cost*quantity but we don't - t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); - ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now - is ( $actual, '9.8500', "We expect this to be a rounded order cost"); #really we should expect cost*quantity but we don't - $cell->{authcat} = 'BRANCHES'; - $cell->{authvalue} = $item_1->{homebranch}; - ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now - t::lib::Mocks::mock_preference('OrderPriceRounding',''); - ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now - is ( $actual, '9.854200', "We expect this to be full cost for items from the branch"); #here we rely on items having been created for each order, again quantity should be considered - t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); - ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now - is ( $actual, '9.8500', "We expect this to be rounded cost for items from the branch"); #here we rely on items having been created for each order, again quantity should be considered + for my $authcat ( keys %$test_values ) { + my $test_val = $test_values->{$authcat}; + my $authvalue = $test_val->{authvalue}; + my $expected_rounded = $test_val->{expected_rounded}; + my $expected_exact = $test_val->{expected_exact}; + $cell->{authcat} = $authcat; + $cell->{authvalue} = $authvalue; + t::lib::Mocks::mock_preference('OrderPriceRounding',''); + my ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now + is ( $actual+0, $expected_exact, "We expect this to be an exact order cost ($authcat)"); #really we should expect cost*quantity but we don't + t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); + ( $actual ) = GetBudgetsPlanCell( $cell, undef, $spent_order); #we are only testing the actual for now + is ( $actual+0, $expected_rounded, "We expect this to be a rounded order cost ($authcat)"); #really we should expect cost*quantity but we don't + } #Okay, now we can receive the order, giving the price as the user would -- 2.1.4