From c5aafe524c7be45d576d8e278b48e947662f2201 Mon Sep 17 00:00:00 2001 From: Yohann Dufour Date: Fri, 18 Jul 2014 17:04:53 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 12606: refactoring GetOrdersByBiblionumber.t with TestBuilder The tests have been refactored with the module TestBuilder. Test plan: 1/ Apply the patch 12603 and the last patch of bug 11518. 2/ The command : prove t/db_dependent/Acquisition/GetOrdersByBiblionumber.t has to be a success without error or warning : t/db_dependent/Acquisition/GetOrdersByBiblionumber.t .. ok All tests successful. Files=1, Tests=4, 2 wallclock secs ( 0.03 usr 0.01 sys + 1.90 cusr 0.09 csys = 2.03 CPU) Result: PASS Signed-off-by: Kyle M Hall --- .../Acquisition/GetOrdersByBiblionumber.t | 114 +++++++++----------- 1 files changed, 51 insertions(+), 63 deletions(-) diff --git a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t b/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t index 8bd0735..3723a2a 100644 --- a/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t +++ b/t/db_dependent/Acquisition/GetOrdersByBiblionumber.t @@ -1,71 +1,64 @@ #!/usr/bin/perl -use Modern::Perl; - -use Test::More; -use C4::Acquisition; -use C4::Biblio; -use C4::Bookseller; -use C4::Budgets; -use MARC::Record; - -#Start transaction -my $dbh = C4::Context->dbh; -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; +# This file is part of Koha. +# +# Copyright 2014 - Biblibre SARL +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . -my $booksellerid = C4::Bookseller::AddBookseller( - { - name => "my vendor", - address1 => "bookseller's address", - phone => "0123456", - active => 1 - } -); +use Modern::Perl; +use Test::More tests => 4; +use t::lib::TestBuilder; -my $basketno = C4::Acquisition::NewBasket( - $booksellerid -); +BEGIN { + use_ok('C4::Acquisition'); +} -my $budgetid = C4::Budgets::AddBudget( - { - budget_code => "budget_code_test_getordersbybib", - budget_name => "budget_name_test_getordersbybib", - } -); -my $budget = C4::Budgets::GetBudget( $budgetid ); +my $builder = t::lib::TestBuilder->new(); +$builder->clear( { source => 'Aqorder' } ); -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}, - } -); +my $order1 = $builder->build({ + source => 'Aqorder', + value => { + datecancellationprinted => undef, + }, + only_fk => 1, +}); +C4::Acquisition::NewOrder($order1); -( undef, $ordernumber2 ) = C4::Acquisition::NewOrder( - { - basketno => $basketno, - quantity => 42, - biblionumber => $biblionumber2, - budget_id => $budget->{budget_id}, - } -); +my $order2 = $builder->build({ + source => 'Aqorder', + value => { + datecancellationprinted => undef, + }, + only_fk => 1, +}); +C4::Acquisition::NewOrder($order2); -( undef, $ordernumber3 ) = C4::Acquisition::NewOrder( - { - basketno => $basketno, - quantity => 4, - biblionumber => $biblionumber2, - budget_id => $budget->{budget_id}, - } -); +my $order3 = $builder->build({ + source => 'Aqorder', + value => { + biblionumber => $order2->{biblionumber}, + datecancellationprinted => undef, + }, + only_fk => 1, +}); +C4::Acquisition::NewOrder($order3); +my $biblionumber1 = $order1->{biblionumber}; +my $biblionumber2 = $order2->{biblionumber}; my @orders = GetOrdersByBiblionumber(); is(scalar(@orders), 0, 'GetOrdersByBiblionumber : no argument, return undef'); @@ -74,8 +67,3 @@ is(scalar(@orders), 1, '1 order on biblionumber 1'); @orders = GetOrdersByBiblionumber( $biblionumber2 ); is(scalar(@orders), 2, '2 orders on biblionumber 2'); - -#End transaction -$dbh->rollback; - -done_testing; -- 1.7.2.5