MDL-80186 course: adding new fields to delegate sections logic

This commit is contained in:
Ferran Recio 2023-11-23 09:31:19 +01:00
parent 513f3b02c7
commit 837dc7e852
14 changed files with 489 additions and 8 deletions

View file

@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace test_component\courseformat;
use core_courseformat\sectiondelegate as sectiondelegatebase;
/**
* Test class for section delegate.
*
* @package core_courseformat
* @copyright 2023 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sectiondelegate extends sectiondelegatebase {
}

View file

@ -36,6 +36,15 @@ use Exception;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class modinfolib_test extends advanced_testcase {
/**
* Setup to ensure that fixtures are loaded.
*/
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->libdir . '/tests/fixtures/sectiondelegatetest.php');
}
public function test_section_info_properties() {
global $DB, $CFG;
@ -1358,4 +1367,36 @@ class modinfolib_test extends advanced_testcase {
// Obviously, modinfo should include the Page now.
$this->assertCount(1, $modinfo->get_instances_of('page'));
}
/**
* Test for get_component_instance.
* @covers \section_info::get_component_instance
*/
public function test_get_component_instance(): void {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 2]);
course_update_section(
$course,
$DB->get_record('course_sections', ['course' => $course->id, 'section' => 2]),
[
'component' => 'test_component',
'itemid' => 1,
]
);
$modinfo = get_fast_modinfo($course->id);
$sectioninfos = $modinfo->get_section_info_all();
$this->assertNull($sectioninfos[1]->get_component_instance());
$this->assertNull($sectioninfos[1]->component);
$this->assertNull($sectioninfos[1]->itemid);
$this->assertInstanceOf('\core_courseformat\sectiondelegate', $sectioninfos[2]->get_component_instance());
$this->assertInstanceOf('\test_component\courseformat\sectiondelegate', $sectioninfos[2]->get_component_instance());
$this->assertEquals('test_component', $sectioninfos[2]->component);
$this->assertEquals(1, $sectioninfos[2]->itemid);
}
}