Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is 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  namespace mod_workshop\backup;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  global $CFG;
  22  require_once($CFG->dirroot . '/mod/workshop/locallib.php');
  23  require_once($CFG->dirroot . '/mod/workshop/lib.php');
  24  require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php");
  25  require_once($CFG->dirroot . "/mod/workshop/tests/fixtures/testable.php");
  26  
  27  /**
  28   * Restore date tests.
  29   *
  30   * @package    mod_workshop
  31   * @copyright  2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class restore_date_test extends \restore_date_testcase {
  35  
  36      /**
  37       * Test restore dates.
  38       */
  39      public function test_restore_dates() {
  40          global $DB, $USER;
  41  
  42          // Create workshop data.
  43          $record = ['submissionstart' => 100, 'submissionend' => 100, 'assessmentend' => 100, 'assessmentstart' => 100];
  44          list($course, $workshop) = $this->create_course_and_module('workshop', $record);
  45          $workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
  46          $subid = $workshopgenerator->create_submission($workshop->id, $USER->id);
  47          $exsubid = $workshopgenerator->create_submission($workshop->id, $USER->id, ['example' => 1]);
  48          $workshopgenerator->create_assessment($subid, $USER->id);
  49          $workshopgenerator->create_assessment($exsubid, $USER->id, ['weight' => 0]);
  50          $workshopgenerator->create_assessment($exsubid, $USER->id);
  51  
  52          // Set time fields to a constant for easy validation.
  53          $timestamp = 100;
  54          $DB->set_field('workshop_submissions', 'timecreated', $timestamp);
  55          $DB->set_field('workshop_submissions', 'timemodified', $timestamp);
  56          $DB->set_field('workshop_assessments', 'timecreated', $timestamp);
  57          $DB->set_field('workshop_assessments', 'timemodified', $timestamp);
  58  
  59          // Do backup and restore.
  60          $newcourseid = $this->backup_and_restore($course);
  61          $newworkshop = $DB->get_record('workshop', ['course' => $newcourseid]);
  62  
  63          $this->assertFieldsNotRolledForward($workshop, $newworkshop, ['timemodified']);
  64          $props = ['submissionstart', 'submissionend', 'assessmentend', 'assessmentstart'];
  65          $this->assertFieldsRolledForward($workshop, $newworkshop, $props);
  66  
  67          $submissions = $DB->get_records('workshop_submissions', ['workshopid' => $newworkshop->id]);
  68          // Workshop submission time checks.
  69          foreach ($submissions as $submission) {
  70              $this->assertEquals($timestamp, $submission->timecreated);
  71              $this->assertEquals($timestamp, $submission->timemodified);
  72              $assessments = $DB->get_records('workshop_assessments', ['submissionid' => $submission->id]);
  73              // Workshop assessment time checks.
  74              foreach ($assessments as $assessment) {
  75                  $this->assertEquals($timestamp, $assessment->timecreated);
  76                  $this->assertEquals($timestamp, $assessment->timemodified);
  77              }
  78          }
  79      }
  80  }