From 86aa4bf3644ba5564c4c045b8eb0419053184227 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 May 2013 14:23:45 +0200 Subject: [PATCH] Bug 10332: CourseReserves.t needs to create its own data prove t/db_dependent/CourseReserves.t t/db_dependent/CourseReserves.t .. ok All tests successful. Files=1, Tests=20, 2 wallclock secs ( 0.02 usr 0.00 sys + 0.43 cusr 0.03 csys = 0.48 CPU) Result: PASS Signed-off-by: Jared Camins-Esakov Without correct data, test fails prior to patch, passes no matter what after patch is applied. Signed-off-by: Kyle M Hall Signed-off-by: Galen Charlton --- t/db_dependent/CourseReserves.t | 40 +++++++++++++++++++++----------------- 1 files changed, 22 insertions(+), 18 deletions(-) diff --git a/t/db_dependent/CourseReserves.t b/t/db_dependent/CourseReserves.t index 9c3172a..a7955e4 100755 --- a/t/db_dependent/CourseReserves.t +++ b/t/db_dependent/CourseReserves.t @@ -3,29 +3,34 @@ # This is to test C4/Members # It requires a working Koha database with the sample data -use strict; -use warnings; +use Modern::Perl; -use Test::More tests => 16; +use Test::More tests => 20; use Data::Dumper; BEGIN { + use_ok('C4::Biblio'); use_ok('C4::Context'); use_ok('C4::CourseReserves', qw/:all/); + use_ok('C4::Items', qw(AddItemFromMarc)); + use_ok('MARC::Field'); + use_ok('MARC::Record'); } my $dbh = C4::Context->dbh; -$dbh->do("TRUNCATE TABLE course_instructors"); -$dbh->do("TRUNCATE TABLE courses"); -$dbh->do("TRUNCATE TABLE course_reserves"); my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10"); $sth->execute(); my @borrowers = @{ $sth->fetchall_arrayref( {} ) }; -$sth = $dbh->prepare("SELECT * FROM items ORDER BY RAND() LIMIT 10"); -$sth->execute(); -my @items = @{ $sth->fetchall_arrayref( {} ) }; +# Create the item +my $record = MARC::Record->new(); +$record->append_fields( + MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' ) +); +my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, ''); +my @iteminfo = C4::Items::AddItemFromMarc( $record, $biblionumber ); +my $itemnumber = $iteminfo[2]; my $course_id = ModCourse( course_name => "Test Course", @@ -55,11 +60,11 @@ ok( $course->{'instructors'}->[0]->{'borrowernumber'} == $borrowers[0]->{'borrow my $course_instructors = GetCourseInstructors($course_id); ok( $course_instructors->[0]->{'borrowernumber'} eq $borrowers[0]->{'borrowernumber'}, "GetCourseInstructors returns valid data" ); -my $ci_id = ModCourseItem( 'itemnumber' => $items[0]->{'itemnumber'} ); +my $ci_id = ModCourseItem( 'itemnumber' => $itemnumber ); ok( $ci_id, "ModCourseItem returned valid data" ); my $course_item = GetCourseItem( 'ci_id' => $ci_id ); -ok( $course_item->{'itemnumber'} eq $items[0]->{'itemnumber'}, "GetCourseItem returns valid data" ); +ok( $course_item->{'itemnumber'} eq $itemnumber, "GetCourseItem returns valid data" ); my $cr_id = ModCourseReserve( 'course_id' => $course_id, 'ci_id' => $ci_id ); ok( $cr_id, "ModCourseReserve returns valid data" ); @@ -70,8 +75,8 @@ ok( $course_reserve->{'cr_id'} eq $cr_id, "GetCourseReserve returns valid data" my $course_reserves = GetCourseReserves( 'course_id' => $course_id ); ok( $course_reserves->[0]->{'ci_id'} eq $ci_id, "GetCourseReserves returns valid data." ); -my $info = GetItemCourseReservesInfo( itemnumber => $items[0]->{'itemnumber'} ); -ok( $info->[0]->{'itemnumber'} eq $items[0]->{'itemnumber'}, "GetItemReservesInfo returns valid data." ); +my $info = GetItemCourseReservesInfo( itemnumber => $itemnumber ); +ok( $info->[0]->{'itemnumber'} eq $itemnumber, "GetItemReservesInfo returns valid data." ); DelCourseReserve( 'cr_id' => $cr_id ); $course_reserve = GetCourseReserve( 'cr_id' => $cr_id ); @@ -81,8 +86,7 @@ DelCourse($course_id); $course = GetCourse($course_id); ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" ); -$dbh->do("TRUNCATE TABLE course_instructors"); -$dbh->do("TRUNCATE TABLE courses"); -$dbh->do("TRUNCATE TABLE course_reserves"); - -exit; +END { + C4::Items::DelItem( $dbh, $biblionumber, $itemnumber ); + C4::Biblio::DelBiblio( $biblionumber ); +}; -- 1.7.2.5