1 package KohaTest::Acquisition::GetHistory;
2 use base qw( KohaTest::Acquisition );
21 sub no_history : Test( 4 ) {
24 # my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( $title, $author, $name, $from_placed_on, $to_placed_on )
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 ) ] ) );
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' );
41 my $INVOICE = "1234-56 AB";
42 sub one_order : Test( 55 ) {
45 my ( $basketno, $ordernumber ) = $self->create_new_basket(invoice => $INVOICE);
46 ok( $basketno, "basketno is $basketno" );
47 ok( $ordernumber, "ordernumber is $ordernumber" );
49 # No arguments fetches no history.
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 ) ] ) );
54 is( $order_loop, undef, 'order_loop is empty' );
57 my $bibliodata = GetBiblioData( $self->{'biblios'}[0] );
58 ok( $bibliodata->{'title'}, 'the biblio has a title' )
59 or diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
61 # searching by title should find it.
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 ) ] ) );
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' );
71 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
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 ) ] ) );
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' );
84 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
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 ) ] ) );
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' );
97 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
101 # searching by basket number
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 ) ] ) );
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' );
111 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
114 # searching by invoice number
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 ) ] ) );
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' );
124 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
127 # searching by author
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 ) ] ) );
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' );
140 # diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
142 my $bookseller = GetBookSellerFromId( $self->{'booksellerid'} );
143 ok( $bookseller->{'name'}, 'bookseller name' )
144 or diag( Data::Dumper->Dump( [ $bookseller ], [ 'bookseller' ] ) );
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 ) ] ) );
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' );
155 # searching by from_date
157 my $tomorrow = $self->tomorrow();
158 # diag( "tomorrow is $tomorrow" );
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 ) ] ) );
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' );
169 # searching by from_date
171 my $yesterday = $self->yesterday();
172 # diag( "yesterday was $yesterday" );
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 ) ] ) );
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' );
183 # set up some things necessary to make GetHistory use the IndependentBranches
184 $self->enable_independant_branches();
186 # just search by title here, we need to search by something.
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 ) ] ) );
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' );
196 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
200 $self->disable_independant_branches();