X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=t%2Fdb_dependent%2FCourseReserves.t;h=42d8d1f670a2867a913f3c34be2c46e7fff093a6;hb=7d8b96803f664d86762a6afb966051f7d565c40e;hp=d122005017cb3dc629997b5a6e32a15f45ec8554;hpb=d157179618241f6b3aa5e6cf54ac5cd08cac90f8;p=koha-ffzg.git diff --git a/t/db_dependent/CourseReserves.t b/t/db_dependent/CourseReserves.t index d122005017..42d8d1f670 100755 --- a/t/db_dependent/CourseReserves.t +++ b/t/db_dependent/CourseReserves.t @@ -1,35 +1,62 @@ #!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# This is to test C4/Members -# It requires a working Koha database with the sample data +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 21; +use Test::More tests => 27; + +use Koha::Database; +use t::lib::TestBuilder; BEGIN { + use_ok('C4::Items', qw(AddItem)); use_ok('C4::Biblio'); - use_ok('C4::Context'); use_ok('C4::CourseReserves', qw/:all/); - use_ok('C4::Items', qw(AddItemFromMarc)); + use_ok('C4::Context'); use_ok('MARC::Field'); use_ok('MARC::Record'); } +my $schema = Koha::Database->schema; +$schema->storage->txn_begin; +my $builder = t::lib::TestBuilder->new; my $dbh = C4::Context->dbh; +$dbh->{RaiseError} = 1; -my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10"); -$sth->execute(); -my @borrowers = @{ $sth->fetchall_arrayref( {} ) }; +my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; +my $itemtype = $builder->build( + { source => 'Itemtype', value => { notforloan => undef } } )->{itemtype}; -# Create the item -my $record = MARC::Record->new(); -$record->append_fields( - MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' ) -); +# Create 10 sample borrowers +my @borrowers = (); +foreach (1..10) { + push @borrowers, $builder->build({ source => 'Borrower' }); +} + +# Create the a record with an item +my $record = MARC::Record->new; my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, ''); -my @iteminfo = C4::Items::AddItemFromMarc( $record, $biblionumber ); -my $itemnumber = $iteminfo[2]; +my ( undef, undef, $itemnumber ) = C4::Items::AddItem( + { homebranch => $branchcode, + holdingbranch => $branchcode, + itype => $itemtype + }, + $biblionumber +); my $course_id = ModCourse( course_name => "Test Course", @@ -42,12 +69,14 @@ ok( $course_id, "ModCourse created course successfully" ); $course_id = ModCourse( course_id => $course_id, staff_note => "Test staff note 2", + enabled => 'no', ); my $course = GetCourse($course_id); ok( $course->{'course_name'} eq "Test Course", "GetCourse returned correct course" ); ok( $course->{'staff_note'} eq "Test staff note 2", "ModCourse updated course succesfully" ); +is( $course->{'enabled'}, 'no', "Test Course is disabled" ); my $courses = GetCourses(); is( ref($courses), 'ARRAY', "GetCourses returns an array" ); @@ -76,6 +105,26 @@ 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." ); +## Check for regression of Bug 15530 +$course_id = ModCourse( + course_id => $course_id, + enabled => 'yes', +); +$course = GetCourse($course_id); +is( $course->{'enabled'}, 'yes', "Test Course is enabled" ); +$course_item = GetCourseItem( 'ci_id' => $ci_id ); +is( $course_item->{enabled}, 'yes', "Course item is enabled after modding disabled course" ); +my $disabled_course_id = ModCourse( + course_name => "Disabled Course", + enabled => 'no', +); +my $disabled_course = GetCourse( $disabled_course_id ); +is( $disabled_course->{'enabled'}, 'no', "Disabled Course is disabled" ); +my $cr_id2 = ModCourseReserve( 'course_id' => $disabled_course_id, 'ci_id' => $ci_id ); +$course_item = GetCourseItem( 'ci_id' => $ci_id ); +is( $course_item->{enabled}, 'yes', "Course item is enabled after modding disabled course" ); +## End check for regression of Bug 15530 + my $info = GetItemCourseReservesInfo( itemnumber => $itemnumber ); ok( $info->[0]->{'itemnumber'} eq $itemnumber, "GetItemReservesInfo returns valid data." ); @@ -87,7 +136,7 @@ DelCourse($course_id); $course = GetCourse($course_id); ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" ); -END { - C4::Items::DelItem( $dbh, $biblionumber, $itemnumber ); - C4::Biblio::DelBiblio( $biblionumber ); -}; +$courses = SearchCourses(); # FIXME Lack of tests for SearchCourses +is( ref($courses), 'ARRAY', 'SearchCourses should not crash and return an arrayref' ); + +$schema->storage->txn_rollback;