Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | 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
 
1441 ariadna 34
final class events_test extends \advanced_testcase {
1 efrain 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;
1441 ariadna 46
        parent::setUp();
1 efrain 47
 
48
        $this->resetAfterTest();
49
 
50
        // Add a mnet host.
51
        $this->mnethost = new \stdClass();
52
        $this->mnethost->name = 'A mnet host';
53
        $this->mnethost->public_key = 'A random public key!';
54
        $this->mnethost->id = $DB->insert_record('mnet_host', $this->mnethost);
55
    }
56
 
57
    /**
58
     * Test the mnet access control created event.
59
     */
11 efrain 60
    public function test_mnet_access_control_created(): void {
1 efrain 61
        // Trigger and capture the event.
62
        $sink = $this->redirectEvents();
63
        mnet_update_sso_access_control('username', $this->mnethost->id, 'enabled');
64
        $events = $sink->get_events();
65
        $event = reset($events);
66
 
67
        // Check that the event data is valid.
68
        $this->assertInstanceOf('\core\event\mnet_access_control_created', $event);
69
        $this->assertEquals(\context_system::instance(), $event->get_context());
70
        $this->assertEventContextNotUsed($event);
71
        $url = new \moodle_url('/admin/mnet/access_control.php');
72
        $this->assertEquals($url, $event->get_url());
73
    }
74
 
75
    /**
76
     * Test the mnet access control updated event.
77
     */
11 efrain 78
    public function test_mnet_access_control_updated(): void {
1 efrain 79
        global $DB;
80
 
81
        // Create a mnet access control.
82
        $mnetaccesscontrol = new \stdClass();
83
        $mnetaccesscontrol->username = 'username';
84
        $mnetaccesscontrol->mnet_host_id = $this->mnethost->id;
85
        $mnetaccesscontrol->accessctrl = 'enabled';
86
        $mnetaccesscontrol->id = $DB->insert_record('mnet_sso_access_control', $mnetaccesscontrol);
87
 
88
        // Trigger and capture the event.
89
        $sink = $this->redirectEvents();
90
        mnet_update_sso_access_control('username', $this->mnethost->id, 'enabled');
91
        $events = $sink->get_events();
92
        $event = reset($events);
93
 
94
        // Check that the event data is valid.
95
        $this->assertInstanceOf('\core\event\mnet_access_control_updated', $event);
96
        $this->assertEquals(\context_system::instance(), $event->get_context());
97
        $this->assertEventContextNotUsed($event);
98
        $url = new \moodle_url('/admin/mnet/access_control.php');
99
        $this->assertEquals($url, $event->get_url());
100
    }
101
}