From 348b5f654b6db1193bbed170a6609775f953ed13 Mon Sep 17 00:00:00 2001 From: Mathieu Saby Date: Thu, 21 Mar 2013 18:48:32 +0100 Subject: [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 | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 8390670..d531b89 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -918,6 +918,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 4a5b31e..54a7296 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -7,10 +7,9 @@ use strict; use warnings; use Data::Dumper; use POSIX qw(strftime); - use C4::Bookseller qw( GetBookSellerFromId ); -use Test::More tests => 38; +use Test::More tests => 42; BEGIN { use_ok('C4::Acquisition'); @@ -26,12 +25,29 @@ SKIP: { ok($basket = GetBasket($basketno), "GetBasket($basketno) returns $basket"); } - my $supplierid = 1; 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.10.4