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_forum 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_forum 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_forum_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_forum'); 47 $record = ['assesstimefinish' => 100, 'assesstimestart' => 100, 'ratingtime' => 1, 'assessed' => 2, 'scale' => 1]; 48 list($course, $forum) = $this->create_course_and_module('forum', $record); 49 50 // Forum Discussions/posts/ratings. 51 $timestamp = 996699; 52 $diff = $this->get_diff(); 53 $record = new stdClass(); 54 $record->course = $course->id; 55 $record->userid = $USER->id; 56 $record->forum = $forum->id; 57 $record->timestart = $record->timeend = $record->timemodified = $timestamp; 58 $discussion = $gg->create_discussion($record); 59 60 $record = new stdClass(); 61 $record->discussion = $discussion->id; 62 $record->parent = $discussion->firstpost; 63 $record->userid = $USER->id; 64 $record->created = $record->modified = $timestamp; 65 $post = $gg->create_post($record); 66 67 // Time modified is changed internally. 68 $DB->set_field('forum_discussions', 'timemodified', $timestamp); 69 70 // Ratings. 71 $ratingoptions = new stdClass; 72 $ratingoptions->context = context_module::instance($forum->cmid); 73 $ratingoptions->ratingarea = 'post'; 74 $ratingoptions->component = 'mod_forum'; 75 $ratingoptions->itemid = $post->id; 76 $ratingoptions->scaleid = 2; 77 $ratingoptions->userid = $USER->id; 78 $rating = new rating($ratingoptions); 79 $rating->update_rating(2); 80 $rating = $DB->get_record('rating', ['itemid' => $post->id]); 81 82 // Do backup and restore. 83 $newcourseid = $this->backup_and_restore($course); 84 $newforum = $DB->get_record('forum', ['course' => $newcourseid]); 85 86 $this->assertFieldsNotRolledForward($forum, $newforum, ['timemodified']); 87 $props = ['assesstimefinish', 'assesstimestart']; 88 $this->assertFieldsRolledForward($forum, $newforum, $props); 89 90 $newdiscussion = $DB->get_record('forum_discussions', ['forum' => $newforum->id]); 91 $newposts = $DB->get_records('forum_posts', ['discussion' => $newdiscussion->id]); 92 $newcm = $DB->get_record('course_modules', ['course' => $newcourseid, 'instance' => $newforum->id]); 93 94 // Forum discussion time checks. 95 $this->assertEquals($timestamp + $diff, $newdiscussion->timestart); 96 $this->assertEquals($timestamp + $diff, $newdiscussion->timeend); 97 $this->assertEquals($timestamp, $newdiscussion->timemodified); 98 99 // Posts test. 100 foreach ($newposts as $post) { 101 $this->assertEquals($timestamp, $post->created); 102 $this->assertEquals($timestamp, $post->modified); 103 } 104 105 // Rating test. 106 $newrating = $DB->get_record('rating', ['contextid' => context_module::instance($newcm->id)->id]); 107 $this->assertEquals($rating->timecreated, $newrating->timecreated); 108 $this->assertEquals($rating->timemodified, $newrating->timemodified); 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body