From fd89c94544eb4466d800b4f524c12c2306d908cf Mon Sep 17 00:00:00 2001 From: Yohann Dufour Date: Fri, 18 Jul 2014 17:14:12 +0200 Subject: [PATCH] Bug 12607: refactoring GetBasketsInfosByBookseller.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/GetBasketsInfosByBookseller.t has to be a success without error or warning : t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t .. ok All tests successful. Files=1, Tests=18, 2 wallclock secs ( 0.03 usr 0.01 sys + 1.71 cusr 0.09 csys = 1.84 CPU) Result: PASS --- .../Acquisition/GetBasketsInfosByBookseller.t | 102 ++++++++++----------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t index 3b4c96b..379e459 100644 --- a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t +++ b/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t @@ -1,61 +1,64 @@ #!/usr/bin/perl +# 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 . + use Modern::Perl; use Test::More tests => 18; -use Data::Dumper; - -use C4::Acquisition qw( NewOrder NewBasket GetBasketsInfosByBookseller ); -use C4::Biblio qw( AddBiblio ); -use C4::Bookseller qw( AddBookseller ); -use C4::Budgets qw( AddBudget ); -use C4::Context; -my $dbh = C4::Context->dbh; -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; +use t::lib::TestBuilder; -my $supplierid = C4::Bookseller::AddBookseller( - { - name => 'my vendor', - address1 => 'bookseller\'s address', - phone => '0123456', - active => 1, - deliverytime => 5, - } -); +BEGIN { + use_ok('C4::Acquisition'); +} -my $basketno; -ok($basketno = NewBasket($supplierid, 1), 'NewBasket( $supplierid , 1 ) returns $basketno'); -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, ''); -my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, ''); +my $order1 = $builder->build({ + source => 'Aqorder', + value => { + quantity => 2, + quantityreceived => 0, + datecancellationprinted => undef, + basketno => { + closedate => undef, + }, + }, + only_fk => 1, +}); +my (undef, $ordernumber1) = C4::Acquisition::NewOrder($order1); -( undef, $ordernumber1 ) = C4::Acquisition::NewOrder( - { - basketno => $basketno, - quantity => 2, - biblionumber => $biblionumber1, - budget_id => $budget->{budget_id}, - } -); +my $order2 = $builder->build({ + source => 'Aqorder', + value => { + basketno => $order1->{basketno}, + quantity => 4, + quantityreceived => 0, + datecancellationprinted => undef, + }, + only_fk => 1, +}); +my (undef, $ordernumber2) = C4::Acquisition::NewOrder($order2); -( undef, $ordernumber2 ) = C4::Acquisition::NewOrder( - { - basketno => $basketno, - quantity => 4, - biblionumber => $biblionumber2, - budget_id => $budget->{budget_id}, - } -); +my $basketno = $order1->{basketno}; +my $biblionumber1 = $order1->{biblionumber}; +my $biblionumber2 = $order2->{biblionumber}; +my $supplierid = $order1->{_fk}->{basketno}->{booksellerid}; my $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid ); is( scalar(@$baskets), 1, 'Start: 1 basket' ); @@ -88,6 +91,3 @@ $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid ); is( scalar(@$baskets), 0, 'Basket is closed, 0 basket opened' ); $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid, 1 ); is( scalar(@$baskets), 1, 'Basket is closed, test allbasket parameter'); - - -$dbh->rollback -- 1.9.1