Koha/t/lib/KohaTest/Acquisition/GetHistory.pm
Andrew Moore d37e9712eb adding database-dependent test libs.
These test libs should have been included in the previous patch.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
2008-04-21 11:26:28 -05:00

165 lines
6.9 KiB
Perl

package KohaTest::Acquisition::GetHistory;
use base qw( KohaTest::Acquisition );
use strict;
use warnings;
use Test::More;
use Time::localtime;
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 $tomorrowseconds = time + 60*60*24;
my $tomorrow = sprintf( '%04d-%02d-%02d',
localtime( $tomorrowseconds )->year() + 1900,
localtime( $tomorrowseconds )->mon() + 1,
localtime( $tomorrowseconds )->mday() );
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 $yesterdayseconds = time - 60*60*24;
my $yesterday = sprintf( '%04d-%02d-%02d',
localtime( $yesterdayseconds )->year() + 1900,
localtime( $yesterdayseconds )->mon() + 1,
localtime( $yesterdayseconds )->mday() );
# 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;