[ 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 /** 18 * Events tests. 19 * 20 * @package core 21 * @category test 22 * @copyright 2016 Stephen Bourget 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 /** 30 * Unit tests for the dashboard events. 31 * 32 * @copyright 2016 Stephen Bourget 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class dashboard_events_testcase extends advanced_testcase { 36 37 /** @var user cobject */ 38 protected $user; 39 40 /** 41 * Setup often used objects for the following tests. 42 */ 43 protected function setup() { 44 global $USER; 45 46 $this->resetAfterTest(); 47 48 // The user we are going to test this on. 49 $this->setAdminUser(); 50 $this->user = $USER; 51 } 52 53 /** 54 * Test the dashboard viewed event. 55 * 56 * There is no external API for viewing the dashboard, so the unit test will simply 57 * create and trigger the event and ensure data is returned as expected. 58 */ 59 public function test_dashboard_viewed() { 60 61 $user = $this->user; 62 // Trigger an event: dashboard viewed. 63 $eventparams = array( 64 'context' => $context = context_user::instance($user->id) 65 ); 66 67 $event = \core\event\dashboard_viewed::create($eventparams); 68 // Trigger and capture the event. 69 $sink = $this->redirectEvents(); 70 $event->trigger(); 71 $events = $sink->get_events(); 72 $event = reset($events); 73 74 // Check that the event data is valid. 75 $this->assertInstanceOf('\core\event\dashboard_viewed', $event); 76 $this->assertEquals($user->id, $event->userid); 77 $this->assertDebuggingNotCalled(); 78 } 79 80 /** 81 * Test the dashboard reset event. 82 * 83 * We will reset the user dashboard to 84 * trigger the event and ensure data is returned as expected. 85 */ 86 public function test_dashboard_reset() { 87 global $CFG; 88 require_once($CFG->dirroot . '/my/lib.php'); 89 $user = $this->user; 90 $sink = $this->redirectEvents(); 91 92 // Reset the dashboard. 93 my_reset_page($user->id); 94 95 // Trigger and capture the event. 96 $events = $sink->get_events(); 97 $event = reset($events); 98 99 // Check that the event data is valid. 100 $this->assertInstanceOf('\core\event\dashboard_reset', $event); 101 $this->assertEquals($user->id, $event->userid); 102 $this->assertDebuggingNotCalled(); 103 } 104 105 /** 106 * Test the dashboards reset event. 107 * 108 * We will reset all user dashboards to 109 * trigger the event and ensure data is returned as expected. 110 */ 111 public function test_dashboards_reset() { 112 global $CFG, $USER; 113 require_once($CFG->dirroot . '/my/lib.php'); 114 115 $sink = $this->redirectEvents(); 116 117 // Reset all dashbaords. 118 my_reset_page_for_all_users(); 119 120 // Trigger and capture the event. 121 $events = $sink->get_events(); 122 $event = reset($events); 123 124 // Check that the event data is valid. 125 $this->assertInstanceOf('\core\event\dashboards_reset', $event); 126 $this->assertEquals($USER->id, $event->userid); 127 $this->assertDebuggingNotCalled(); 128 } 129 }
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 |