Bug 10080 - Change system pref IndependantBranches to IndependentBranches
[koha.git] / t / db_dependent / lib / KohaTest / Acquisition / GetHistory.pm
1 package KohaTest::Acquisition::GetHistory;
2 use base qw( KohaTest::Acquisition );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9 use C4::Acquisition;
10 use C4::Context;
11 use C4::Members;
12 use C4::Biblio;
13 use C4::Bookseller;
14
15 =head3 no_history
16
17
18
19 =cut
20
21 sub no_history : Test( 4 ) {
22     my $self = shift;
23
24     # my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( $title, $author, $name, $from_placed_on, $to_placed_on )
25
26     my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory();
27     # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
28
29     is( scalar @$order_loop, 0, 'order_loop is empty' );
30     is( $total_qty,          0, 'total_qty' );
31     is( $total_price,        0, 'total_price' );
32     is( $total_qtyreceived,  0, 'total_qtyreceived' );
33
34     
35 }
36
37 =head3 one_order
38
39 =cut
40
41 my $INVOICE = "1234-56 AB";
42 sub one_order : Test( 55 ) {
43     my $self = shift;
44     
45     my ( $basketno, $ordernumber ) = $self->create_new_basket(invoice => $INVOICE);
46     ok( $basketno, "basketno is $basketno" );
47     ok( $ordernumber, "ordernumber is $ordernumber" );
48
49     # No arguments fetches no history.
50     {
51         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = eval { GetHistory() };
52         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
53         
54         is( $order_loop, undef, 'order_loop is empty' );
55     }
56
57     my $bibliodata = GetBiblioData( $self->{'biblios'}[0] );
58     ok( $bibliodata->{'title'}, 'the biblio has a title' )
59       or diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
60     
61     # searching by title should find it.
62     {
63         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( title => $bibliodata->{'title'} );
64         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
65     
66         is( scalar @$order_loop, 1, 'order_loop searched by title' );
67         is( $total_qty,          1, 'total_qty searched by title' );
68         is( $total_price,        1, 'total_price searched by title' );
69         is( $total_qtyreceived,  0, 'total_qtyreceived searched by title' );
70
71         # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
72     }
73
74     # searching by isbn
75     {
76         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( isbn => $bibliodata->{'isbn'} );
77         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
78
79         is( scalar @$order_loop, 1, 'order_loop searched by isbn' );
80         is( $total_qty,          1, 'total_qty searched by isbn' );
81         is( $total_price,        1, 'total_price searched by isbn' );
82         is( $total_qtyreceived,  0, 'total_qtyreceived searched by isbn' );
83
84         # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
85     }
86
87     # searching by ean
88     {
89         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( ean => $bibliodata->{'ean'} );
90         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
91
92         is( scalar @$order_loop, 1, 'order_loop searched by ean' );
93         is( $total_qty,          1, 'total_qty searched by ean' );
94         is( $total_price,        1, 'total_price searched by ean' );
95         is( $total_qtyreceived,  0, 'total_qtyreceived searched by ean' );
96
97         # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
98     }
99
100
101     # searching by basket number
102     {
103         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( basket => $basketno );
104         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
105     
106         is( scalar @$order_loop, 1, 'order_loop searched by basket no' );
107         is( $total_qty,          1, 'total_qty searched by basket no' );
108         is( $total_price,        1, 'total_price searched by basket no' );
109         is( $total_qtyreceived,  0, 'total_qtyreceived searched by basket no' );
110
111         # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
112     }
113
114     # searching by invoice number
115     {
116         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( booksellerinvoicenumber  => $INVOICE );
117         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
118     
119         is( scalar @$order_loop, 1, 'order_loop searched by invoice no' );
120         is( $total_qty,          1, 'total_qty searched by invoice no' );
121         is( $total_price,        1, 'total_price searched by invoice no' );
122         is( $total_qtyreceived,  0, 'total_qtyreceived searched by invoice no' );
123
124         # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
125     }
126
127     # searching by author
128     {
129         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( author => $bibliodata->{'author'} );
130         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
131     
132         is( scalar @$order_loop, 1, 'order_loop searched by author' );
133         is( $total_qty,          1, 'total_qty searched by author' );
134         is( $total_price,        1, 'total_price searched by author' );
135         is( $total_qtyreceived,  0, 'total_qtyreceived searched by author' );
136     }
137
138     # searching by name
139     {
140         # diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
141
142         my $bookseller = GetBookSellerFromId( $self->{'booksellerid'} );
143         ok( $bookseller->{'name'}, 'bookseller name' )
144           or diag( Data::Dumper->Dump( [ $bookseller ], [ 'bookseller' ] ) );
145         
146         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( name => $bookseller->{'name'} );
147         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
148     
149         is( scalar @$order_loop, 1, 'order_loop searched by name' );
150         is( $total_qty,          1, 'total_qty searched by name' );
151         is( $total_price,        1, 'total_price searched by name' );
152         is( $total_qtyreceived,  0, 'total_qtyreceived searched by name' );
153     }
154
155     # searching by from_date
156     {
157         my $tomorrow = $self->tomorrow();
158         # diag( "tomorrow is $tomorrow" );
159
160         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( to_placed_on =>  $tomorrow );
161         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
162     
163         is( scalar @$order_loop, 1, 'order_loop searched by to_date' );
164         is( $total_qty,          1, 'total_qty searched by to_date' );
165         is( $total_price,        1, 'total_price searched by to_date' );
166         is( $total_qtyreceived,  0, 'total_qtyreceived searched by to_date' );
167     }
168
169     # searching by from_date
170     {
171         my $yesterday = $self->yesterday();
172         # diag( "yesterday was $yesterday" );
173     
174         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( from_placed_on =>  $yesterday );
175         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
176     
177         is( scalar @$order_loop, 1, 'order_loop searched by from_date' );
178         is( $total_qty,          1, 'total_qty searched by from_date' );
179         is( $total_price,        1, 'total_price searched by from_date' );
180         is( $total_qtyreceived,  0, 'total_qtyreceived searched by from_date' );
181     }
182
183     # set up some things necessary to make GetHistory use the IndependentBranches
184     $self->enable_independant_branches();    
185
186     # just search by title here, we need to search by something.
187     {
188         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( title => $bibliodata->{'title'} );
189         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
190     
191         is( scalar @$order_loop, 1, 'order_loop searched by title' );
192         is( $total_qty,          1, 'total_qty searched by title' );
193         is( $total_price,        1, 'total_price searched by title' );
194         is( $total_qtyreceived,  0, 'total_qtyreceived searched by title' );
195
196         # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
197     }
198     
199     # reset that.
200     $self->disable_independant_branches();    
201
202     
203
204     
205 }
206
207
208 1;