See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
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 * PHPUnit data generator tests 19 * 20 * @package mod_quiz 21 * @category phpunit 22 * @copyright 2012 Matt Petro 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 29 /** 30 * PHPUnit data generator testcase 31 * 32 * @package mod_quiz 33 * @category phpunit 34 * @copyright 2012 Matt Petro 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 * @covers \mod_quiz_generator 37 */ 38 class mod_quiz_generator_testcase extends advanced_testcase { 39 public function test_generator() { 40 global $DB, $SITE; 41 42 $this->resetAfterTest(true); 43 44 $this->assertEquals(0, $DB->count_records('quiz')); 45 46 /** @var \mod_quiz_generator $generator */ 47 $generator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); 48 $this->assertInstanceOf('mod_quiz_generator', $generator); 49 $this->assertEquals('quiz', $generator->get_modulename()); 50 51 $generator->create_instance(array('course'=>$SITE->id)); 52 $generator->create_instance(array('course'=>$SITE->id)); 53 $createtime = time(); 54 $quiz = $generator->create_instance(array('course' => $SITE->id, 'timecreated' => 0)); 55 $this->assertEquals(3, $DB->count_records('quiz')); 56 57 $cm = get_coursemodule_from_instance('quiz', $quiz->id); 58 $this->assertEquals($quiz->id, $cm->instance); 59 $this->assertEquals('quiz', $cm->modname); 60 $this->assertEquals($SITE->id, $cm->course); 61 62 $context = context_module::instance($cm->id); 63 $this->assertEquals($quiz->cmid, $context->instanceid); 64 65 $this->assertEqualsWithDelta($createtime, 66 $DB->get_field('quiz', 'timecreated', ['id' => $cm->instance]), 2); 67 } 68 69 public function test_generating_a_user_override() { 70 $this->resetAfterTest(true); 71 72 $generator = $this->getDataGenerator(); 73 $course = $generator->create_course(); 74 $user = $generator->create_user(); 75 $quiz = $generator->create_module('quiz', ['course' => $course->id]); 76 $generator->enrol_user($user->id, $course->id, 'student'); 77 78 /** @var \mod_quiz_generator $quizgenerator */ 79 $quizgenerator = $generator->get_plugin_generator('mod_quiz'); 80 $quizgenerator->create_override([ 81 'quiz' => $quiz->id, 82 'userid' => $user->id, 83 'timeclose' => strtotime('2022-10-20'), 84 ]); 85 86 // Check the corresponding calendar event now exists. 87 $events = calendar_get_events(strtotime('2022-01-01'), 88 strtotime('2022-12-31'), $user->id, false, $course->id); 89 $this->assertCount(1, $events); 90 $event = reset($events); 91 $this->assertEquals($user->id, $event->userid); 92 $this->assertEquals(0, $event->groupid); 93 $this->assertEquals(0, $event->courseid); 94 $this->assertEquals('quiz', $event->modulename); 95 $this->assertEquals($quiz->id, $event->instance); 96 $this->assertEquals('close', $event->eventtype); 97 $this->assertEquals(strtotime('2022-10-20'), $event->timestart); 98 } 99 100 public function test_generating_a_group_override() { 101 $this->resetAfterTest(true); 102 103 $generator = $this->getDataGenerator(); 104 $course = $generator->create_course(); 105 $quiz = $generator->create_module('quiz', ['course' => $course->id]); 106 $group = $generator->create_group(['courseid' => $course->id]); 107 108 /** @var \mod_quiz_generator $quizgenerator */ 109 $quizgenerator = $generator->get_plugin_generator('mod_quiz'); 110 $quizgenerator->create_override([ 111 'quiz' => $quiz->id, 112 'groupid' => $group->id, 113 'timeclose' => strtotime('2022-10-20'), 114 ]); 115 116 // Check the corresponding calendar event now exists. 117 $events = calendar_get_events(strtotime('2022-01-01'), 118 strtotime('2022-12-31'), false, $group->id, $course->id); 119 $this->assertCount(1, $events); 120 $event = reset($events); 121 $this->assertEquals(0, $event->userid); 122 $this->assertEquals($group->id, $event->groupid); 123 $this->assertEquals($course->id, $event->courseid); 124 $this->assertEquals('quiz', $event->modulename); 125 $this->assertEquals($quiz->id, $event->instance); 126 $this->assertEquals('close', $event->eventtype); 127 $this->assertEquals(strtotime('2022-10-20'), $event->timestart); 128 } 129 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body