From fefbf8ddc2b99ceff5ae7adb9b9cb2c8a7068c65 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 23 Apr 2013 16:50:22 +0200 Subject: [PATCH] Bug 5336: Add unit tests for 3 acq routines Unit tests In C4::Acquisition for: - CloseBasket - ReopenBasket - GetBiblioCountByBasketno Signed-off-by: Cedric Vita --- t/db_dependent/Acquisition/close_reopen_basket.t | 81 ++++++++++++++++++++++ t/db_dependent/lib/KohaTest/Acquisition.pm | 2 + 2 files changed, 83 insertions(+), 0 deletions(-) create mode 100644 t/db_dependent/Acquisition/close_reopen_basket.t diff --git a/t/db_dependent/Acquisition/close_reopen_basket.t b/t/db_dependent/Acquisition/close_reopen_basket.t new file mode 100644 index 0000000..7ef6341 --- /dev/null +++ b/t/db_dependent/Acquisition/close_reopen_basket.t @@ -0,0 +1,81 @@ +#!/usr/bin/env perl + +use Modern::Perl; + +use Test::More; +use C4::Acquisition; +use C4::Biblio qw( AddBiblio DelBiblio ); +use C4::Bookseller; +use C4::Budgets; + +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_close_reopen", + budget_name => "budget_name_test_close_reopen", + } +); + +my $budget = C4::Budgets::GetBudget( $budgetid ); + +my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); +my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); + +my ($ordernumber1, $ordernumber2); +( 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}, + } +); + +my $nb_biblio = C4::Acquisition::GetBiblioCountByBasketno( $basketno ); +is ( $nb_biblio, 2, "There are 2 biblio for this basket" ); +my @orders = C4::Acquisition::GetOrders( $basketno ); +is( scalar(@orders), 2, "2 orders are created" ); +is ( scalar( map { $_->{orderstatus} == 0 ? 1 : () } @orders ), 2, "2 order are new before closing the basket" ); + +C4::Acquisition::CloseBasket( $basketno ); +@orders = C4::Acquisition::GetOrders( $basketno ); +is ( scalar( map { $_->{orderstatus} == 1 ? 1 : () } @orders ), 2, "2 orders are ordered, the basket is closed" ); + +C4::Acquisition::ReopenBasket( $basketno ); +@orders = C4::Acquisition::GetOrders( $basketno ); +is ( scalar( map { $_->{orderstatus} == 1 ? 1 : () } @orders ), 0, "No order are ordered, the basket is reopen" ); +is ( scalar( map { $_->{orderstatus} == 0 ? 1 : () } @orders ), 2, "2 order are new, the basket is reopen" ); + + +END { + C4::Acquisition::DelOrder( 1, $ordernumber1 ); + C4::Acquisition::DelOrder( 2, $ordernumber2 ); + C4::Budgets::DelBudget( $budgetid ); + C4::Acquisition::DelBasket( $basketno ); + C4::Bookseller::DelBookseller( $booksellerid ); + C4::Biblio::DelBiblio($biblionumber1); + C4::Biblio::DelBiblio($biblionumber2); +}; + +done_testing; diff --git a/t/db_dependent/lib/KohaTest/Acquisition.pm b/t/db_dependent/lib/KohaTest/Acquisition.pm index c859038..409fdf3 100644 --- a/t/db_dependent/lib/KohaTest/Acquisition.pm +++ b/t/db_dependent/lib/KohaTest/Acquisition.pm @@ -20,6 +20,7 @@ sub methods : Test( 1 ) { my @methods = qw( GetBasket NewBasket CloseBasket + ReopenBasket GetPendingOrders GetOrders GetOrderNumber @@ -34,6 +35,7 @@ sub methods : Test( 1 ) { GetLateOrders GetHistory GetRecentAcqui + GetBiblioCountByBasketno ); can_ok( $self->testing_class, @methods ); -- 1.7.2.5