See Release Notes
Long Term Support Release
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_glossary\backup; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 global $CFG; 22 require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php"); 23 require_once($CFG->dirroot . '/rating/lib.php'); 24 25 /** 26 * Restore date tests. 27 * 28 * @package mod_glossary 29 * @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com> 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class restore_date_test extends \restore_date_testcase { 33 34 /** 35 * Test restore dates. 36 */ 37 public function test_restore_dates() { 38 global $DB, $USER; 39 40 $gg = $this->getDataGenerator()->get_plugin_generator('mod_glossary'); 41 $record = ['assesstimefinish' => 100, 'assesstimestart' => 100, 'ratingtime' => 1, 'assessed' => 2, 'scale' => 1]; 42 list($course, $glossary) = $this->create_course_and_module('glossary', $record); 43 44 // Glossary entries. 45 $entry1 = $gg->create_content($glossary, array('approved' => 1)); 46 $gg->create_content($glossary, array('approved' => 0, 'userid' => $USER->id)); 47 $gg->create_content($glossary, array('approved' => 0, 'userid' => -1)); 48 $gg->create_content($glossary, array('approved' => 1)); 49 $timestamp = 10000; 50 $DB->set_field('glossary_entries', 'timecreated', $timestamp); 51 $DB->set_field('glossary_entries', 'timemodified', $timestamp); 52 $ratingoptions = new \stdClass; 53 $ratingoptions->context = \context_module::instance($glossary->cmid); 54 $ratingoptions->ratingarea = 'entry'; 55 $ratingoptions->component = 'mod_glossary'; 56 $ratingoptions->itemid = $entry1->id; 57 $ratingoptions->scaleid = 2; 58 $ratingoptions->userid = $USER->id; 59 $rating = new \rating($ratingoptions); 60 $rating->update_rating(2); 61 $rating = $DB->get_record('rating', ['itemid' => $entry1->id]); 62 63 // Do backup and restore. 64 $newcourseid = $this->backup_and_restore($course); 65 $newglossary = $DB->get_record('glossary', ['course' => $newcourseid]); 66 67 $this->assertFieldsNotRolledForward($glossary, $newglossary, ['timecreated', 'timemodified']); 68 $props = ['assesstimefinish', 'assesstimestart']; 69 $this->assertFieldsRolledForward($glossary, $newglossary, $props); 70 71 $newentries = $DB->get_records('glossary_entries', ['glossaryid' => $newglossary->id]); 72 $newcm = $DB->get_record('course_modules', ['course' => $newcourseid, 'instance' => $newglossary->id]); 73 74 // Entries test. 75 foreach ($newentries as $entry) { 76 $this->assertEquals($timestamp, $entry->timecreated); 77 $this->assertEquals($timestamp, $entry->timemodified); 78 } 79 80 // Rating test. 81 $newrating = $DB->get_record('rating', ['contextid' => \context_module::instance($newcm->id)->id]); 82 $this->assertEquals($rating->timecreated, $newrating->timecreated); 83 $this->assertEquals($rating->timemodified, $newrating->timemodified); 84 } 85 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body