From 18d0ced7f6d97fe1c7854f060ae2faacdcae60df Mon Sep 17 00:00:00 2001 From: Mathieu Saby Date: Fri, 12 Apr 2013 15:36:25 +0200 [PATCH 2/2] Bug 9780: Add unit test and a new condition in GetOrdersByBiblionumber This followup adds a new condition in GetOrdersByBiblionumber (return unless $biblionumber) and 4 tests in Acquisition.t --- C4/Acquisition.pm | 1 + t/db_dependent/Acquisition.t | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index c560b2e..05705ce 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -924,6 +924,7 @@ fields from the aqorders, biblio, and biblioitems tables in the Koha database. sub GetOrdersByBiblionumber { my $biblionumber = shift; + return unless $biblionumber; my $dbh = C4::Context->dbh; my $query =" SELECT biblio.*,biblioitems.*, diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index c015425..db43118 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -10,7 +10,7 @@ use POSIX qw(strftime); use C4::Bookseller qw( GetBookSellerFromId ); -use Test::More tests => 37; +use Test::More tests => 42; BEGIN { use_ok('C4::Acquisition'); @@ -32,6 +32,23 @@ my $grouped = 0; my $orders = GetPendingOrders( $supplierid, $grouped ); isa_ok( $orders, 'ARRAY' ); +# testing GetOrdersByBiblionumber +# result should be undef if no params +my @ordersbybiblionumber = GetOrdersByBiblionumber(); +is(@ordersbybiblionumber,0,'GetOrdersByBiblionumber : no argument, return undef'); +# TODO : create 2 orders using the same biblionumber, and check the result of GetOrdersByBiblionumber +# if a record is used in at least one order, result should be an array with at least one element +SKIP: { + skip 'No Orders, cannot test GetOrdersByBiblionumber', 3 unless( scalar @$orders ); + my $testorder = @$orders[0]; + my $testbiblio = $testorder->{'biblionumber'}; + my @listorders = GetOrdersByBiblionumber($testbiblio); + isa_ok( ref @listorders, 'ARRAY','GetOrdersByBiblionumber : result is an array' ); + ok( scalar (@listorders) >0,'GetOrdersByBiblionumber : result contains at least one element' ); + my @matched_biblios = grep {$_->{biblionumber} == $testbiblio} @listorders; + ok ( @matched_biblios == @listorders, "all orders match"); +} + my @lateorders = GetLateOrders(0); SKIP: { skip 'No Late Orders, cannot test AddClaim', 1 unless @lateorders; -- 1.7.9.5