1 package KohaTest::Acquisition::GetParcels;
2 use base qw( KohaTest::Acquisition );
14 Please do not confuse this with the test suite for C4::Acquisition::GetParcel.
18 at first, there should be no parcels for our bookseller.
22 sub no_parcels : Test( 1 ) {
25 my @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
27 # code ( aqorders.booksellerinvoicenumber )
32 is( scalar @parcels, 0, 'our new bookseller has no parcels' )
33 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
38 we create an order, mark it as received, and then see if we can find
43 sub one_parcel : Test( 19 ) {
46 my $invoice = 123; # XXX what should this be?
47 my $today = sprintf( '%04d-%02d-%02d',
48 localtime->year() + 1900,
52 $self->create_order( authorizedby => 1, # XXX what should this be?
56 my @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
58 # code ( aqorders.booksellerinvoicenumber )
62 is( scalar @parcels, 1, 'we found one (1) parcel.' )
63 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
65 my $thisparcel = shift( @parcels );
66 is( scalar ( keys( %$thisparcel ) ), 6, 'my parcel hashref has 6 keys' )
67 or diag( Data::Dumper->Dump( [ $thisparcel ], [ 'thisparcel' ] ) );
69 is( $thisparcel->{'datereceived'}, $today, 'datereceived' );
70 is( $thisparcel->{'biblio'}, 1, 'biblio' );
71 is( $thisparcel->{'booksellerinvoicenumber'}, $invoice, 'booksellerinvoicenumber' );
73 # diag( Data::Dumper->Dump( [ $thisparcel ], [ 'thisparcel' ] ) );
79 we create another order, mark it as received, and then see if we can find
80 them all with GetParcels.
84 sub two_parcels : Test( 31 ) {
87 my $invoice = 1234; # XXX what should this be?
88 my $today = sprintf( '%04d-%02d-%02d',
89 localtime->year() + 1900,
92 $self->create_order( authorizedby => 1, # XXX what should this be?
97 # fetch them all and check that this one is last
98 my @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
100 # code ( aqorders.booksellerinvoicenumber )
104 is( scalar @parcels, 2, 'we found two (2) parcels.' )
105 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
107 my $thisparcel = pop( @parcels );
108 is( scalar ( keys( %$thisparcel ) ), 6, 'my parcel hashref has 6 keys' )
109 or diag( Data::Dumper->Dump( [ $thisparcel ], [ 'thisparcel' ] ) );
111 is( $thisparcel->{'datereceived'}, $today, 'datereceived' );
112 is( $thisparcel->{'biblio'}, 1, 'biblio' );
113 is( $thisparcel->{'booksellerinvoicenumber'}, $invoice, 'booksellerinvoicenumber' );
117 # fetch just one, by using the exact code
118 my @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
120 $invoice, # code ( aqorders.booksellerinvoicenumber )
124 is( scalar @parcels, 1, 'we found one (1) parcels.' )
125 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
127 my $thisparcel = pop( @parcels );
128 is( scalar ( keys( %$thisparcel ) ), 6, 'my parcel hashref has 6 keys' )
129 or diag( Data::Dumper->Dump( [ $thisparcel ], [ 'thisparcel' ] ) );
131 is( $thisparcel->{'datereceived'}, $today, 'datereceived' );
132 is( $thisparcel->{'biblio'}, 1, 'biblio' );
133 is( $thisparcel->{'booksellerinvoicenumber'}, $invoice, 'booksellerinvoicenumber' );
137 # fetch them both by using code 123, which gets 123 and 1234
138 my @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
140 '123', # code ( aqorders.booksellerinvoicenumber )
144 is( scalar @parcels, 2, 'we found 2 parcels.' )
145 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
150 # fetch them both, and try to order them
151 my @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
152 'aqorders.booksellerinvoicenumber', # order
153 undef, # code ( aqorders.booksellerinvoicenumber )
157 is( scalar @parcels, 2, 'we found 2 parcels.' )
158 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
159 is( $parcels[0]->{'booksellerinvoicenumber'}, 123 );
160 is( $parcels[1]->{'booksellerinvoicenumber'}, 1234 );
165 # fetch them both, and try to order them, descending
166 my @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
167 'aqorders.booksellerinvoicenumber desc', # order
168 undef, # code ( aqorders.booksellerinvoicenumber )
172 is( scalar @parcels, 2, 'we found 2 parcels.' )
173 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
174 is( $parcels[0]->{'booksellerinvoicenumber'}, 1234 );
175 is( $parcels[1]->{'booksellerinvoicenumber'}, 123 );
182 # diag( Data::Dumper->Dump( [ $thisparcel ], [ 'thisparcel' ] ) );
187 =head3 z_several_parcels_with_different_dates
189 we create an order, mark it as received, and then see if we can find
194 sub z_several_parcels_with_different_dates : Test( 44 ) {
197 my $authorizedby = 1; # XXX what should this be?
199 my @inputs = ( { invoice => 10,
200 date => sprintf( '%04d-%02d-%02d',
202 localtime->mon() + 1,
203 10 ), # I'm using the invoice number as the day.
206 date => sprintf( '%04d-%02d-%02d',
208 localtime->mon() + 1,
209 15 ), # I'm using the invoice number as the day.
212 date => sprintf( '%04d-%02d-%02d',
214 localtime->mon() + 1,
215 20 ), # I'm using the invoice number as the day.
219 foreach my $input ( @inputs ) {
220 $self->create_order( authorizedby => $authorizedby,
221 invoice => $input->{'invoice'},
222 date => $input->{'date'},
226 my @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
228 undef, # code ( aqorders.booksellerinvoicenumber )
229 sprintf( '%04d-%02d-%02d',
231 localtime->mon() + 1,
233 sprintf( '%04d-%02d-%02d',
235 localtime->mon() + 1,
238 is( scalar @parcels, scalar @inputs, 'we found all of the parcels.' )
239 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
241 @parcels = GetParcels( $self->{'booksellerid'}, # bookseller
243 undef, # code ( aqorders.booksellerinvoicenumber )
244 sprintf( '%04d-%02d-%02d',
246 localtime->mon() + 1,
248 sprintf( '%04d-%02d-%02d',
250 localtime->mon() + 1,
253 is( scalar @parcels, scalar @inputs - 1, 'we found all of the parcels except one' )
254 or diag( Data::Dumper->Dump( [ \@parcels ], [ 'parcels' ] ) );
258 # diag( Data::Dumper->Dump( [ $thisparcel ], [ 'thisparcel' ] ) );
265 $param{'authorizedby'} = 1 unless exists $param{'authorizedby'};
266 $param{'invoice'} = 1 unless exists $param{'invoice'};
267 $param{'date'} = sprintf( '%04d-%02d-%02d',
268 localtime->year() + 1900,
269 localtime->mon() + 1,
270 localtime->mday() ) unless exists $param{'date'};
272 my ( $basketno, $ordernumber ) = $self->create_new_basket( %param );
274 my $datereceived = ModReceiveOrder( $self->{'biblios'}[0], # biblionumber
275 $ordernumber, # $ordernumber,
279 $param{'invoice'}, # $invoiceno,
282 $self->{'bookfundid'}, # $bookfund,
283 $param{'date'}, # $datereceived
285 is( $datereceived, $param{'date'}, "the parcel was received on $datereceived" );