Differences Between: [Versions 311 and 403] [Versions 400 and 403] [Versions 401 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 * Events tests. 19 * 20 * @package mod_survey 21 * @copyright 2014 Rajesh Taneja <rajesh@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace mod_survey\event; 26 27 /** 28 * Events tests class. 29 * 30 * @package mod_survey 31 * @copyright 2014 Rajesh Taneja <rajesh@moodle.com> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class events_test extends \advanced_testcase { 35 36 /** 37 * Setup. 38 */ 39 public function setUp(): void { 40 $this->resetAfterTest(); 41 } 42 43 /** 44 * Test report downloaded event. 45 */ 46 public function test_report_downloaded() { 47 // There is no proper API to call to generate chapters for a book, so what we are 48 // doing here is simply making sure that the events returns the right information. 49 50 $course = $this->getDataGenerator()->create_course(); 51 $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id)); 52 53 $params = array( 54 'objectid' => $survey->id, 55 'context' => \context_module::instance($survey->cmid), 56 'courseid' => $course->id, 57 'other' => array('type' => 'xls') 58 ); 59 $event = \mod_survey\event\report_downloaded::create($params); 60 61 // Triggering and capturing the event. 62 $sink = $this->redirectEvents(); 63 $event->trigger(); 64 $events = $sink->get_events(); 65 $this->assertCount(1, $events); 66 $event = reset($events); 67 68 // Checking that the event contains the expected values. 69 $this->assertInstanceOf('\mod_survey\event\report_downloaded', $event); 70 $this->assertEquals(\context_module::instance($survey->cmid), $event->get_context()); 71 $this->assertEquals($survey->id, $event->objectid); 72 $this->assertEventContextNotUsed($event); 73 } 74 75 /** 76 * Test report viewed event. 77 */ 78 public function test_report_viewed() { 79 // There is no proper API to call to generate chapters for a book, so what we are 80 // doing here is simply making sure that the events returns the right information. 81 82 $course = $this->getDataGenerator()->create_course(); 83 $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id)); 84 85 $params = array( 86 'objectid' => $survey->id, 87 'context' => \context_module::instance($survey->cmid), 88 'courseid' => $course->id 89 ); 90 $event = \mod_survey\event\report_viewed::create($params); 91 92 // Triggering and capturing the event. 93 $sink = $this->redirectEvents(); 94 $event->trigger(); 95 $events = $sink->get_events(); 96 $this->assertCount(1, $events); 97 $event = reset($events); 98 99 // Checking that the event contains the expected values. 100 $this->assertInstanceOf('\mod_survey\event\report_viewed', $event); 101 $this->assertEquals(\context_module::instance($survey->cmid), $event->get_context()); 102 $this->assertEquals($survey->id, $event->objectid); 103 } 104 105 /** 106 * Test response submitted event. 107 */ 108 public function test_response_submitted() { 109 // There is no proper API to call to generate chapters for a book, so what we are 110 // doing here is simply making sure that the events returns the right information. 111 112 $course = $this->getDataGenerator()->create_course(); 113 $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id)); 114 115 $params = array( 116 'context' => \context_module::instance($survey->cmid), 117 'courseid' => $course->id, 118 'other' => array('surveyid' => $survey->id) 119 ); 120 $event = \mod_survey\event\response_submitted::create($params); 121 122 // Triggering and capturing the event. 123 $sink = $this->redirectEvents(); 124 $event->trigger(); 125 $events = $sink->get_events(); 126 $this->assertCount(1, $events); 127 $event = reset($events); 128 129 // Checking that the event contains the expected values. 130 $this->assertInstanceOf('\mod_survey\event\response_submitted', $event); 131 $this->assertEquals(\context_module::instance($survey->cmid), $event->get_context()); 132 $this->assertEquals($survey->id, $event->other['surveyid']); 133 $this->assertEventContextNotUsed($event); 134 } 135 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body