3d61550e22
The C4::Acquisition module should be exploded in order to add readability and maintainability to this part of the code. This patch is a POC, it introduces a new Koha::Acquisition::Order module and put in it the code from NewOrder and NewOrderItem. Test plan: 1/ Create an order, modify it, receive it, cancel the receipt. 2/ Launch the prove command on all unit tests modified by this patch and verify that all pass. Signed-off-by: Paola Rossi <paola.rossi@cineca.it> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
86 lines
2.6 KiB
Perl
86 lines
2.6 KiB
Perl
#!/usr/bin/perl
|
|
|
|
use Modern::Perl;
|
|
|
|
use Test::More tests => 7;
|
|
use C4::Acquisition;
|
|
use C4::Biblio;
|
|
use C4::Bookseller;
|
|
use C4::Budgets;
|
|
use MARC::Record;
|
|
use Koha::DateUtils qw( dt_from_string output_pref );
|
|
use Koha::Acquisition::Order;
|
|
|
|
my $dbh = C4::Context->dbh;
|
|
$dbh->{AutoCommit} = 0;
|
|
$dbh->{RaiseError} = 1;
|
|
|
|
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_getordersbybib",
|
|
budget_name => "budget_name_test_getordersbybib",
|
|
}
|
|
);
|
|
|
|
my $budget = C4::Budgets::GetBudget( $budgetid );
|
|
|
|
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
|
|
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
|
|
|
|
|
|
# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing
|
|
my $order = eval { Koha::Acquisition::Order->new->insert };
|
|
my $return_error = $@;
|
|
ok(
|
|
( ! defined $order )
|
|
&& ( defined $return_error ),
|
|
"Inserting an order with no params returns undef and croaks"
|
|
);
|
|
|
|
my $mandatoryparams = {
|
|
basketno => $basketno,
|
|
quantity => 24,
|
|
biblionumber => $biblionumber1,
|
|
budget_id => $budgetid,
|
|
};
|
|
my @mandatoryparams_keys = keys %$mandatoryparams;
|
|
foreach my $mandatoryparams_key (@mandatoryparams_keys) {
|
|
my %test_missing_mandatoryparams = %$mandatoryparams;
|
|
delete $test_missing_mandatoryparams{$mandatoryparams_key};
|
|
$order = eval {
|
|
Koha::Acquisition::Order->new( \%test_missing_mandatoryparams )->insert;
|
|
};
|
|
$return_error = $@;
|
|
my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing";
|
|
ok(
|
|
( !( defined $order ) )
|
|
&& ( index( $return_error, $expected_error ) >= 0 ),
|
|
"Inserting an order with no $mandatoryparams_key returns undef and croaks with expected error message"
|
|
);
|
|
}
|
|
|
|
$order = Koha::Acquisition::Order->new(
|
|
{
|
|
basketno => $basketno,
|
|
quantity => 24,
|
|
biblionumber => $biblionumber1,
|
|
budget_id => $budget->{budget_id},
|
|
}
|
|
)->insert;
|
|
my $ordernumber = $order->{ordernumber};
|
|
$order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber });
|
|
is( $order->{quantityreceived}, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' );
|
|
is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->insert set entrydate to today' );
|