|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use Modern::Perl; |
| 4 |
|
| 5 |
use Test::More; |
| 6 |
use C4::Acquisition; |
| 7 |
use C4::Biblio qw( AddBiblio DelBiblio ); |
| 8 |
use C4::Bookseller; |
| 9 |
use C4::Budgets; |
| 10 |
|
| 11 |
my $booksellerid = C4::Bookseller::AddBookseller( |
| 12 |
{ |
| 13 |
name => "my vendor", |
| 14 |
address1 => "bookseller's address", |
| 15 |
phone => "0123456", |
| 16 |
active => 1 |
| 17 |
} |
| 18 |
); |
| 19 |
|
| 20 |
my $basketno = C4::Acquisition::NewBasket( |
| 21 |
$booksellerid |
| 22 |
); |
| 23 |
|
| 24 |
my $budgetid = C4::Budgets::AddBudget( |
| 25 |
{ |
| 26 |
budget_code => "budget_code_test_close_reopen", |
| 27 |
budget_name => "budget_name_test_close_reopen", |
| 28 |
} |
| 29 |
); |
| 30 |
|
| 31 |
my $budget = C4::Budgets::GetBudget( $budgetid ); |
| 32 |
|
| 33 |
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); |
| 34 |
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); |
| 35 |
|
| 36 |
my ($ordernumber1, $ordernumber2); |
| 37 |
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder( |
| 38 |
{ |
| 39 |
basketno => $basketno, |
| 40 |
quantity => 24, |
| 41 |
biblionumber => $biblionumber1, |
| 42 |
budget_id => $budget->{budget_id}, |
| 43 |
} |
| 44 |
); |
| 45 |
|
| 46 |
( undef, $ordernumber2 ) = C4::Acquisition::NewOrder( |
| 47 |
{ |
| 48 |
basketno => $basketno, |
| 49 |
quantity => 42, |
| 50 |
biblionumber => $biblionumber2, |
| 51 |
budget_id => $budget->{budget_id}, |
| 52 |
} |
| 53 |
); |
| 54 |
|
| 55 |
my $nb_biblio = C4::Acquisition::GetBiblioCountByBasketno( $basketno ); |
| 56 |
is ( $nb_biblio, 2, "There are 2 biblio for this basket" ); |
| 57 |
my @orders = C4::Acquisition::GetOrders( $basketno ); |
| 58 |
is( scalar(@orders), 2, "2 orders are created" ); |
| 59 |
is ( scalar( map { $_->{orderstatus} == 0 ? 1 : () } @orders ), 2, "2 order are new before closing the basket" ); |
| 60 |
|
| 61 |
C4::Acquisition::CloseBasket( $basketno ); |
| 62 |
@orders = C4::Acquisition::GetOrders( $basketno ); |
| 63 |
is ( scalar( map { $_->{orderstatus} == 1 ? 1 : () } @orders ), 2, "2 orders are ordered, the basket is closed" ); |
| 64 |
|
| 65 |
C4::Acquisition::ReopenBasket( $basketno ); |
| 66 |
@orders = C4::Acquisition::GetOrders( $basketno ); |
| 67 |
is ( scalar( map { $_->{orderstatus} == 1 ? 1 : () } @orders ), 0, "No order are ordered, the basket is reopen" ); |
| 68 |
is ( scalar( map { $_->{orderstatus} == 0 ? 1 : () } @orders ), 2, "2 order are new, the basket is reopen" ); |
| 69 |
|
| 70 |
|
| 71 |
END { |
| 72 |
C4::Acquisition::DelOrder( 1, $ordernumber1 ); |
| 73 |
C4::Acquisition::DelOrder( 2, $ordernumber2 ); |
| 74 |
C4::Budgets::DelBudget( $budgetid ); |
| 75 |
C4::Acquisition::DelBasket( $basketno ); |
| 76 |
C4::Bookseller::DelBookseller( $booksellerid ); |
| 77 |
C4::Biblio::DelBiblio($biblionumber1); |
| 78 |
C4::Biblio::DelBiblio($biblionumber2); |
| 79 |
}; |
| 80 |
|
| 81 |
done_testing; |