Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2024 Koha Development team |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 1; |
23 |
|
24 |
use Koha::Course; |
25 |
use Koha::Courses; |
26 |
use Koha::Course::Instructor; |
27 |
use Koha::Course::Instructors; |
28 |
use Koha::Database; |
29 |
|
30 |
use t::lib::TestBuilder; |
31 |
use t::lib::Mocks; |
32 |
|
33 |
my $schema = Koha::Database->new->schema; |
34 |
my $builder = t::lib::TestBuilder->new; |
35 |
|
36 |
subtest 'relationship tests' => sub { |
37 |
plan tests => 1; |
38 |
|
39 |
subtest 'intructors' => sub { |
40 |
plan tests => 3; |
41 |
|
42 |
$schema->storage->txn_begin; |
43 |
|
44 |
my $course = $builder->build_object( { class => 'Koha::Courses' } ); |
45 |
|
46 |
my $instructors = $course->instructors; |
47 |
is( ref($instructors), 'Koha::Patrons', '->instructors returns a Koha::Patrons object' ); |
48 |
is( $instructors->count, 0, '->instructors->count returns 0 when there are no instructors associated' ); |
49 |
|
50 |
foreach my $i ( 0 .. 3 ) { |
51 |
|
52 |
my $instructor = $builder->build_object( { class => 'Koha::Patrons' } ); |
53 |
|
54 |
Koha::Course::Instructor->new( |
55 |
{ |
56 |
course_id => $course->course_id, |
57 |
borrowernumber => $instructor->borrowernumber, |
58 |
} |
59 |
)->store(); |
60 |
} |
61 |
|
62 |
$instructors = $course->instructors; |
63 |
is( $instructors->count, 4, '4 instructors returns' ); |
64 |
|
65 |
$schema->storage->txn_rollback; |
66 |
}; |
67 |
}; |