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 <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-04-18 10:37:18 +01:00 committed by Kyle M Hall
parent 5e8ded21af
commit 9c5b819100
4 changed files with 36 additions and 15 deletions

View file

@ -397,7 +397,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
@ -410,11 +417,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 ];
}
# -------------------------------------------------------------------

View file

@ -127,7 +127,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;

View file

@ -48,7 +48,7 @@
[% ELSE %]
<li class="disabled">
[% END %]
<a href="/cgi-bin/koha/admin/aqplan.pl?budget_period_id=[% budget_period_id %]&amp;authcat=[% auth_cats_loo.authcat %]">Plan by [% auth_cats_loo.authcat %]</a>
<a href="/cgi-bin/koha/admin/aqplan.pl?budget_period_id=[% budget_period_id %]&amp;authcat=[% auth_cats_loo %]">Plan by [% auth_cats_loo %]</a>
</li>
[% END %]
</ul>
@ -58,4 +58,4 @@
<div class="btn-group"><a class="btn btn-small" id="newrootbudget" href="/cgi-bin/koha/admin/aqbudgetperiods.pl?op=add_form"><i class="fa fa-plus"></i> New budget</a></div>
[% END %]
</div>
</div>

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 133;
use Test::More tests => 134;
BEGIN {
use_ok('C4::Budgets')
@ -635,11 +635,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";
@ -653,7 +658,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} = "";
@ -667,7 +685,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} = "";