Bug 12863 [LESS follow-up] News in OPAC: HTML broken with nested p tags and multiple...
[koha.git] / t / db_dependent / CourseReserves.t
blobddb6ad9a31178f72fdc641c8b122a7ce0cea0797
1 #!/usr/bin/perl
3 # This is to test C4/Members
4 # It requires a working Koha database with the sample data
6 use Modern::Perl;
8 use Test::More tests => 21;
10 BEGIN {
11 use_ok('C4::Biblio');
12 use_ok('C4::Context');
13 use_ok('C4::CourseReserves', qw/:all/);
14 use_ok('C4::Items', qw(AddItem));
15 use_ok('MARC::Field');
16 use_ok('MARC::Record');
19 my $dbh = C4::Context->dbh;
21 # Start transaction
22 $dbh->{AutoCommit} = 0;
23 $dbh->{RaiseError} = 1;
25 my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
26 $sth->execute();
27 my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
29 # Create the item
30 my $record = MARC::Record->new();
31 $record->append_fields(
32 MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )
34 my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
35 my @iteminfo = C4::Items::AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber );
36 my $itemnumber = $iteminfo[2];
38 my $course_id = ModCourse(
39 course_name => "Test Course",
40 staff_note => "Test staff note",
41 public_note => "Test public note",
44 ok( $course_id, "ModCourse created course successfully" );
46 $course_id = ModCourse(
47 course_id => $course_id,
48 staff_note => "Test staff note 2",
51 my $course = GetCourse($course_id);
53 ok( $course->{'course_name'} eq "Test Course", "GetCourse returned correct course" );
54 ok( $course->{'staff_note'} eq "Test staff note 2", "ModCourse updated course succesfully" );
56 my $courses = GetCourses();
57 is( ref($courses), 'ARRAY', "GetCourses returns an array" );
58 my @match = map {$_->{course_name} eq 'Test Course'} @$courses;
59 ok( scalar(@match) > 0, "GetCourses returns valid array of course data" );
61 ModCourseInstructors( mode => 'add', course_id => $course_id, borrowernumbers => [ $borrowers[0]->{'borrowernumber'} ] );
62 $course = GetCourse($course_id);
63 ok( $course->{'instructors'}->[0]->{'borrowernumber'} == $borrowers[0]->{'borrowernumber'}, "ModCourseInstructors added instructors correctly" );
65 my $course_instructors = GetCourseInstructors($course_id);
66 ok( $course_instructors->[0]->{'borrowernumber'} eq $borrowers[0]->{'borrowernumber'}, "GetCourseInstructors returns valid data" );
68 my $ci_id = ModCourseItem( 'itemnumber' => $itemnumber );
69 ok( $ci_id, "ModCourseItem returned valid data" );
71 my $course_item = GetCourseItem( 'ci_id' => $ci_id );
72 ok( $course_item->{'itemnumber'} eq $itemnumber, "GetCourseItem returns valid data" );
74 my $cr_id = ModCourseReserve( 'course_id' => $course_id, 'ci_id' => $ci_id );
75 ok( $cr_id, "ModCourseReserve returns valid data" );
77 my $course_reserve = GetCourseReserve( 'course_id' => $course_id, 'ci_id' => $ci_id );
78 ok( $course_reserve->{'cr_id'} eq $cr_id, "GetCourseReserve returns valid data" );
80 my $course_reserves = GetCourseReserves( 'course_id' => $course_id );
81 ok( $course_reserves->[0]->{'ci_id'} eq $ci_id, "GetCourseReserves returns valid data." );
83 my $info = GetItemCourseReservesInfo( itemnumber => $itemnumber );
84 ok( $info->[0]->{'itemnumber'} eq $itemnumber, "GetItemReservesInfo returns valid data." );
86 DelCourseReserve( 'cr_id' => $cr_id );
87 $course_reserve = GetCourseReserve( 'cr_id' => $cr_id );
88 ok( !defined( $course_reserve->{'cr_id'} ), "DelCourseReserve functions correctly" );
90 DelCourse($course_id);
91 $course = GetCourse($course_id);
92 ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" );
94 $dbh->rollback;