From 62059d15fa9cd950827bf630f354f167cddf746f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 29 Jan 2024 09:41:08 +0000 Subject: [PATCH] Bug 28762: Add test for new 'instructors' accessor --- t/db_dependent/Koha/Course.t | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 t/db_dependent/Koha/Course.t diff --git a/t/db_dependent/Koha/Course.t b/t/db_dependent/Koha/Course.t new file mode 100755 index 00000000000..af23e03d549 --- /dev/null +++ b/t/db_dependent/Koha/Course.t @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +# Copyright 2024 Koha Development team +# +# 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. +# +# 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 => 1; + +use Koha::Course; +use Koha::Courses; +use Koha::Course::Instructor; +use Koha::Course::Instructors; +use Koha::Database; + +use t::lib::TestBuilder; +use t::lib::Mocks; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'relationship tests' => sub { + plan tests => 1; + + subtest 'intructors' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $course = $builder->build_object( { class => 'Koha::Courses' } ); + + my $instructors = $course->instructors; + is( ref($instructors), 'Koha::Patrons', '->instructors returns a Koha::Patrons object' ); + is( $instructors->count, 0, '->instructors->count returns 0 when there are no instructors associated' ); + + foreach my $i ( 0 .. 3 ) { + + my $instructor = $builder->build_object( { class => 'Koha::Patrons' } ); + + Koha::Course::Instructor->new( + { + course_id => $course->course_id, + borrowernumber => $instructor->borrowernumber, + } + )->store(); + } + + $instructors = $course->instructors; + is( $instructors->count, 4, '4 instructors returns' ); + + $schema->storage->txn_rollback; + }; +}; -- 2.44.0