@@ -, +, @@ --- t/db_dependent/Acquisition.t | 19 +---- .../Acquisition/GetOrdersByBiblionumber.t | 84 ++++++++++++++++++++ 2 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 t/db_dependent/Acquisition/GetOrdersByBiblionumber.t --- a/t/db_dependent/Acquisition.t +++ a/t/db_dependent/Acquisition.t @@ -10,7 +10,7 @@ use POSIX qw(strftime); use C4::Bookseller qw( GetBookSellerFromId ); -use Test::More tests => 41; +use Test::More tests => 37; BEGIN { use_ok('C4::Acquisition'); @@ -32,23 +32,6 @@ 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); - ok( @listorders ,'GetOrdersByBiblionumber : result is defined' ); - 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; --- a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t +++ a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t @@ -0,0 +1,84 @@ +#!/usr/bin/env perl + +use Modern::Perl; + +use Test::More; +use C4::Acquisition; +use C4::Biblio; +use C4::Bookseller; +use C4::Budgets; +use MARC::Record; + +my $booksellerid = C4::Bookseller::AddBookseller( + { + name => "my vendor", + address1 => "bookseller's address", + phone => "0123456", + active => 1 + } +); + +my $basketno = C4::Acquisition::NewBasket( + $booksellerid +); + +my $budgetid = C4::Budgets::AddBudget( + { + budget_code => "budget_code_test_getordersbybib", + budget_name => "budget_name_test_getordersbybib", + } +); + +my $budget = C4::Budgets::GetBudget( $budgetid ); + +my ($ordernumber1, $ordernumber2, $ordernumber3); +my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); +my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); +( undef, $ordernumber1 ) = C4::Acquisition::NewOrder( + { + basketno => $basketno, + quantity => 24, + biblionumber => $biblionumber1, + budget_id => $budget->{budget_id}, + } +); + +( undef, $ordernumber2 ) = C4::Acquisition::NewOrder( + { + basketno => $basketno, + quantity => 42, + biblionumber => $biblionumber2, + budget_id => $budget->{budget_id}, + } +); + +( undef, $ordernumber3 ) = C4::Acquisition::NewOrder( + { + basketno => $basketno, + quantity => 4, + biblionumber => $biblionumber2, + budget_id => $budget->{budget_id}, + } +); + +my @orders = GetOrdersByBiblionumber(); +is(scalar(@orders), 0, 'GetOrdersByBiblionumber : no argument, return undef'); + +@orders = GetOrdersByBiblionumber( $biblionumber1 ); +is(scalar(@orders), 1, '1 order on biblionumber 1'); + +@orders = GetOrdersByBiblionumber( $biblionumber2 ); +is(scalar(@orders), 2, '2 orders on biblionumber 2'); + +END { + C4::Acquisition::DelOrder( 1, $ordernumber1 ); + C4::Acquisition::DelOrder( 2, $ordernumber2 ); + C4::Acquisition::DelOrder( 3, $ordernumber3 ); + C4::Budgets::DelBudget( $budgetid ); + C4::Acquisition::DelBasket( $basketno ); + C4::Bookseller::DelBookseller( $booksellerid ); + C4::Biblio::DelBiblio($biblionumber1); + C4::Biblio::DelBiblio($biblionumber2); +}; + +done_testing; --