From 362e1025c9c59b482c0c61fa519f539ec0a955f4 Mon Sep 17 00:00:00 2001 From: Andrew Moore Date: Fri, 25 Jul 2008 11:55:11 -0500 Subject: [PATCH] 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 --- t/lib/KohaTest.pm | 75 ++++++++++++++++++++---- t/lib/KohaTest/Acquisition/GetHistory.pm | 14 +---- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/t/lib/KohaTest.pm b/t/lib/KohaTest.pm index 720017a83c..7da83614dd 100644 --- a/t/lib/KohaTest.pm +++ b/t/lib/KohaTest.pm @@ -20,6 +20,7 @@ use C4::Installer; use C4::Languages; use File::Temp qw/ tempdir /; use CGI; +use Time::localtime; # Since this is an abstract base class, this prevents these tests from # being run directly unless we're testing a subclass. It just makes @@ -475,6 +476,50 @@ sub random_date { } +=head3 tomorrow + +returns tomorrow's date as YYYY-MM-DD. + +=cut + +sub tomorrow { + my $self = shift; + + return $self->days_from_now( 1 ); + +} + +=head3 yesterday + +returns yesterday's date as YYYY-MM-DD. + +=cut + +sub yesterday { + my $self = shift; + + return $self->days_from_now( -1 ); +} + + +=head3 days_from_now + +returns an arbitrary date based on today in YYYY-MM-DD format. + +=cut + +sub days_from_now { + my $self = shift; + my $days = shift or return; + + my $seconds = time + $days * 60*60*24; + my $yyyymmdd = sprintf( '%04d-%02d-%02d', + localtime( $seconds )->year() + 1900, + localtime( $seconds )->mon() + 1, + localtime( $seconds )->mday() ); + return $yyyymmdd; +} + =head3 add_biblios $self->add_biblios( count => 10, @@ -507,21 +552,25 @@ sub add_biblios { foreach my $counter ( 1..$param{'count'} ) { my $marcrecord = MARC::Record->new(); isa_ok( $marcrecord, 'MARC::Record' ); - my $appendedfieldscount = $marcrecord->append_fields( MARC::Field->new( '100', '1', '0', - a => 'Twain, Mark', - d => "1835-1910." ), - MARC::Field->new( '245', '1', '4', - a => sprintf( 'The Adventures of Huckleberry Finn Test %s', $counter ), - c => "Mark Twain ; illustrated by E.W. Kemble." ), - MARC::Field->new( '952', '0', '0', - p => '12345678' . $self->random_string() ), # barcode - MARC::Field->new( '952', '0', '0', - a => 'CPL', - b => 'CPL' ), - ); + my @marc_fields = ( MARC::Field->new( '100', '1', '0', + a => 'Twain, Mark', + d => "1835-1910." ), + MARC::Field->new( '245', '1', '4', + a => sprintf( 'The Adventures of Huckleberry Finn Test %s', $counter ), + c => "Mark Twain ; illustrated by E.W. Kemble." ), + MARC::Field->new( '952', '0', '0', + p => '12345678' . $self->random_string() ), # barcode + MARC::Field->new( '952', '0', '0', + o => $self->random_string() ), # callnumber + MARC::Field->new( '952', '0', '0', + a => 'CPL', + b => 'CPL' ), + ); + + my $appendedfieldscount = $marcrecord->append_fields( @marc_fields ); diag $MARC::Record::ERROR if ( $MARC::Record::ERROR ); - is( $appendedfieldscount, 4, 'added 4 fields' ); + is( $appendedfieldscount, scalar @marc_fields, 'added correct number of MARC fields' ); my $frameworkcode = ''; # XXX I'd like to put something reasonable here. my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $marcrecord, $frameworkcode ); diff --git a/t/lib/KohaTest/Acquisition/GetHistory.pm b/t/lib/KohaTest/Acquisition/GetHistory.pm index 940d1a988a..be5e6be815 100644 --- a/t/lib/KohaTest/Acquisition/GetHistory.pm +++ b/t/lib/KohaTest/Acquisition/GetHistory.pm @@ -5,7 +5,6 @@ use strict; use warnings; use Test::More; -use Time::localtime; use C4::Acquisition; use C4::Context; @@ -104,11 +103,8 @@ sub one_order : Test( 50 ) { # 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 $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 ) ] ) ); @@ -121,11 +117,7 @@ sub one_order : Test( 50 ) { # 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() ); + my $yesterday = $self->yesterday(); # diag( "yesterday was $yesterday" ); my ( $order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( undef, undef, undef, $yesterday ); -- 2.39.5