From 1b9c688d935ca2825dac2812ef32decf6d30492a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 18 Apr 2016 10:37:18 +0100 Subject: [PATCH] Bug 15009: QA follow-up This patch adds a test to check the unicity of auth cats, simplify the GetBudgetAuthCats subroutine and make it return an arrayref of scalar instead of an arrayref of hashref with only 1 key. Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall (cherry picked from commit 9c5b8191009eba54e851512c9cfa2e3d5ab949df) Signed-off-by: Julian Maurice --- C4/Budgets.pm | 15 ++++++---- admin/aqplan.pl | 2 +- .../en/includes/budgets-admin-toolbar.inc | 4 +-- t/db_dependent/Budgets.t | 30 +++++++++++++++---- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 7d15bae114..cd7198a8c5 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -401,7 +401,14 @@ sub GetBudgetName { return $sth->fetchrow_array; } -# ------------------------------------------------------------------- +=head2 GetBudgetAuthCats + + my $auth_cats = &GetBudgetAuthCats($budget_period_id); + +Return the list of authcat for a given budget_period_id + +=cut + sub GetBudgetAuthCats { my ($budget_period_id) = shift; # now, populate the auth_cats_loop used in the budget planning button @@ -414,11 +421,7 @@ sub GetBudgetAuthCats { $authcats{$sort1_authcat}=1 if $sort1_authcat; $authcats{$sort2_authcat}=1 if $sort2_authcat; } - my @auth_cats_loop; - foreach (sort keys %authcats) { - push @auth_cats_loop,{ authcat => $_ }; - } - return \@auth_cats_loop; + return [ sort keys %authcats ]; } # ------------------------------------------------------------------- diff --git a/admin/aqplan.pl b/admin/aqplan.pl index 7374428983..ba2ee1e8a7 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -126,7 +126,7 @@ while ( my ($category) = $sth->fetchrow_array ) { push( @category_list, 'MONTHS' ); push( @category_list, 'ITEMTYPES' ); push( @category_list, 'BRANCHES' ); -push( @category_list, $$_{'authcat'} ) foreach @$auth_cats_loop; +push( @category_list, $_ ) foreach @$auth_cats_loop; #reorder the list @category_list = sort { $a cmp $b } @category_list; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-toolbar.inc index 03c9b45312..7172a8de39 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-toolbar.inc @@ -48,7 +48,7 @@ [% ELSE %]
  • [% END %] - Plan by [% auth_cats_loo.authcat %] + Plan by [% auth_cats_loo %]
  • [% END %] @@ -58,4 +58,4 @@ [% END %] - \ No newline at end of file + diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 843ed3d188..7fd5d18468 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -1,5 +1,5 @@ use Modern::Perl; -use Test::More tests => 125; +use Test::More tests => 126; BEGIN { use_ok('C4::Budgets') @@ -591,11 +591,16 @@ is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id}, # Test GetBudgetAuthCats -my $budgetPeriodId = 1; +my $budgetPeriodId = AddBudgetPeriod({ + budget_period_startdate => '2008-01-01', + budget_period_enddate => '2008-12-31', + budget_period_description => 'just another budget', + budget_period_active => 0, +}); -my $bdgts = GetBudgets(); +$budgets = GetBudgets(); my $i = 0; -for my $budget ( @{$bdgts} ) +for my $budget ( @$budgets ) { $budget->{sort1_authcat} = "sort1_authcat_$i"; $budget->{sort2_authcat} = "sort2_authcat_$i"; @@ -609,7 +614,20 @@ 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} ) +for my $budget ( @$budgets ) +{ + $budget->{sort1_authcat} = "sort_authcat_$i"; + $budget->{sort2_authcat} = "sort_authcat_$i"; + $budget->{budget_period_id} = $budgetPeriodId; + ModBudget( $budget ); + $i++; +} + +$authCat = GetBudgetAuthCats($budgetPeriodId); +is( scalar @$authCat, scalar @$budgets, "GetBudgetAuthCats returns distinct authCat" ); + +$i = 0; +for my $budget ( @$budgets ) { $budget->{sort1_authcat} = "sort1_authcat_$i"; $budget->{sort2_authcat} = ""; @@ -623,7 +641,7 @@ $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} ) +for my $budget ( @$budgets ) { $budget->{sort1_authcat} = ""; $budget->{sort2_authcat} = ""; -- 2.39.5