. declare(strict_types=1); namespace core_courseformat\external; defined('MOODLE_INTERNAL') || die(); use core_courseformat\stateactions; use core_courseformat\stateupdates; global $CFG; require_once($CFG->dirroot . '/webservice/tests/helpers.php'); /** * Tests for the delete section test class. * * @package core_courseformat * @copyright 2025 Laurent David * @category test * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @coversDefaultClass \core_courseformat\stateactions */ final class delete_section_test extends \externallib_advanced_testcase { /** * Test the webservice can execute the section_delete action. * * @covers ::section_delete * @dataProvider section_delete_provider * @param int $sectionum * @param string $format * @param int $expectedsectionum * * @throws \moodle_exception */ public function test_delete_section(int $sectionum, string $format, int $expectedsectionum): void { $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(['numsections' => $sectionum, 'format' => $format]); $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher'); // Execute the method. $courseformat = course_get_format($course->id); $updates = new stateupdates($courseformat); $modinfo = get_fast_modinfo($course); $sections = $modinfo->get_section_info_all(); $sectionsid = array_map(function ($section) { return $section->id; }, $sections); $actions = new stateactions(); $this->setUser($teacher); $actions->section_delete( $updates, $course, $sectionsid ); // Check result. $modinfo = get_fast_modinfo($course); $sections = $modinfo->get_section_info_all(); $this->assertCount($expectedsectionum, $sections); } /** * Data provider for the test_delete_section method. * * @return array */ public static function section_delete_provider(): array { return [ 'format topic' => [ 'sectionum' => 4, 'format' => 'topics', 'expectedsectionum' => 1, ], 'format weeks' => [ 'sectionum' => 4, 'format' => 'weeks', 'expectedsectionum' => 1, ], 'format social' => [ 'sectionum' => 4, 'format' => 'social', 'expectedsectionum' => 5, ], ]; } }