From 3c8c0591e2344ba6e44df16319b47065d23d652e 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 Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer Signed-off-by: Galen Charlton --- 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 ea371c8437..882172f05e 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -713,6 +713,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 bfb910bf63..54beddfe5f 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=>20; +use Test::More tests => 22; BEGIN {use_ok('C4::Budgets') } use C4::Dates; @@ -94,6 +94,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, @@ -109,6 +110,11 @@ 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"); + my $second_budget_id; ok($second_budget_id=AddBudget( { budget_code => "ZZZZ", -- 2.39.5