Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/admin/presets/classes/helper.php b/admin/presets/classes/helper.php
- index 756bbed5ee1..1b7c53b2d05 100644
- --- a/admin/presets/classes/helper.php
- +++ b/admin/presets/classes/helper.php
- @@ -32,7 +32,7 @@ class helper {
- * - name. To define the preset name.
- * - comments. To change the comments field.
- * - author. To update the author field.
- - * - iscore. Whether the preset is a core preset or not.
- + * - iscore. Whether the preset is a core preset or not. TODO: Add more information about this field.
- * @return int The identifier of the preset created.
- */
- public static function create_preset(array $data): int {
- @@ -42,6 +42,7 @@ class helper {
- $comments = array_key_exists('comments', $data) ? $data['comments'] : '';
- $author = array_key_exists('author', $data) ? $data['author'] : fullname($USER);
- $iscore = array_key_exists('iscore', $data) ? $data['iscore'] : manager::NONCORE_PRESET;
- + // TODO: Check iscore value is valid (only accepted NONCORE_PRESET, STARTER_PRESET or FULL_PRESET).
- $preset = [
- 'userid' => $USER->id,
- diff --git a/admin/presets/tests/helper_test.php b/admin/presets/tests/helper_test.php
- index 81fc4500a9a..d22bc890e0b 100644
- --- a/admin/presets/tests/helper_test.php
- +++ b/admin/presets/tests/helper_test.php
- @@ -36,7 +36,7 @@ class helper_test extends \advanced_testcase {
- * @param string|null $name Preset name field.
- * @param string|null $comments Preset comments field.
- */
- - public function test_create_preset(?string $name = null, ?string $comments = null): void {
- + public function test_create_preset(?string $name = null, ?string $comments = null, ?int $iscore = null): void {
- global $CFG, $DB, $USER;
- $this->resetAfterTest();
- @@ -48,6 +48,11 @@ class helper_test extends \advanced_testcase {
- if (isset($comments)) {
- $data['comments'] = $comments;
- }
- + if (isset($iscore)) {
- + $data['iscore'] = $iscore;
- + } else {
- + $iscore = manager::NONCORE_PRESET;
- + }
- // Create a preset.
- $presetid = helper::create_preset($data);
- @@ -61,6 +66,11 @@ class helper_test extends \advanced_testcase {
- $this->assertEquals($CFG->version, $preset->moodleversion);
- $this->assertEquals($CFG->release, $preset->moodlerelease);
- $this->assertEquals($CFG->wwwroot, $preset->site);
- + if ($iscore !== manager::NONCORE_PRESET && $iscore !== manager::STARTER_PRESET && $iscore !== manager::FULL_PRESET) {
- + // If defined valued for iscore is not valid, NONCORE_PRESET will be used for creating the preset.
- + $iscore = manager::NONCORE_PRESET;
- + }
- + $this->assertEquals($iscore, $preset->iscore);
- // Check the preset is empty and hasn't settings or plugins.
- $settings = $DB->get_records('adminpresets_it', ['adminpresetid' => $presetid]);
- @@ -89,6 +99,26 @@ class helper_test extends \advanced_testcase {
- 'name' => 'Preset with a super-nice name',
- 'comments' => 'This is a comment different from the previous one',
- ],
- + 'Noncore preset. Name and comments not empty' => [
- + 'name' => 'Preset with a super-nice name',
- + 'comments' => 'This is a comment different from the previous one',
- + 'iscore' => manager::NONCORE_PRESET,
- + ],
- + 'Starter preset. Name and comments not empty' => [
- + 'name' => 'Preset with a super-nice name',
- + 'comments' => 'This is a comment different from the previous one',
- + 'iscore' => manager::STARTER_PRESET,
- + ],
- + 'Full preset. Name and comments not empty' => [
- + 'name' => 'Preset with a super-nice name',
- + 'comments' => 'This is a comment different from the previous one',
- + 'iscore' => manager::FULL_PRESET,
- + ],
- + 'Invalid preset. Name and comments not empty' => [
- + 'name' => 'Preset with a super-nice name',
- + 'comments' => 'This is a comment different from the previous one',
- + 'iscore' => -1,
- + ],
- ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement