1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
declare(strict_types=1);
|
|
|
18 |
|
|
|
19 |
namespace core_courseformat\external;
|
|
|
20 |
|
|
|
21 |
defined('MOODLE_INTERNAL') || die();
|
|
|
22 |
|
|
|
23 |
use core_courseformat\stateactions;
|
|
|
24 |
use core_courseformat\stateupdates;
|
|
|
25 |
|
|
|
26 |
global $CFG;
|
|
|
27 |
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Tests for the delete section test class.
|
|
|
31 |
*
|
|
|
32 |
* @package core_courseformat
|
|
|
33 |
* @copyright 2025 Laurent David <laurent.david@moodle.com>
|
|
|
34 |
* @category test
|
|
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
36 |
* @coversDefaultClass \core_courseformat\stateactions
|
|
|
37 |
*/
|
|
|
38 |
final class delete_section_test extends \externallib_advanced_testcase {
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Test the webservice can execute the section_delete action.
|
|
|
42 |
*
|
|
|
43 |
* @covers ::section_delete
|
|
|
44 |
* @dataProvider section_delete_provider
|
|
|
45 |
* @param int $sectionum
|
|
|
46 |
* @param string $format
|
|
|
47 |
* @param int $expectedsectionum
|
|
|
48 |
*
|
|
|
49 |
* @throws \moodle_exception
|
|
|
50 |
*/
|
|
|
51 |
public function test_delete_section(int $sectionum, string $format, int $expectedsectionum): void {
|
|
|
52 |
$this->resetAfterTest();
|
|
|
53 |
|
|
|
54 |
$course =
|
|
|
55 |
$this->getDataGenerator()->create_course(['numsections' => $sectionum, 'format' => $format]);
|
|
|
56 |
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
|
|
57 |
// Execute the method.
|
|
|
58 |
$courseformat = course_get_format($course->id);
|
|
|
59 |
$updates = new stateupdates($courseformat);
|
|
|
60 |
$modinfo = get_fast_modinfo($course);
|
|
|
61 |
$sections = $modinfo->get_section_info_all();
|
|
|
62 |
$sectionsid = array_map(function ($section) {
|
|
|
63 |
return $section->id;
|
|
|
64 |
}, $sections);
|
|
|
65 |
$actions = new stateactions();
|
|
|
66 |
$this->setUser($teacher);
|
|
|
67 |
$actions->section_delete(
|
|
|
68 |
$updates,
|
|
|
69 |
$course,
|
|
|
70 |
$sectionsid
|
|
|
71 |
);
|
|
|
72 |
// Check result.
|
|
|
73 |
$modinfo = get_fast_modinfo($course);
|
|
|
74 |
$sections = $modinfo->get_section_info_all();
|
|
|
75 |
$this->assertCount($expectedsectionum, $sections);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Data provider for the test_delete_section method.
|
|
|
80 |
*
|
|
|
81 |
* @return array
|
|
|
82 |
*/
|
|
|
83 |
public static function section_delete_provider(): array {
|
|
|
84 |
return [
|
|
|
85 |
'format topic' => [
|
|
|
86 |
'sectionum' => 4,
|
|
|
87 |
'format' => 'topics',
|
|
|
88 |
'expectedsectionum' => 1,
|
|
|
89 |
],
|
|
|
90 |
'format weeks' => [
|
|
|
91 |
'sectionum' => 4,
|
|
|
92 |
'format' => 'weeks',
|
|
|
93 |
'expectedsectionum' => 1,
|
|
|
94 |
],
|
|
|
95 |
'format social' => [
|
|
|
96 |
'sectionum' => 4,
|
|
|
97 |
'format' => 'social',
|
|
|
98 |
'expectedsectionum' => 5,
|
|
|
99 |
],
|
|
|
100 |
];
|
|
|
101 |
}
|
|
|
102 |
}
|