Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Test::More tests => 7; |
6 |
use C4::Acquisition; |
7 |
use C4::Biblio; |
8 |
use C4::Bookseller; |
9 |
use C4::Budgets; |
10 |
use MARC::Record; |
11 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
12 |
|
13 |
my $dbh = C4::Context->dbh; |
14 |
$dbh->{AutoCommit} = 0; |
15 |
$dbh->{RaiseError} = 1; |
16 |
|
17 |
my $booksellerid = C4::Bookseller::AddBookseller( |
18 |
{ |
19 |
name => "my vendor", |
20 |
address1 => "bookseller's address", |
21 |
phone => "0123456", |
22 |
active => 1 |
23 |
} |
24 |
); |
25 |
|
26 |
my $basketno = C4::Acquisition::NewBasket( |
27 |
$booksellerid |
28 |
); |
29 |
|
30 |
my $budgetid = C4::Budgets::AddBudget( |
31 |
{ |
32 |
budget_code => "budget_code_test_getordersbybib", |
33 |
budget_name => "budget_name_test_getordersbybib", |
34 |
} |
35 |
); |
36 |
|
37 |
my $budget = C4::Budgets::GetBudget( $budgetid ); |
38 |
|
39 |
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); |
40 |
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); |
41 |
|
42 |
|
43 |
# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing |
44 |
my $ordernumber = eval { C4::Acquisition::NewOrder() }; |
45 |
my $return_error = $@; |
46 |
ok( |
47 |
( ! defined $ordernumber ) |
48 |
&& ( defined $return_error ), |
49 |
"NewOrder with no params returns undef and croaks" |
50 |
); |
51 |
|
52 |
my $mandatoryparams = { |
53 |
basketno => $basketno, |
54 |
quantity => 24, |
55 |
biblionumber => $biblionumber1, |
56 |
budget_id => $budgetid, |
57 |
}; |
58 |
my @mandatoryparams_keys = keys %$mandatoryparams; |
59 |
foreach my $mandatoryparams_key (@mandatoryparams_keys) { |
60 |
my %test_missing_mandatoryparams = %$mandatoryparams; |
61 |
delete $test_missing_mandatoryparams{$mandatoryparams_key}; |
62 |
eval { |
63 |
$ordernumber = |
64 |
C4::Acquisition::NewOrder( \%test_missing_mandatoryparams ); |
65 |
}; |
66 |
$return_error = $@; |
67 |
my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing"; |
68 |
ok( |
69 |
( !( defined $ordernumber ) ) |
70 |
&& ( index( $return_error, $expected_error ) >= 0 ), |
71 |
"NewOrder with no $mandatoryparams_key returns undef and croaks with expected error message" |
72 |
); |
73 |
} |
74 |
|
75 |
$ordernumber = C4::Acquisition::NewOrder( |
76 |
{ |
77 |
basketno => $basketno, |
78 |
quantity => 24, |
79 |
biblionumber => $biblionumber1, |
80 |
budget_id => $budget->{budget_id}, |
81 |
} |
82 |
); |
83 |
|
84 |
my $order = C4::Acquisition::GetOrder( $ordernumber ); |
85 |
is( $order->{quantityreceived}, 0, 'NewOrder set quantityreceivedto 0 if undef is given' ); |
86 |
is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'NewOrder set entrydate to today' ); |