See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 402] [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 core_mnet 21 * @category test 22 * @copyright 2013 Mark Nelson <markn@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace core_mnet\event; 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 global $CFG; 31 32 require_once($CFG->dirroot . '/mnet/lib.php'); 33 34 class events_test extends \advanced_testcase { 35 36 /** @var stdClass the mnet host we are using to test */ 37 protected $mnethost; 38 39 /** 40 * Test set up. 41 * 42 * This is executed before running any test in this file. 43 */ 44 public function setUp(): void { 45 global $DB; 46 47 $this->resetAfterTest(); 48 49 // Add a mnet host. 50 $this->mnethost = new \stdClass(); 51 $this->mnethost->name = 'A mnet host'; 52 $this->mnethost->public_key = 'A random public key!'; 53 $this->mnethost->id = $DB->insert_record('mnet_host', $this->mnethost); 54 } 55 56 /** 57 * Test the mnet access control created event. 58 */ 59 public function test_mnet_access_control_created() { 60 // Trigger and capture the event. 61 $sink = $this->redirectEvents(); 62 mnet_update_sso_access_control('username', $this->mnethost->id, 'enabled'); 63 $events = $sink->get_events(); 64 $event = reset($events); 65 66 // Check that the event data is valid. 67 $this->assertInstanceOf('\core\event\mnet_access_control_created', $event); 68 $this->assertEquals(\context_system::instance(), $event->get_context()); 69 $expected = array(SITEID, 'admin/mnet', 'add', 'admin/mnet/access_control.php', 70 'SSO ACL: enabled user \'username\' from ' . $this->mnethost->name); 71 $this->assertEventLegacyLogData($expected, $event); 72 $this->assertEventContextNotUsed($event); 73 $url = new \moodle_url('/admin/mnet/access_control.php'); 74 $this->assertEquals($url, $event->get_url()); 75 } 76 77 /** 78 * Test the mnet access control updated event. 79 */ 80 public function test_mnet_access_control_updated() { 81 global $DB; 82 83 // Create a mnet access control. 84 $mnetaccesscontrol = new \stdClass(); 85 $mnetaccesscontrol->username = 'username'; 86 $mnetaccesscontrol->mnet_host_id = $this->mnethost->id; 87 $mnetaccesscontrol->accessctrl = 'enabled'; 88 $mnetaccesscontrol->id = $DB->insert_record('mnet_sso_access_control', $mnetaccesscontrol); 89 90 // Trigger and capture the event. 91 $sink = $this->redirectEvents(); 92 mnet_update_sso_access_control('username', $this->mnethost->id, 'enabled'); 93 $events = $sink->get_events(); 94 $event = reset($events); 95 96 // Check that the event data is valid. 97 $this->assertInstanceOf('\core\event\mnet_access_control_updated', $event); 98 $this->assertEquals(\context_system::instance(), $event->get_context()); 99 $expected = array(SITEID, 'admin/mnet', 'update', 'admin/mnet/access_control.php', 100 'SSO ACL: enabled user \'username\' from ' . $this->mnethost->name); 101 $this->assertEventLegacyLogData($expected, $event); 102 $this->assertEventContextNotUsed($event); 103 $url = new \moodle_url('/admin/mnet/access_control.php'); 104 $this->assertEquals($url, $event->get_url()); 105 } 106 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body