From 18475a028ae0a8f82c4ef45980cc1eba5c4c2ecb Mon Sep 17 00:00:00 2001 From: charles Date: Fri, 25 Mar 2016 17:09:24 -0400 Subject: [PATCH] Bug 15009 - Adds unit tests for C4::Budget::GetBudgetAuthCats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc VĂ©ron --- t/db_dependent/Budgets.t | 51 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 0f59b8b..269b147 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -1,5 +1,5 @@ use Modern::Perl; -use Test::More tests => 130; +use Test::More tests => 133; BEGIN { use_ok('C4::Budgets') @@ -623,6 +623,55 @@ is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id}, is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id}, undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" ); +# Test GetBudgetAuthCats + +my $budgetPeriodId = 1; + +my $bdgts = GetBudgets(); +my $i = 0; +for my $budget ( @{$bdgts} ) +{ + $budget->{sort1_authcat} = "sort1_authcat_$i"; + $budget->{sort2_authcat} = "sort2_authcat_$i"; + $budget->{budget_period_id} = $budgetPeriodId; + ModBudget( $budget ); + $i++; +} + +my $authCat = GetBudgetAuthCats($budgetPeriodId); + +is( scalar @{$authCat}, $i * 2, "GetBudgetAuthCats returns only non-empty sorting categories (no empty authCat in db)" ); + +$i = 0; +for my $budget ( @{$bdgts} ) +{ + $budget->{sort1_authcat} = "sort1_authcat_$i"; + $budget->{sort2_authcat} = ""; + $budget->{budget_period_id} = $budgetPeriodId; + ModBudget( $budget ); + $i++; +} + +$authCat = GetBudgetAuthCats($budgetPeriodId); + +is( scalar @{$authCat}, $i, "GetBudgetAuthCats returns only non-empty sorting categories (empty sort2_authcat on all records)" ); + +$i = 0; +for my $budget ( @{$bdgts} ) +{ + $budget->{sort1_authcat} = ""; + $budget->{sort2_authcat} = ""; + $budget->{budget_period_id} = $budgetPeriodId; + ModBudget( $budget ); + $i++; +} + +$authCat = GetBudgetAuthCats($budgetPeriodId); + +is( scalar @{$authCat}, 0, "GetBudgetAuthCats returns only non-empty sorting categories (all empty)" ); + +# /Test GetBudgetAuthCats + sub _get_dependencies { my ($budget_hierarchy) = @_; my $graph; -- 1.7.10.4