Advertisement
sarjona

create_preset and iscore

Mar 1st, 2022
1,472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.30 KB | None | 0 0
  1. diff --git a/admin/presets/classes/helper.php b/admin/presets/classes/helper.php
  2. index 756bbed5ee1..1b7c53b2d05 100644
  3. --- a/admin/presets/classes/helper.php
  4. +++ b/admin/presets/classes/helper.php
  5. @@ -32,7 +32,7 @@ class helper {
  6.       *   - name. To define the preset name.
  7.       *   - comments. To change the comments field.
  8.       *   - author. To update the author field.
  9. -     *   - iscore. Whether the preset is a core preset or not.
  10. +     *   - iscore. Whether the preset is a core preset or not. TODO: Add more information about this field.
  11.       * @return int The identifier of the preset created.
  12.       */
  13.      public static function create_preset(array $data): int {
  14. @@ -42,6 +42,7 @@ class helper {
  15.          $comments = array_key_exists('comments', $data) ? $data['comments'] : '';
  16.          $author = array_key_exists('author', $data) ? $data['author'] : fullname($USER);
  17.          $iscore = array_key_exists('iscore', $data) ? $data['iscore'] : manager::NONCORE_PRESET;
  18. +        // TODO: Check iscore value is valid (only accepted NONCORE_PRESET, STARTER_PRESET or FULL_PRESET).
  19.  
  20.          $preset = [
  21.              'userid' => $USER->id,
  22. diff --git a/admin/presets/tests/helper_test.php b/admin/presets/tests/helper_test.php
  23. index 81fc4500a9a..d22bc890e0b 100644
  24. --- a/admin/presets/tests/helper_test.php
  25. +++ b/admin/presets/tests/helper_test.php
  26. @@ -36,7 +36,7 @@ class helper_test extends \advanced_testcase {
  27.       * @param string|null $name Preset name field.
  28.       * @param string|null $comments Preset comments field.
  29.       */
  30. -    public function test_create_preset(?string $name = null, ?string $comments = null): void {
  31. +    public function test_create_preset(?string $name = null, ?string $comments = null, ?int $iscore = null): void {
  32.          global $CFG, $DB, $USER;
  33.  
  34.          $this->resetAfterTest();
  35. @@ -48,6 +48,11 @@ class helper_test extends \advanced_testcase {
  36.          if (isset($comments)) {
  37.              $data['comments'] = $comments;
  38.          }
  39. +        if (isset($iscore)) {
  40. +            $data['iscore'] = $iscore;
  41. +        } else {
  42. +            $iscore = manager::NONCORE_PRESET;
  43. +        }
  44.  
  45.          // Create a preset.
  46.          $presetid = helper::create_preset($data);
  47. @@ -61,6 +66,11 @@ class helper_test extends \advanced_testcase {
  48.          $this->assertEquals($CFG->version, $preset->moodleversion);
  49.          $this->assertEquals($CFG->release, $preset->moodlerelease);
  50.          $this->assertEquals($CFG->wwwroot, $preset->site);
  51. +        if ($iscore !== manager::NONCORE_PRESET && $iscore !== manager::STARTER_PRESET && $iscore !== manager::FULL_PRESET) {
  52. +            // If defined valued for iscore is not valid, NONCORE_PRESET will be used for creating the preset.
  53. +            $iscore = manager::NONCORE_PRESET;
  54. +        }
  55. +        $this->assertEquals($iscore, $preset->iscore);
  56.  
  57.          // Check the preset is empty and hasn't settings or plugins.
  58.          $settings = $DB->get_records('adminpresets_it', ['adminpresetid' => $presetid]);
  59. @@ -89,6 +99,26 @@ class helper_test extends \advanced_testcase {
  60.                  'name' => 'Preset with a super-nice name',
  61.                  'comments' => 'This is a comment different from the previous one',
  62.              ],
  63. +            'Noncore preset. Name and comments not empty' => [
  64. +                'name' => 'Preset with a super-nice name',
  65. +                'comments' => 'This is a comment different from the previous one',
  66. +                'iscore' => manager::NONCORE_PRESET,
  67. +            ],
  68. +            'Starter preset. Name and comments not empty' => [
  69. +                'name' => 'Preset with a super-nice name',
  70. +                'comments' => 'This is a comment different from the previous one',
  71. +                'iscore' => manager::STARTER_PRESET,
  72. +            ],
  73. +            'Full preset. Name and comments not empty' => [
  74. +                'name' => 'Preset with a super-nice name',
  75. +                'comments' => 'This is a comment different from the previous one',
  76. +                'iscore' => manager::FULL_PRESET,
  77. +            ],
  78. +            'Invalid preset. Name and comments not empty' => [
  79. +                'name' => 'Preset with a super-nice name',
  80. +                'comments' => 'This is a comment different from the previous one',
  81. +                'iscore' => -1,
  82. +            ],
  83.          ];
  84.      }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement