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