kohabug 2139 Fixes C4::Aquisition::NewOrder so that it saves the branchcode
[koha.git] / t / lib / KohaTest / Acquisition / NewOrder.pm
1 package KohaTest::Acquisition::NewOrder;
2 use base qw( KohaTest::Acquisition );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8 use Time::localtime;
9
10 use C4::Acquisition;
11
12 =head3 new_order_no_budget
13
14 If we make a new order and don't pass in a budget date, it defaults to
15 today.
16
17 =cut
18
19 sub new_order_no_budget : Test( 4 ) {
20     my $self = shift;
21
22     my $authorizedby = 1; # XXX what should this be?
23     my $invoice = 123;    # XXX what should this be?
24     my $today = sprintf( '%04d-%02d-%02d',
25                          localtime->year() + 1900,
26                          localtime->mon() + 1,
27                          localtime->mday() );
28     my ( $basketno, $ordnum ) = NewOrder( undef, # $basketno,
29                                           1, # $bibnum,
30                                           undef, # $title,
31                                           undef, # $quantity,
32                                           undef, # $listprice,
33                                           $self->{'booksellerid'}, # $booksellerid,
34                                           $authorizedby, # $authorisedby,
35                                           undef, # $notes,
36                                           $self->{'bookfundid'},     # $bookfund,
37                                           undef, # $bibitemnum,
38                                           undef, # $rrp,
39                                           undef, # $ecost,
40                                           undef, # $gst,
41                                           undef, # $budget,
42                                           undef, # $cost,
43                                           undef, # $sub,
44                                           $invoice, # $invoice,
45                                           undef, # $sort1,
46                                           undef, # $sort2,
47                                           undef, # $purchaseorder,
48                                                                                   undef, # $branchcode
49                                      );
50     ok( $basketno, "my basket number is $basketno" );
51     ok( $ordnum,   "my order number is $ordnum" );
52
53     my $order = GetOrder( $ordnum );
54     is( $order->{'ordernumber'}, $ordnum, 'got the right order' )
55       or diag( Data::Dumper->Dump( [ $order ], [ 'order' ] ) );
56     
57     is( $order->{'budgetdate'}, $today, "the budget date is $today" );
58 }
59
60 =head3 new_order_set_budget
61
62 Let's set the budget date of this new order. It actually pretty much
63 only pays attention to the current month and year.
64
65 =cut
66
67 sub new_order_set_budget : Test( 4 ) {
68     my $self = shift;
69
70     my $authorizedby = 1; # XXX what should this be?
71     my $invoice = 123;    # XXX what should this be?
72     my $today = sprintf( '%04d-%02d-%02d',
73                          localtime->year() + 1900,
74                          localtime->mon() + 1,
75                          localtime->mday() );
76     my ( $basketno, $ordnum ) = NewOrder( undef, # $basketno,
77                                           1, # $bibnum,
78                                           undef, # $title,
79                                           undef, # $quantity,
80                                           undef, # $listprice,
81                                           $self->{'booksellerid'}, # $booksellerid,
82                                           $authorizedby, # $authorisedby,
83                                           undef, # $notes,
84                                           $self->{'bookfundid'},     # $bookfund,
85                                           undef, # $bibitemnum,
86                                           undef, # $rrp,
87                                           undef, # $ecost,
88                                           undef, # $gst,
89                                           'does not matter, just not undef', # $budget,
90                                           undef, # $cost,
91                                           undef, # $sub,
92                                           $invoice, # $invoice,
93                                           undef, # $sort1,
94                                           undef, # $sort2,
95                                           undef, # $purchaseorder,
96                                                                                   undef, # $branchcode
97                                      );
98     ok( $basketno, "my basket number is $basketno" );
99     ok( $ordnum,   "my order number is $ordnum" );
100
101     my $order = GetOrder( $ordnum );
102     is( $order->{'ordernumber'}, $ordnum, 'got the right order' )
103       or diag( Data::Dumper->Dump( [ $order ], [ 'order' ] ) );
104     
105     like( $order->{'budgetdate'}, qr(^2\d\d\d-07-01$), "the budget date ($order->{'budgetdate'}) is a July 1st." );
106 }
107
108 1;