From ce57f3d342d1e43ea6c66a5a50f5697f1626d929 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Mar 2013 13:27:39 +0100 Subject: [PATCH] Bug 7180: Add UT for C4::Budgets::GetBudgetByCode --- C4/Budgets.pm | 2 ++ t/db_dependent/Budgets.t | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 5fb84a8..6e6b5ee 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -690,6 +690,8 @@ sub GetBudgetByCode { SELECT * FROM aqbudgets WHERE budget_code = ? + ORDER BY budget_id DESC + LIMIT 1 }; my $sth = $dbh->prepare( $query ); $sth->execute( $budget_code ); diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 717f8fe..d9bcd51 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests=>18; +use Test::More tests => 20; BEGIN {use_ok('C4::Budgets') } use C4::Dates; @@ -87,6 +87,7 @@ ok($budget_id=AddBudget( my $budget; ok($budget=GetBudget($budget_id) ,"GetBudget OK"); +$budget_id = $budget->{budget_id}; $$budget{budget_permission}=1; ok($mod_status=ModBudget($budget),"ModBudget OK"); ok(GetBudgets()>0, @@ -102,5 +103,10 @@ ok(GetBudgets({budget_period_id=>GetBudgetPeriod($bpid)->{budget_period_id}},[{" my $budget_name = GetBudgetName( $budget_id ); is($budget_name, $budget->{budget_name}, "Test the GetBudgetName routine"); +my $budget_code = $budget->{budget_code}; +my $budget_by_code = GetBudgetByCode( $budget_code ); +is($budget_by_code->{budget_id}, $budget_id, "GetBudgetByCode, check id"); +is($budget_by_code->{budget_notes}, 'This is a note', "GetBudgetByCode, check notes"); + ok($del_status=DelBudget($budget_id), "DelBudget returned $del_status"); -- 1.7.10.4