Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Fixtures for advanced_testcase tests.
19
 *
20
 * @package   core
21
 * @category  event
22
 * @copyright 2024 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
23
 * @license   https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace core\event;
27
 
28
defined('MOODLE_INTERNAL') || die();
29
 
30
/**
31
 * Event to test that \advanced_testcase::assertEventContextNotUsed() passes ok when no context is used.
32
 */
33
class context_used_in_event_correct extends \core\event\base {
34
 
35
    protected function init() {
36
        $this->data['crud'] = 'u';
37
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
38
        $this->context = \context_system::instance();
39
    }
40
 
41
    public function get_url() {
42
        return new \moodle_url('/somepath/somefile.php'); // No context used.
43
    }
44
 
45
    public function get_description() {
46
        return 'Description'; // No context used.
47
    }
48
}
49
 
50
/**
51
 * Event to test that \advanced_testcase::assertEventContextNotUsed() detects context usage on get_url().
52
 */
53
class context_used_in_event_get_url extends \core\event\base {
54
 
55
    protected function init() {
56
        $this->data['crud'] = 'u';
57
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
58
        $this->context = \context_system::instance();
59
    }
60
 
61
    public function get_url() {
62
        return new \moodle_url('/somepath/somefile.php', ['id' => $this->context->instanceid]); // Causes a PHP Warning.
63
    }
64
}
65
 
66
/**
67
 * Event to test that \advanced_testcase::assertEventContextNotUsed() detects context usage on get_description().
68
 */
69
class context_used_in_event_get_description extends \core\event\base {
70
 
71
    protected function init() {
72
        $this->data['crud'] = 'u';
73
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
74
        $this->context = \context_system::instance();
75
    }
76
 
77
    public function get_description() {
78
        return $this->context->instanceid . " Description"; // Causes a PHP Warning.
79
    }
80
}