Proyectos de Subversion Moodle

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
        $this->assertEventContextNotUsed($event);
70
        $url = new \moodle_url('/admin/mnet/access_control.php');
71
        $this->assertEquals($url, $event->get_url());
72
    }
73
 
74
    /**
75
     * Test the mnet access control updated event.
76
     */
77
    public function test_mnet_access_control_updated() {
78
        global $DB;
79
 
80
        // Create a mnet access control.
81
        $mnetaccesscontrol = new \stdClass();
82
        $mnetaccesscontrol->username = 'username';
83
        $mnetaccesscontrol->mnet_host_id = $this->mnethost->id;
84
        $mnetaccesscontrol->accessctrl = 'enabled';
85
        $mnetaccesscontrol->id = $DB->insert_record('mnet_sso_access_control', $mnetaccesscontrol);
86
 
87
        // Trigger and capture the event.
88
        $sink = $this->redirectEvents();
89
        mnet_update_sso_access_control('username', $this->mnethost->id, 'enabled');
90
        $events = $sink->get_events();
91
        $event = reset($events);
92
 
93
        // Check that the event data is valid.
94
        $this->assertInstanceOf('\core\event\mnet_access_control_updated', $event);
95
        $this->assertEquals(\context_system::instance(), $event->get_context());
96
        $this->assertEventContextNotUsed($event);
97
        $url = new \moodle_url('/admin/mnet/access_control.php');
98
        $this->assertEquals($url, $event->get_url());
99
    }
100
}