Bug 5327 shifting database dependent modules and scripts to t/db_dependent
[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 sub one_order : Test( 50 ) {
42     my $self = shift;
43     
44     my ( $basketno, $ordernumber ) = $self->create_new_basket();
45     ok( $basketno, "basketno is $basketno" );
46     ok( $ordernumber, "ordernumber is $ordernumber" );
47
48     # No arguments fetches no history.
49     {
50         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory();
51         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
52         
53         is( scalar @$order_loop, 0, 'order_loop is empty' );
54         is( $total_qty,          0, 'total_qty' );
55         is( $total_price,        0, 'total_price' );
56         is( $total_qtyreceived,  0, 'total_qtyreceived' );
57     }
58
59     my $bibliodata = GetBiblioData( $self->{'biblios'}[0] );
60     ok( $bibliodata->{'title'}, 'the biblio has a title' )
61       or diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
62     
63     # searching by title should find it.
64     {
65         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( $bibliodata->{'title'} );
66         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
67     
68         is( scalar @$order_loop, 1, 'order_loop searched by title' );
69         is( $total_qty,          1, 'total_qty searched by title' );
70         is( $total_price,        1, 'total_price searched by title' );
71         is( $total_qtyreceived,  0, 'total_qtyreceived searched by title' );
72
73         # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
74     }
75
76     # searching by author
77     {
78         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, $bibliodata->{'author'} );
79         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
80     
81         is( scalar @$order_loop, 1, 'order_loop searched by author' );
82         is( $total_qty,          1, 'total_qty searched by author' );
83         is( $total_price,        1, 'total_price searched by author' );
84         is( $total_qtyreceived,  0, 'total_qtyreceived searched by author' );
85     }
86
87     # searching by name
88     {
89         # diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
90
91         my $bookseller = GetBookSellerFromId( $self->{'booksellerid'} );
92         ok( $bookseller->{'name'}, 'bookseller name' )
93           or diag( Data::Dumper->Dump( [ $bookseller ], [ 'bookseller' ] ) );
94         
95         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, undef, $bookseller->{'name'} );
96         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
97     
98         is( scalar @$order_loop, 1, 'order_loop searched by name' );
99         is( $total_qty,          1, 'total_qty searched by name' );
100         is( $total_price,        1, 'total_price searched by name' );
101         is( $total_qtyreceived,  0, 'total_qtyreceived searched by name' );
102     }
103
104     # searching by from_date
105     {
106         my $tomorrow = $self->tomorrow();
107         # diag( "tomorrow is $tomorrow" );
108
109         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, undef, undef, undef, $tomorrow );
110         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
111     
112         is( scalar @$order_loop, 1, 'order_loop searched by to_date' );
113         is( $total_qty,          1, 'total_qty searched by to_date' );
114         is( $total_price,        1, 'total_price searched by to_date' );
115         is( $total_qtyreceived,  0, 'total_qtyreceived searched by to_date' );
116     }
117
118     # searching by from_date
119     {
120         my $yesterday = $self->yesterday();
121         # diag( "yesterday was $yesterday" );
122     
123         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, undef, undef, $yesterday );
124         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
125     
126         is( scalar @$order_loop, 1, 'order_loop searched by from_date' );
127         is( $total_qty,          1, 'total_qty searched by from_date' );
128         is( $total_price,        1, 'total_price searched by from_date' );
129         is( $total_qtyreceived,  0, 'total_qtyreceived searched by from_date' );
130     }
131
132     # set up some things necessary to make GetHistory use the IndependantBranches
133     $self->enable_independant_branches();    
134
135     # just search by title here, we need to search by something.
136     {
137         my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( $bibliodata->{'title'} );
138         # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
139     
140         is( scalar @$order_loop, 1, 'order_loop searched by title' );
141         is( $total_qty,          1, 'total_qty searched by title' );
142         is( $total_price,        1, 'total_price searched by title' );
143         is( $total_qtyreceived,  0, 'total_qtyreceived searched by title' );
144
145         # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
146     }
147     
148     # reset that.
149     $self->disable_independant_branches();    
150
151     
152
153     
154 }
155
156
157 1;