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' ] ) );
74 # searching by basket number
76 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( basket => $basketno );
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 basket no' );
80 is( $total_qty, 1, 'total_qty searched by basket no' );
81 is( $total_price, 1, 'total_price searched by basket no' );
82 is( $total_qtyreceived, 0, 'total_qtyreceived searched by basket no' );
84 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
87 # searching by invoice number
89 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( booksellerinvoicenumber => $INVOICE );
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 invoice no' );
93 is( $total_qty, 1, 'total_qty searched by invoice no' );
94 is( $total_price, 1, 'total_price searched by invoice no' );
95 is( $total_qtyreceived, 0, 'total_qtyreceived searched by invoice no' );
97 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
100 # searching by author
102 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( author => $bibliodata->{'author'} );
103 # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
105 is( scalar @$order_loop, 1, 'order_loop searched by author' );
106 is( $total_qty, 1, 'total_qty searched by author' );
107 is( $total_price, 1, 'total_price searched by author' );
108 is( $total_qtyreceived, 0, 'total_qtyreceived searched by author' );
113 # diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
115 my $bookseller = GetBookSellerFromId( $self->{'booksellerid'} );
116 ok( $bookseller->{'name'}, 'bookseller name' )
117 or diag( Data::Dumper->Dump( [ $bookseller ], [ 'bookseller' ] ) );
119 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( name => $bookseller->{'name'} );
120 # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
122 is( scalar @$order_loop, 1, 'order_loop searched by name' );
123 is( $total_qty, 1, 'total_qty searched by name' );
124 is( $total_price, 1, 'total_price searched by name' );
125 is( $total_qtyreceived, 0, 'total_qtyreceived searched by name' );
128 # searching by from_date
130 my $tomorrow = $self->tomorrow();
131 # diag( "tomorrow is $tomorrow" );
133 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( to_placed_on => $tomorrow );
134 # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
136 is( scalar @$order_loop, 1, 'order_loop searched by to_date' );
137 is( $total_qty, 1, 'total_qty searched by to_date' );
138 is( $total_price, 1, 'total_price searched by to_date' );
139 is( $total_qtyreceived, 0, 'total_qtyreceived searched by to_date' );
142 # searching by from_date
144 my $yesterday = $self->yesterday();
145 # diag( "yesterday was $yesterday" );
147 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( from_placed_on => $yesterday );
148 # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
150 is( scalar @$order_loop, 1, 'order_loop searched by from_date' );
151 is( $total_qty, 1, 'total_qty searched by from_date' );
152 is( $total_price, 1, 'total_price searched by from_date' );
153 is( $total_qtyreceived, 0, 'total_qtyreceived searched by from_date' );
156 # set up some things necessary to make GetHistory use the IndependantBranches
157 $self->enable_independant_branches();
159 # just search by title here, we need to search by something.
161 my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( title => $bibliodata->{'title'} );
162 # diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
164 is( scalar @$order_loop, 1, 'order_loop searched by title' );
165 is( $total_qty, 1, 'total_qty searched by title' );
166 is( $total_price, 1, 'total_price searched by title' );
167 is( $total_qtyreceived, 0, 'total_qtyreceived searched by title' );
169 # diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
173 $self->disable_independant_branches();