View | Details | Raw Unified | Return to bug 10332
Collapse All | Expand All

(-)a/t/db_dependent/CourseReserves.t (-19 / +22 lines)
Lines 3-31 Link Here
3
# This is to test C4/Members
3
# This is to test C4/Members
4
# It requires a working Koha database with the sample data
4
# It requires a working Koha database with the sample data
5
5
6
use strict;
6
use Modern::Perl;
7
use warnings;
8
7
9
use Test::More tests => 16;
8
use Test::More tests => 20;
10
use Data::Dumper;
9
use Data::Dumper;
11
10
12
BEGIN {
11
BEGIN {
12
    use_ok('C4::Biblio');
13
    use_ok('C4::Context');
13
    use_ok('C4::Context');
14
    use_ok('C4::CourseReserves', qw/:all/);
14
    use_ok('C4::CourseReserves', qw/:all/);
15
    use_ok('C4::Items', qw(AddItemFromMarc));
16
    use_ok('MARC::Field');
17
    use_ok('MARC::Record');
15
}
18
}
16
19
17
my $dbh = C4::Context->dbh;
20
my $dbh = C4::Context->dbh;
18
$dbh->do("TRUNCATE TABLE course_instructors");
19
$dbh->do("TRUNCATE TABLE courses");
20
$dbh->do("TRUNCATE TABLE course_reserves");
21
21
22
my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
22
my $sth = $dbh->prepare("SELECT * FROM borrowers ORDER BY RAND() LIMIT 10");
23
$sth->execute();
23
$sth->execute();
24
my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
24
my @borrowers = @{ $sth->fetchall_arrayref( {} ) };
25
25
26
$sth = $dbh->prepare("SELECT * FROM items ORDER BY RAND() LIMIT 10");
26
# Create the item
27
$sth->execute();
27
my $record = MARC::Record->new();
28
my @items = @{ $sth->fetchall_arrayref( {} ) };
28
$record->append_fields(
29
    MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )
30
);
31
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
32
my @iteminfo = C4::Items::AddItemFromMarc( $record, $biblionumber );
33
my $itemnumber = $iteminfo[2];
29
34
30
my $course_id = ModCourse(
35
my $course_id = ModCourse(
31
    course_name => "Test Course",
36
    course_name => "Test Course",
Lines 55-65 ok( $course->{'instructors'}->[0]->{'borrowernumber'} == $borrowers[0]->{'borrow Link Here
55
my $course_instructors = GetCourseInstructors($course_id);
60
my $course_instructors = GetCourseInstructors($course_id);
56
ok( $course_instructors->[0]->{'borrowernumber'} eq $borrowers[0]->{'borrowernumber'}, "GetCourseInstructors returns valid data" );
61
ok( $course_instructors->[0]->{'borrowernumber'} eq $borrowers[0]->{'borrowernumber'}, "GetCourseInstructors returns valid data" );
57
62
58
my $ci_id = ModCourseItem( 'itemnumber' => $items[0]->{'itemnumber'} );
63
my $ci_id = ModCourseItem( 'itemnumber' => $itemnumber );
59
ok( $ci_id, "ModCourseItem returned valid data" );
64
ok( $ci_id, "ModCourseItem returned valid data" );
60
65
61
my $course_item = GetCourseItem( 'ci_id' => $ci_id );
66
my $course_item = GetCourseItem( 'ci_id' => $ci_id );
62
ok( $course_item->{'itemnumber'} eq $items[0]->{'itemnumber'}, "GetCourseItem returns valid data" );
67
ok( $course_item->{'itemnumber'} eq $itemnumber, "GetCourseItem returns valid data" );
63
68
64
my $cr_id = ModCourseReserve( 'course_id' => $course_id, 'ci_id' => $ci_id );
69
my $cr_id = ModCourseReserve( 'course_id' => $course_id, 'ci_id' => $ci_id );
65
ok( $cr_id, "ModCourseReserve returns valid data" );
70
ok( $cr_id, "ModCourseReserve returns valid data" );
Lines 70-77 ok( $course_reserve->{'cr_id'} eq $cr_id, "GetCourseReserve returns valid data" Link Here
70
my $course_reserves = GetCourseReserves( 'course_id' => $course_id );
75
my $course_reserves = GetCourseReserves( 'course_id' => $course_id );
71
ok( $course_reserves->[0]->{'ci_id'} eq $ci_id, "GetCourseReserves returns valid data." );
76
ok( $course_reserves->[0]->{'ci_id'} eq $ci_id, "GetCourseReserves returns valid data." );
72
77
73
my $info = GetItemCourseReservesInfo( itemnumber => $items[0]->{'itemnumber'} );
78
my $info = GetItemCourseReservesInfo( itemnumber => $itemnumber );
74
ok( $info->[0]->{'itemnumber'} eq $items[0]->{'itemnumber'}, "GetItemReservesInfo returns valid data." );
79
ok( $info->[0]->{'itemnumber'} eq $itemnumber, "GetItemReservesInfo returns valid data." );
75
80
76
DelCourseReserve( 'cr_id' => $cr_id );
81
DelCourseReserve( 'cr_id' => $cr_id );
77
$course_reserve = GetCourseReserve( 'cr_id' => $cr_id );
82
$course_reserve = GetCourseReserve( 'cr_id' => $cr_id );
Lines 81-88 DelCourse($course_id); Link Here
81
$course = GetCourse($course_id);
86
$course = GetCourse($course_id);
82
ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" );
87
ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" );
83
88
84
$dbh->do("TRUNCATE TABLE course_instructors");
89
END {
85
$dbh->do("TRUNCATE TABLE courses");
90
    C4::Items::DelItem( $dbh, $biblionumber, $itemnumber );
86
$dbh->do("TRUNCATE TABLE course_reserves");
91
    C4::Biblio::DelBiblio( $biblionumber );
87
92
};
88
exit;
89
- 

Return to bug 10332