diff --git a/course/format/classes/sectiondelegate.php b/course/format/classes/sectiondelegate.php index 2dcfcb17ee1..14af95ff4db 100644 --- a/course/format/classes/sectiondelegate.php +++ b/course/format/classes/sectiondelegate.php @@ -124,4 +124,13 @@ abstract class sectiondelegate { ): ?action_menu { return $controlmenu->get_default_action_menu($output); } + + /** + * Get the parent section of the current delegated section if any. + * + * @return section_info|null + */ + public function get_parent_section(): ?section_info { + return null; + } } diff --git a/course/format/tests/sectiondelegate_test.php b/course/format/tests/sectiondelegate_test.php index e3932342c0e..39d793ba78f 100644 --- a/course/format/tests/sectiondelegate_test.php +++ b/course/format/tests/sectiondelegate_test.php @@ -141,4 +141,21 @@ class sectiondelegate_test extends \advanced_testcase { $result = $delegated->get_section_action_menu($format, $controlmenu, $renderer); $this->assertNull($result); } + + /** + * Test get_parent_section(). + * + * @covers ::get_parent_section + */ + public function test_get_parent_section(): void { + $this->resetAfterTest(); + + $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]); + $sectioninfo = formatactions::section($course)->create_delegated('test_component', 1); + + /** @var testsectiondelegate */ + $delegated = $sectioninfo->get_component_instance(); + + $this->assertNull($delegated->get_parent_section()); + } }