Koha/t/lib/KohaTest/Acquisition/GetHistory.pm
Andrew Moore 362e1025c9 Bug 1953 [1/3]: test suite improvements
Here are a few improvments to the test suite to make it easier to write some tests
for C4::Items

I extracted "tomorrow" and "yesterday" methods from a test module into the base class
so that they could be used by multiple test modules

Adding callnumber to items added in the test suite.

I recatored KohaTest::add_biblios a bit to remove the manual count of the number of
MARC::Fields that were added.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
2008-07-27 06:10:47 -05:00

157 lines
6.3 KiB
Perl

package KohaTest::Acquisition::GetHistory;
use base qw( KohaTest::Acquisition );
use strict;
use warnings;
use Test::More;
use C4::Acquisition;
use C4::Context;
use C4::Members;
use C4::Biblio;
use C4::Bookseller;
=head3 no_history
=cut
sub no_history : Test( 4 ) {
my $self = shift;
# my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( $title, $author, $name, $from_placed_on, $to_placed_on )
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory();
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 0, 'order_loop is empty' );
is( $total_qty, 0, 'total_qty' );
is( $total_price, 0, 'total_price' );
is( $total_qtyreceived, 0, 'total_qtyreceived' );
}
=head3 one_order
=cut
sub one_order : Test( 50 ) {
my $self = shift;
my ( $basketno, $ordnum ) = $self->create_new_basket();
ok( $basketno, "basketno is $basketno" );
ok( $ordnum, "ordnum is $ordnum" );
# No arguments fetches no history.
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory();
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 0, 'order_loop is empty' );
is( $total_qty, 0, 'total_qty' );
is( $total_price, 0, 'total_price' );
is( $total_qtyreceived, 0, 'total_qtyreceived' );
}
my $bibliodata = GetBiblioData( $self->{'biblios'}[0] );
ok( $bibliodata->{'title'}, 'the biblio has a title' )
or diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
# searching by title should find it.
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( $bibliodata->{'title'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by title' );
is( $total_qty, 1, 'total_qty searched by title' );
is( $total_price, 1, 'total_price searched by title' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by title' );
# diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
}
# searching by author
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, $bibliodata->{'author'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by author' );
is( $total_qty, 1, 'total_qty searched by author' );
is( $total_price, 1, 'total_price searched by author' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by author' );
}
# searching by name
{
# diag( Data::Dumper->Dump( [ $bibliodata ], [ 'bibliodata' ] ) );
my $bookseller = GetBookSellerFromId( $self->{'booksellerid'} );
ok( $bookseller->{'name'}, 'bookseller name' )
or diag( Data::Dumper->Dump( [ $bookseller ], [ 'bookseller' ] ) );
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, undef, $bookseller->{'name'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by name' );
is( $total_qty, 1, 'total_qty searched by name' );
is( $total_price, 1, 'total_price searched by name' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by name' );
}
# searching by from_date
{
my $tomorrow = $self->tomorrow();
# diag( "tomorrow is $tomorrow" );
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, undef, undef, undef, $tomorrow );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by to_date' );
is( $total_qty, 1, 'total_qty searched by to_date' );
is( $total_price, 1, 'total_price searched by to_date' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by to_date' );
}
# searching by from_date
{
my $yesterday = $self->yesterday();
# diag( "yesterday was $yesterday" );
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, undef, undef, $yesterday );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by from_date' );
is( $total_qty, 1, 'total_qty searched by from_date' );
is( $total_price, 1, 'total_price searched by from_date' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by from_date' );
}
# set up some things necessary to make GetHistory use the IndependantBranches
$self->enable_independant_branches();
# just search by title here, we need to search by something.
{
my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( $bibliodata->{'title'} );
# diag( Data::Dumper->Dump( [ $order_loop, $total_qty, $total_price, $total_qtyreceived ], [ qw( order_loop total_qty total_price total_qtyreceived ) ] ) );
is( scalar @$order_loop, 1, 'order_loop searched by title' );
is( $total_qty, 1, 'total_qty searched by title' );
is( $total_price, 1, 'total_price searched by title' );
is( $total_qtyreceived, 0, 'total_qtyreceived searched by title' );
# diag( Data::Dumper->Dump( [ $order_loop ], [ 'order_loop' ] ) );
}
# reset that.
$self->disable_independant_branches();
}
1;