Skip to content

Commit

Permalink
Merge branch 'MDL-74925-400' of https://github.com/lameze/moodle into…
Browse files Browse the repository at this point in the history
… MOODLE_400_STABLE
  • Loading branch information
junpataleta committed Jul 18, 2022
2 parents 7d36cf9 + 437db87 commit 4525bad
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 15 deletions.
4 changes: 2 additions & 2 deletions course/format/classes/stateactions.php
Expand Up @@ -247,11 +247,11 @@ public function section_delete(
if (!empty($modinfo->sections[$section->section])) {
foreach ($modinfo->sections[$section->section] as $modnumber) {
$cm = $modinfo->cms[$modnumber];
$updates->add_cm_delete($cm->id);
$updates->add_cm_remove($cm->id);
}
}
course_delete_section($course, $section, true, true);
$updates->add_section_delete($sectionid);
$updates->add_section_remove($sectionid);
}

// Removing a section affects the full course structure.
Expand Down
20 changes: 19 additions & 1 deletion course/format/classes/stateupdates.php
Expand Up @@ -134,6 +134,15 @@ public function add_section_delete(int $sectionid): void {
$this->add_update('section', 'remove', (object)['id' => $sectionid]);
}

/**
* Add track about a section removed.
*
* @param int $sectionid The affected section id.
*/
public function add_section_remove(int $sectionid): void {
$this->add_update('section', 'remove', (object)['id' => $sectionid]);
}

/**
* Add track about a course module state update.
*
Expand Down Expand Up @@ -184,11 +193,20 @@ public function add_cm_delete(int $cmid): void {
$this->add_update('cm', 'remove', (object)['id' => $cmid]);
}

/**
* Add track about a course module removed.
*
* @param int $cmid the affected course module id
*/
public function add_cm_remove(int $cmid): void {
$this->add_update('cm', 'remove', (object)['id' => $cmid]);
}

/**
* Add a valid update message to the update list.
*
* @param string $name the update name
* @param string $action the update action (usually update, create, delete)
* @param string $action the update action (usually update, create, remove)
* @param stdClass $fields the object fields
*/
protected function add_update(string $name, string $action, stdClass $fields): void {
Expand Down
2 changes: 1 addition & 1 deletion course/format/tests/external/update_course_test.php
Expand Up @@ -133,7 +133,7 @@ public function execute_course_state_provider(): array {
'action' => 'format_do_something',
'expected' => [
'count' => 1,
'action' => 'delete',
'action' => 'remove',
'visible' => null,
],
'expectexception' => false,
Expand Down
Expand Up @@ -65,7 +65,7 @@ public function format_do_something(
?int $targetcmid = null
): void {

$updates->add_cm_delete(array_pop($ids));
$updates->add_cm_remove(array_pop($ids));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions course/format/tests/stateactions_test.php
Expand Up @@ -143,7 +143,7 @@ private function summarize_updates(stateupdates $updateobj): array {
'cm' => [],
'count' => 0,
],
'delete' => [
'remove' => [
'course' => [],
'section' => [],
'cm' => [],
Expand Down Expand Up @@ -236,10 +236,10 @@ public function test_get_state(
// Format results in a way we can compare easily.
$results = $this->summarize_updates($updates);

// The state actions does not use create or delete actions because they are designed
// The state actions does not use create or remove actions because they are designed
// to refresh parts of the state.
$this->assertEquals(0, $results['create']['count']);
$this->assertEquals(0, $results['delete']['count']);
$this->assertEquals(0, $results['remove']['count']);

// Validate we have all the expected entries.
$expectedtotal = count($expectedresults['course']) + count($expectedresults['section']) + count($expectedresults['cm']);
Expand Down
14 changes: 7 additions & 7 deletions course/format/tests/stateupdates_test.php
Expand Up @@ -186,7 +186,7 @@ public function test_add_section(string $action, string $role, array $expected):
$this->assertEquals($action, $update->action);
$this->assertEquals('section', $update->name);
// Delete does not provide all fields.
if ($action == 'delete') {
if ($action == 'remove') {
$this->assertEquals($section->id, $update->fields->id);
} else {
$this->assertEquals($expected, $update->fields);
Expand All @@ -203,7 +203,7 @@ public function add_section_provider(): array {
return array_merge(
$this->add_section_provider_helper('put'),
$this->add_section_provider_helper('create'),
$this->add_section_provider_helper('delete'),
$this->add_section_provider_helper('remove'),
);
}

Expand All @@ -215,7 +215,7 @@ public function add_section_provider(): array {
*/
private function add_section_provider_helper(string $action): array {
// Delete does not depends on user permissions.
if ($action == 'delete') {
if ($action == 'remove') {
$studentsections = [0, 1, 2];
} else {
$studentsections = [0, 1];
Expand Down Expand Up @@ -247,7 +247,7 @@ private function add_section_provider_helper(string $action): array {
* @dataProvider add_cm_provider
* @covers ::add_cm_update
* @covers ::add_cm_create
* @covers ::add_cm_delete
* @covers ::add_cm_remove
*
* @param string $action the action name
* @param string $role the user role name
Expand Down Expand Up @@ -330,7 +330,7 @@ public function test_add_cm(string $action, string $role, array $expected): void
$this->assertEquals($action, $update->action);
$this->assertEquals('cm', $update->name);
// Delete does not provide all fields.
if ($action == 'delete') {
if ($action == 'remove') {
$this->assertEquals($cm->id, $update->fields->id);
} else {
$this->assertEquals($expected, $update->fields);
Expand All @@ -347,7 +347,7 @@ public function add_cm_provider(): array {
return array_merge(
$this->add_cm_provider_helper('put'),
$this->add_cm_provider_helper('create'),
$this->add_cm_provider_helper('delete'),
$this->add_cm_provider_helper('remove'),
);
}

Expand All @@ -359,7 +359,7 @@ public function add_cm_provider(): array {
*/
private function add_cm_provider_helper(string $action): array {
// Delete does not depends on user permissions.
if ($action == 'delete') {
if ($action == 'remove') {
$studentcms = [0, 1, 2, 3];
} else {
$studentcms = [0];
Expand Down
4 changes: 4 additions & 0 deletions course/format/upgrade.txt
Expand Up @@ -2,6 +2,10 @@ This files describes API changes for course formats

Overview of this plugin type at http://docs.moodle.org/dev/Course_formats

=== 4.0.3 ===
* New \core_courseformat\stateupdates methods add_section_remove() and add_cm_remove() have been added to replace
the incorrect methods add_section_delete() and add_cm_delete().

=== 4.0 ===
* New core_courseformat\base::uses_course_index() to define whether the course format uses course index or not.
* New core_courseformat\base::supports_components() to specify if the format is compatible with reactive components.
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Expand Up @@ -103,6 +103,9 @@
<testsuite name="core_course_testsuite">
<directory suffix="_test.php">course/tests</directory>
</testsuite>
<testsuite name="core_courseformat_testsuite">
<directory suffix="_test.php">course/format/tests</directory>
</testsuite>
<testsuite name="core_privacy_testsuite">
<directory suffix="_test.php">privacy/tests</directory>
</testsuite>
Expand Down

0 comments on commit 4525bad

Please sign in to comment.