Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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  /**
  18   * Restore override tests.
  19   *
  20   * @package    mod_lesson
  21   * @author   2019 Nathan Nguyen <nathannguyen@catalyst-au.net>
  22   * @copyright Catalyst IT
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
  30  /**
  31   * Restore override tests.
  32   *
  33   * @package    mod_lesson
  34   * @author   2019 Nathan Nguyen <nathannguyen@catalyst-au.net>
  35   * @copyright Catalyst IT
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class mod_lesson_restore_override_testcase extends restore_date_testcase {
  39  
  40      /**
  41       * Test restore overrides.
  42       */
  43      public function test_restore_overrides() {
  44          global $DB, $USER;
  45          $this->resetAfterTest();
  46  
  47          $course = $this->getDataGenerator()->create_course();
  48          $lessongen = $this->getDataGenerator()->get_plugin_generator('mod_lesson');
  49          $lesson = $lessongen->create_instance(['course' => $course->id]);
  50  
  51          $group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
  52          $group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
  53  
  54          $now = 100;
  55          $groupoverride1 = (object)[
  56              'lessonid' => $lesson->id,
  57              'groupid' => $group1->id,
  58              'available' => $now,
  59              'deadline' => $now + 20
  60          ];
  61          $DB->insert_record('lesson_overrides', $groupoverride1);
  62  
  63          $groupoverride2 = (object)[
  64              'lessonid' => $lesson->id,
  65              'groupid' => $group2->id,
  66              'available' => $now,
  67              'deadline' => $now + 40
  68          ];
  69          $DB->insert_record('lesson_overrides', $groupoverride2);
  70  
  71          // Current quiz overrides.
  72          $overrides = $DB->get_records('lesson_overrides', ['lessonid' => $lesson->id]);
  73          $this->assertEquals(2, count($overrides));
  74  
  75          // User override.
  76          $useroverride = (object)[
  77              'lessonid' => $lesson->id,
  78              'userid' => $USER->id,
  79              'sortorder' => 1,
  80              'available' => 100,
  81              'deadline' => 200
  82          ];
  83          $DB->insert_record('lesson_overrides', $useroverride);
  84  
  85          // Current quiz overrides.
  86          $overrides = $DB->get_records('lesson_overrides', ['lessonid' => $lesson->id]);
  87          $this->assertEquals(3, count($overrides));
  88  
  89          // Back up and restore including group info and user info.
  90          set_config('backup_general_groups', 1, 'backup');
  91          $newcourseid = $this->backup_and_restore($course);
  92          $newquiz = $DB->get_record('lesson', ['course' => $newcourseid]);
  93          $overrides = $DB->get_records('lesson_overrides', ['lessonid' => $newquiz->id]);
  94          // 2 groups overrides and 1 user override.
  95          $this->assertEquals(3, count($overrides));
  96  
  97          // Back up and restore with user info and without group info.
  98          set_config('backup_general_groups', 0, 'backup');
  99          $newcourseid = $this->backup_and_restore($course);
 100          $newquiz = $DB->get_record('lesson', ['course' => $newcourseid]);
 101          $overrides = $DB->get_records('lesson_overrides', ['lessonid' => $newquiz->id]);
 102          // 1 user override.
 103          $this->assertEquals(1, count($overrides));
 104      }
 105  }