1441 |
ariadna |
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 |
namespace core\event;
|
|
|
18 |
|
|
|
19 |
use core\tests\fake_plugins_test_trait;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Tests for the \core\event\manager class.
|
|
|
23 |
*
|
|
|
24 |
* @package core
|
|
|
25 |
* @category test
|
|
|
26 |
* @copyright 2024 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
* @covers \core\event\manager
|
|
|
29 |
*/
|
|
|
30 |
final class manager_test extends \advanced_testcase {
|
|
|
31 |
|
|
|
32 |
use fake_plugins_test_trait;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Test verifying that observers are not returned for deprecated plugin types.
|
|
|
36 |
*
|
|
|
37 |
* @runInSeparateProcess
|
|
|
38 |
* @return void
|
|
|
39 |
*/
|
|
|
40 |
public function test_get_all_observers_deprecated_plugintype(): void {
|
|
|
41 |
$this->resetAfterTest();
|
|
|
42 |
|
|
|
43 |
// Inject the fixture 'fake' plugin type into component sources, which includes a single 'fake_fullfeatured' plugin.
|
|
|
44 |
// This 'fake_fullfeatured' plugin is an available plugin at this stage (not yet deprecated).
|
|
|
45 |
$this->add_full_mocked_plugintype(
|
|
|
46 |
plugintype: 'fake',
|
|
|
47 |
path: 'lib/tests/fixtures/fakeplugins/fake',
|
|
|
48 |
);
|
|
|
49 |
|
|
|
50 |
$observers = array_filter(
|
|
|
51 |
\core\event\manager::get_all_observers()['\core\event\course_created'],
|
|
|
52 |
fn($observer) => $observer->plugintype == 'fake'
|
|
|
53 |
);
|
|
|
54 |
$this->assertEquals('\fake_fullfeatured\event_listener::event_handler', $observers[0]->callable);
|
|
|
55 |
|
|
|
56 |
// Now, deprecate the plugin type, verifying the event observer isn't visible.
|
|
|
57 |
// Note: \core\event\manager::$allobservers static cache must be reset first, to force a reload.
|
|
|
58 |
|
|
|
59 |
$this->deprecate_full_mocked_plugintype('fake');
|
|
|
60 |
$eventmanrc = new \ReflectionClass(\core\event\manager::class);
|
|
|
61 |
$eventmanrc->setStaticPropertyValue('allobservers', null);
|
|
|
62 |
|
|
|
63 |
$observers = array_filter(
|
|
|
64 |
\core\event\manager::get_all_observers()['\core\event\course_created'],
|
|
|
65 |
fn($observer) => $observer->plugintype == 'fake'
|
|
|
66 |
);
|
|
|
67 |
$this->assertEmpty($observers);
|
|
|
68 |
}
|
|
|
69 |
}
|