Search moodle.org's
Developer Documentation

See Release Notes

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