[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Unit tests for (some of) mod/feedback/lib.php. 18 * 19 * @package mod_feedback 20 * @copyright 2016 Stephen Bourget 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 defined('MOODLE_INTERNAL') || die(); 24 global $CFG; 25 require_once($CFG->dirroot . '/mod/feedback/lib.php'); 26 27 /** 28 * Unit tests for (some of) mod/feedback/lib.php. 29 * 30 * @copyright 2016 Stephen Bourget 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class mod_feedback_lib_testcase extends advanced_testcase { 34 35 /** 36 * Tests for mod_feedback_refresh_events. 37 */ 38 public function test_feedback_refresh_events() { 39 global $DB; 40 $this->resetAfterTest(); 41 $this->setAdminUser(); 42 43 $timeopen = time(); 44 $timeclose = time() + 86400; 45 46 $course = $this->getDataGenerator()->create_course(); 47 $generator = $this->getDataGenerator()->get_plugin_generator('mod_feedback'); 48 $params['course'] = $course->id; 49 $params['timeopen'] = $timeopen; 50 $params['timeclose'] = $timeclose; 51 $feedback = $generator->create_instance($params); 52 $cm = get_coursemodule_from_instance('feedback', $feedback->id); 53 $context = context_module::instance($cm->id); 54 55 // Normal case, with existing course. 56 $this->assertTrue(feedback_refresh_events($course->id)); 57 $eventparams = array('modulename' => 'feedback', 'instance' => $feedback->id, 'eventtype' => 'open'); 58 $openevent = $DB->get_record('event', $eventparams, '*', MUST_EXIST); 59 $this->assertEquals($openevent->timestart, $timeopen); 60 61 $eventparams = array('modulename' => 'feedback', 'instance' => $feedback->id, 'eventtype' => 'close'); 62 $closeevent = $DB->get_record('event', $eventparams, '*', MUST_EXIST); 63 $this->assertEquals($closeevent->timestart, $timeclose); 64 // In case the course ID is passed as a numeric string. 65 $this->assertTrue(feedback_refresh_events('' . $course->id)); 66 // Course ID not provided. 67 $this->assertTrue(feedback_refresh_events()); 68 $eventparams = array('modulename' => 'feedback'); 69 $events = $DB->get_records('event', $eventparams); 70 foreach ($events as $event) { 71 if ($event->modulename === 'feedback' && $event->instance === $feedback->id && $event->eventtype === 'open') { 72 $this->assertEquals($event->timestart, $timeopen); 73 } 74 if ($event->modulename === 'feedback' && $event->instance === $feedback->id && $event->eventtype === 'close') { 75 $this->assertEquals($event->timestart, $timeclose); 76 } 77 } 78 } 79 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |