5 use Test::More tests => 7;
12 use Koha::DateUtils qw( dt_from_string output_pref );
13 use Koha::Acquisition::Order;
15 my $schema = Koha::Database->new()->schema();
16 $schema->storage->txn_begin();
17 my $dbh = C4::Context->dbh;
18 $dbh->{RaiseError} = 1;
20 my $booksellerid = C4::Bookseller::AddBookseller(
23 address1 => "bookseller's address",
29 my $basketno = C4::Acquisition::NewBasket(
33 my $budgetid = C4::Budgets::AddBudget(
35 budget_code => "budget_code_test_getordersbybib",
36 budget_name => "budget_name_test_getordersbybib",
40 my $budget = C4::Budgets::GetBudget( $budgetid );
42 my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
43 my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
46 # returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing
47 my $order = eval { Koha::Acquisition::Order->new->insert };
48 my $return_error = $@;
51 && ( defined $return_error ),
52 "Inserting an order with no params returns undef and croaks"
55 my $mandatoryparams = {
56 basketno => $basketno,
58 biblionumber => $biblionumber1,
59 budget_id => $budgetid,
61 my @mandatoryparams_keys = keys %$mandatoryparams;
62 foreach my $mandatoryparams_key (@mandatoryparams_keys) {
63 my %test_missing_mandatoryparams = %$mandatoryparams;
64 delete $test_missing_mandatoryparams{$mandatoryparams_key};
66 Koha::Acquisition::Order->new( \%test_missing_mandatoryparams )->insert;
69 my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing";
71 ( !( defined $order ) )
72 && ( index( $return_error, $expected_error ) >= 0 ),
73 "Inserting an order with no $mandatoryparams_key returns undef and croaks with expected error message"
77 $order = Koha::Acquisition::Order->new(
79 basketno => $basketno,
81 biblionumber => $biblionumber1,
82 budget_id => $budget->{budget_id},
85 my $ordernumber = $order->{ordernumber};
86 $order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber });
87 is( $order->{quantityreceived}, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' );
88 is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->insert set entrydate to today' );
90 $schema->storage->txn_rollback();