#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# 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.
#
-# This Koha test module is a stub!
-# Add more tests here!!!
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
-use POSIX qw(strftime);
-use C4::Bookseller qw( GetBookSellerFromId );
+use POSIX qw(strftime);
-use Test::More tests => 77;
+use Test::More tests => 88;
BEGIN {
use_ok('C4::Acquisition');
use_ok('C4::Biblio');
use_ok('C4::Budgets');
use_ok('C4::Bookseller');
+ use_ok('Koha::Acquisition::Order');
+ use_ok('Koha::Acquisition::Bookseller');
}
# Sub used for testing C4::Acquisition subs returning order(s):
# params :
# $exp_fields : arrayref whose elements are the keys we expect to find
# $original_order_content : hashref whose 2 keys str and num contains hashrefs
-# containing content fields of the order created with NewOrder
+# containing content fields of the order created with Koha::Acquisition::Order
# $order_to_check : hashref whose keys/values are the content of an order
# returned by the C4::Acquisition sub we are testing
# returns :
}
);
-my $booksellerinfo = C4::Bookseller::GetBookSellerFromId($booksellerid);
+my $booksellerinfo = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
is( $booksellerinfo->{deliverytime},
5, 'set deliverytime when creating vendor (Bug 10556)' );
my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' );
my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' );
-#
-# Test NewOrder
-#
-
-my ( $mandatoryparams, $return_error, $basketnum );
-
-# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing
-eval { ( $basketnum, $ordernumbers[0] ) = C4::Acquisition::NewOrder() };
-$return_error = $@;
-ok(
- ( !( defined $basketnum || defined $ordernumbers[0] ) )
- && ( defined $return_error ),
- "NewOrder with no params returns undef and croaks"
-);
-
-$mandatoryparams = {
- basketno => $basketno,
- quantity => 24,
- biblionumber => $biblionumber1,
- budget_id => $budget->{budget_id},
-};
-my @mandatoryparams_keys = keys %$mandatoryparams;
-foreach my $mandatoryparams_key (@mandatoryparams_keys) {
- my %test_missing_mandatoryparams = %$mandatoryparams;
- delete $test_missing_mandatoryparams{$mandatoryparams_key};
- eval {
- ( $basketnum, $ordernumbers[0] ) =
- C4::Acquisition::NewOrder( \%test_missing_mandatoryparams );
- };
- $return_error = $@;
- my $expected_error = "Mandatory parameter $mandatoryparams_key missing";
- ok(
- ( !( defined $basketnum || defined $ordernumbers[0] ) )
- && ( index( $return_error, $expected_error ) >= 0 ),
-"NewOrder with no $mandatoryparams_key returns undef and croaks with expected error message"
- );
-}
-
-# FIXME to do : test the other features of NewOrder
-
# Prepare 5 orders, and make distinction beween fields to be tested with eq and with ==
# Ex : a price of 50.1 will be stored internally as 5.100000
budget_id => $budget->{budget_id},
uncertainprice => 0,
order_internalnote => "internal note",
- order_vendornote => "vendor note"
+ order_vendornote => "vendor note",
+ ordernumber => '',
},
num => {
quantity => 24,
values %{ $order_content[$_]->{num} };
@ocontent{ keys %{ $order_content[$_]->{str} } } =
values %{ $order_content[$_]->{str} };
- ( undef, $ordernumbers[$_] ) = C4::Acquisition::NewOrder( \%ocontent );
+ $ordernumbers[$_] = Koha::Acquisition::Order->new( \%ocontent )->insert->{ordernumber};
$order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_];
}
freight
unitprice
quantityreceived
- cancelledby
datecancellationprinted
- supplierreference
purchaseordernumber
basketno
timestamp
quantity_to_receive
subtotal
latesince
+ cancellationreason
);
(
$test_missing_fields, $test_extra_fields,
ecost
uncertainprice
marc
- cancelledby
url
isbn
copyrightdate
biblioitemnumber
datereceived
orderstatus
- supplierreference
agerestriction
budget_branchcode
gstrate
frameworkcode
volumedesc
datecancellationprinted
+ cancellationreason
);
@expectedfields =
( @base_expectedfields,
creationdate
datereceived
orderstatus
- supplierreference
- cancelledby
isbn
copyrightdate
gstrate
budget_id
authorisedby
booksellerid
+ cancellationreason
);
# note that authorisedby was added to the return of SearchOrder by the
});
is( scalar (@$search_orders), 0, "SearchOrders with pending and ordered params gets only pending ordered orders (bug 11170)" );
+$search_orders = SearchOrders({
+ ordernumber => $ordernumbers[4]
+});
+is( scalar (@$search_orders), 1, "SearchOrders takes into account the ordernumber filter" );
+
+$search_orders = SearchOrders({
+ biblionumber => $biblionumber4
+});
+is( scalar (@$search_orders), 1, "SearchOrders takes into account the biblionumber filter" );
+
+$search_orders = SearchOrders({
+ biblionumber => $biblionumber4,
+ pending => 1
+});
+is( scalar (@$search_orders), 0, "SearchOrders takes into account the biblionumber and pending filters" );
#
# Test GetBudgetByOrderNumber
});
is( scalar (@$search_orders), 3, "SearchOrders with pending and ordered params gets only pending ordered orders. After closing the basket, orders are marked as 'ordered' (bug 11170)" );
-$search_orders = SearchOrders({
- ordernumber => $ordernumbers[4]
-});
-is( scalar (@$search_orders), 1, "SearchOrders takes into account the ordernumber filter" );
-
#
# Test AddClaim
#
is( $neworder->{ordernumber}, $new_ordernumber, 'Split: test ordernumber' );
is( $neworder->{parent_ordernumber}, $ordernumbers[1], 'Split: test parent_ordernumber' );
-my ( $orders ) = GetHistory( ordernumber => $ordernumbers[1] );
+my $orders = GetHistory( ordernumber => $ordernumbers[1] );
is( scalar( @$orders ), 1, 'GetHistory with a given ordernumber returns 1 order' );
-( $orders ) = GetHistory( ordernumber => $ordernumbers[1], search_children_too => 1 );
+$orders = GetHistory( ordernumber => $ordernumbers[1], search_children_too => 1 );
is( scalar( @$orders ), 2, 'GetHistory with a given ordernumber and search_children_too set returns 2 orders' );
my $budgetid2 = C4::Budgets::AddBudget(
$nonexistent_order = GetOrder( 424242424242 );
is( $nonexistent_order, undef, 'GetOrder returns undef if a nonexistent ordernumber is given' );
+# Tests for DelOrder
+my $order1 = GetOrder($ordernumbers[0]);
+my $error = DelOrder($order1->{biblionumber}, $order1->{ordernumber});
+ok((not defined $error), "DelOrder does not fail");
+$order1 = GetOrder($order1->{ordernumber});
+ok((defined $order1->{datecancellationprinted}), "order is cancelled");
+ok((not defined $order1->{cancellationreason}), "order has no cancellation reason");
+ok((defined GetBiblio($order1->{biblionumber})), "biblio still exists");
+
+$order2 = GetOrder($ordernumbers[1]);
+$error = DelOrder($order2->{biblionumber}, $order2->{ordernumber}, 1);
+ok((not defined $error), "DelOrder does not fail");
+$order2 = GetOrder($order2->{ordernumber});
+ok((defined $order2->{datecancellationprinted}), "order is cancelled");
+ok((not defined $order2->{cancellationreason}), "order has no cancellation reason");
+ok((not defined GetBiblio($order2->{biblionumber})), "biblio does not exist anymore");
+
+my $order4 = GetOrder($ordernumbers[3]);
+$error = DelOrder($order4->{biblionumber}, $order4->{ordernumber}, 1, "foobar");
+ok((not defined $error), "DelOrder does not fail");
+$order4 = GetOrder($order4->{ordernumber});
+ok((defined $order4->{datecancellationprinted}), "order is cancelled");
+ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \"foobar\"");
+ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore");
+# End of tests for DelOrder
+
$dbh->rollback;