2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 use core_plugin_manager
;
20 use testable_core_plugin_manager
;
21 use testable_plugininfo_base
;
24 * Unit tests for plugin manager class.
28 * @copyright 2013 Petr Skoda {@link http://skodak.org}
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 * @covers \core_plugin_manager
32 final class plugin_manager_test
extends \advanced_testcase
{
33 public static function setUpBeforeClass(): void
{
35 require_once($CFG->dirroot
. '/lib/tests/fixtures/testable_plugin_manager.php');
36 require_once($CFG->dirroot
. '/lib/tests/fixtures/testable_plugininfo_base.php');
37 parent
::setUpBeforeClass();
40 public function tearDown(): void
{
41 // The caches of the testable singleton must be reset explicitly. It is
42 // safer to kill the whole testable singleton at the end of every test.
43 testable_core_plugin_manager
::reset_caches();
47 public function test_instance(): void
{
48 $pluginman1 = core_plugin_manager
::instance();
49 $this->assertInstanceOf('core_plugin_manager', $pluginman1);
50 $pluginman2 = core_plugin_manager
::instance();
51 $this->assertSame($pluginman1, $pluginman2);
52 $pluginman3 = testable_core_plugin_manager
::instance();
53 $this->assertInstanceOf('core_plugin_manager', $pluginman3);
54 $this->assertInstanceOf('testable_core_plugin_manager', $pluginman3);
55 $pluginman4 = testable_core_plugin_manager
::instance();
56 $this->assertSame($pluginman3, $pluginman4);
57 $this->assertNotSame($pluginman1, $pluginman3);
60 public function test_reset_caches(): void
{
61 // Make sure there are no warnings or errors.
62 core_plugin_manager
::reset_caches();
63 testable_core_plugin_manager
::reset_caches();
67 * Make sure that the tearDown() really kills the singleton after this test.
69 public function test_teardown_works_precheck(): void
{
70 $pluginman = testable_core_plugin_manager
::instance();
71 $pluginfo = testable_plugininfo_base
::fake_plugin_instance(
76 'testable_plugininfo_base',
79 $pluginman->inject_testable_plugininfo('fake', 'one', $pluginfo);
81 $this->assertInstanceOf('\core\plugininfo\base', $pluginman->get_plugin_info('fake_one'));
82 $this->assertNull($pluginman->get_plugin_info('fake_two'));
85 public function test_teardown_works_postcheck(): void
{
86 $pluginman = testable_core_plugin_manager
::instance();
87 $this->assertNull($pluginman->get_plugin_info('fake_one'));
88 $this->assertNull($pluginman->get_plugin_info('fake_two'));
91 public function test_get_plugin_types(): void
{
92 // Make sure there are no warnings or errors.
93 $types = core_plugin_manager
::instance()->get_plugin_types();
94 $this->assertIsArray($types);
95 foreach ($types as $type => $fulldir) {
96 $this->assertFileExists($fulldir);
100 public function test_get_installed_plugins(): void
{
101 $types = core_plugin_manager
::instance()->get_plugin_types();
102 foreach ($types as $type => $fulldir) {
103 $installed = core_plugin_manager
::instance()->get_installed_plugins($type);
104 foreach ($installed as $plugin => $version) {
105 $this->assertMatchesRegularExpression('/^[a-z]+[a-z0-9_]*$/', $plugin);
107 is_numeric($version),
108 'All plugins should have a version, plugin ' . $type . '_' . $plugin . ' does not have version info.'
114 public function test_get_enabled_plugins(): void
{
115 $types = core_plugin_manager
::instance()->get_plugin_types();
116 foreach ($types as $type => $fulldir) {
117 $enabled = core_plugin_manager
::instance()->get_enabled_plugins($type);
118 if (is_array($enabled)) {
119 foreach ($enabled as $key => $val) {
120 $this->assertMatchesRegularExpression('/^[a-z]+[a-z0-9_]*$/', $key);
121 $this->assertSame($key, $val);
124 $this->assertNull($enabled);
129 public function test_get_present_plugins(): void
{
130 $types = core_plugin_manager
::instance()->get_plugin_types();
131 foreach ($types as $type => $fulldir) {
132 $present = core_plugin_manager
::instance()->get_present_plugins($type);
133 if (is_array($present)) {
134 foreach ($present as $plugin => $version) {
135 $this->assertMatchesRegularExpression(
136 '/^[a-z]+[a-z0-9_]*$/',
138 'All plugins are supposed to have version.php file.'
140 $this->assertIsObject($version);
142 is_numeric($version->version
),
143 'All plugins should have a version, plugin ' . $type . '_' . $plugin . ' does not have version info.'
147 // No plugins of this type exist.
148 $this->assertNull($present);
153 public function test_get_plugins(): void
{
154 $plugininfos1 = core_plugin_manager
::instance()->get_plugins();
155 foreach ($plugininfos1 as $type => $infos) {
156 foreach ($infos as $name => $info) {
157 $this->assertInstanceOf('\core\plugininfo\base', $info);
161 // The testable variant of the manager holds its own tree of the
162 // plugininfo objects.
163 $plugininfos2 = testable_core_plugin_manager
::instance()->get_plugins();
164 $this->assertNotSame($plugininfos1['mod']['forum'], $plugininfos2['mod']['forum']);
166 // Singletons of each manager class share the same tree.
167 $plugininfos3 = core_plugin_manager
::instance()->get_plugins();
168 $this->assertSame($plugininfos1['mod']['forum'], $plugininfos3['mod']['forum']);
169 $plugininfos4 = testable_core_plugin_manager
::instance()->get_plugins();
170 $this->assertSame($plugininfos2['mod']['forum'], $plugininfos4['mod']['forum']);
173 public function test_plugininfo_back_reference_to_the_plugin_manager(): void
{
174 $plugman1 = core_plugin_manager
::instance();
175 $plugman2 = testable_core_plugin_manager
::instance();
177 foreach ($plugman1->get_plugins() as $type => $infos) {
178 foreach ($infos as $info) {
179 $this->assertSame($info->pluginman
, $plugman1);
183 foreach ($plugman2->get_plugins() as $type => $infos) {
184 foreach ($infos as $info) {
185 $this->assertSame($info->pluginman
, $plugman2);
190 public function test_get_plugins_of_type(): void
{
191 $plugininfos = core_plugin_manager
::instance()->get_plugins();
192 foreach ($plugininfos as $type => $infos) {
193 $this->assertSame($infos, core_plugin_manager
::instance()->get_plugins_of_type($type));
197 public function test_get_subplugins_of_plugin(): void
{
200 // Any standard plugin with subplugins is suitable.
201 $this->assertFileExists("$CFG->dirroot/lib/editor/tiny", 'TinyMCE is not present.');
203 $subplugins = core_plugin_manager
::instance()->get_subplugins_of_plugin('editor_tiny');
204 foreach ($subplugins as $component => $info) {
205 $this->assertInstanceOf('\core\plugininfo\base', $info);
209 public function test_get_subplugins(): void
{
210 // Tested already indirectly from test_get_subplugins_of_plugin().
211 $subplugins = core_plugin_manager
::instance()->get_subplugins();
212 $this->assertIsArray($subplugins);
215 public function test_get_parent_of_subplugin(): void
{
218 // Any standard plugin with subplugins is suitable.
219 $this->assertFileExists("$CFG->dirroot/lib/editor/tiny", 'TinyMCE is not present.');
221 $parent = core_plugin_manager
::instance()->get_parent_of_subplugin('tiny');
222 $this->assertSame('editor_tiny', $parent);
225 public function test_plugin_name(): void
{
228 // Any standard plugin is suitable.
229 $this->assertFileExists("$CFG->dirroot/lib/editor/tiny", 'TinyMCE is not present.');
231 $name = core_plugin_manager
::instance()->plugin_name('editor_tiny');
232 $this->assertSame(get_string('pluginname', 'editor_tiny'), $name);
235 public function test_plugintype_name(): void
{
236 $name = core_plugin_manager
::instance()->plugintype_name('editor');
237 $this->assertSame(get_string('type_editor', 'core_plugin'), $name);
240 public function test_plugintype_name_plural(): void
{
241 $name = core_plugin_manager
::instance()->plugintype_name_plural('editor');
242 $this->assertSame(get_string('type_editor_plural', 'core_plugin'), $name);
245 public function test_get_plugin_info(): void
{
248 // Any standard plugin is suitable.
249 $this->assertFileExists("$CFG->dirroot/lib/editor/tiny", 'TinyMCE is not present.');
251 $info = core_plugin_manager
::instance()->get_plugin_info('editor_tiny');
252 $this->assertInstanceOf('\core\plugininfo\editor', $info);
255 public function test_can_uninstall_plugin(): void
{
258 // Any standard plugin that is required by some other standard plugin is ok.
259 $this->assertFileExists("$CFG->dirroot/report/competency", 'competency report is not present');
260 $this->assertFileExists("$CFG->dirroot/$CFG->admin/tool/lp", 'tool lp is not present');
262 $this->assertFalse(core_plugin_manager
::instance()->can_uninstall_plugin('tool_lp'));
263 $this->assertTrue(core_plugin_manager
::instance()->can_uninstall_plugin('report_competency'));
266 public function test_plugin_states(): void
{
268 $this->resetAfterTest();
270 // Any standard plugin that is ok.
271 $this->assertFileExists("$CFG->dirroot/mod/assign", 'assign module is not present');
272 $this->assertFileExists("$CFG->dirroot/mod/forum", 'forum module is not present');
273 $this->assertFileExists("$CFG->dirroot/$CFG->admin/tool/phpunit", 'phpunit tool is not present');
274 $this->assertFileDoesNotExist("$CFG->dirroot/mod/xxxxxxx");
275 $this->assertFileDoesNotExist("$CFG->dirroot/enrol/autorize");
277 // Ready for upgrade.
278 $assignversion = get_config('mod_assign', 'version');
279 set_config('version', $assignversion - 1, 'mod_assign');
280 // Downgrade problem.
281 $forumversion = get_config('mod_forum', 'version');
282 set_config('version', $forumversion +
1, 'mod_forum');
283 // Not installed yet.
284 unset_config('version', 'tool_phpunit');
285 // Missing already installed.
286 set_config('version', 2013091300, 'mod_xxxxxxx');
288 set_config('version', 2013091300, 'enrol_authorize');
290 core_plugin_manager
::reset_caches();
292 $plugininfos = core_plugin_manager
::instance()->get_plugins();
293 foreach ($plugininfos as $type => $infos) {
294 /** @var \core\plugininfo\base $info */
295 foreach ($infos as $info) {
296 if ($info->component
=== 'mod_assign') {
298 core_plugin_manager
::PLUGIN_STATUS_UPGRADE
,
300 'Invalid ' . $info->component
. ' state'
302 } else if ($info->component
=== 'mod_forum') {
304 core_plugin_manager
::PLUGIN_STATUS_DOWNGRADE
,
306 'Invalid ' . $info->component
. ' state'
308 } else if ($info->component
=== 'tool_phpunit') {
310 core_plugin_manager
::PLUGIN_STATUS_NEW
,
312 'Invalid ' . $info->component
. ' state'
314 } else if ($info->component
=== 'mod_xxxxxxx') {
316 core_plugin_manager
::PLUGIN_STATUS_MISSING
,
318 'Invalid ' . $info->component
. ' state'
320 } else if ($info->component
=== 'enrol_authorize') {
322 core_plugin_manager
::PLUGIN_STATUS_DELETE
,
324 'Invalid ' . $info->component
. ' state'
328 core_plugin_manager
::PLUGIN_STATUS_UPTODATE
,
330 'Invalid ' . $info->component
. ' state'
337 public function test_plugin_available_updates(): void
{
338 $pluginman = testable_core_plugin_manager
::instance();
340 $foobar = testable_plugininfo_base
::fake_plugin_instance(
345 'testable_plugininfo_base',
348 $foobar->versiondb
= 2015092900;
349 $foobar->versiondisk
= 2015092900;
350 $pluginman->inject_testable_plugininfo('foo', 'bar', $foobar);
353 foreach ($pluginman->get_plugins() as $type => $infos) {
354 foreach ($infos as $name => $plugin) {
355 $updates = $plugin->available_updates();
356 if ($plugin->component
!= 'foo_bar') {
357 $this->assertNull($updates);
359 $this->assertTrue(is_array($updates));
360 $this->assertEquals(3, count($updates));
361 foreach ($updates as $update) {
363 $this->assertInstanceOf('\core\update\info', $update);
364 $this->assertEquals($update->component
, $plugin->component
);
365 $this->assertTrue($update->version
> $plugin->versiondb
);
370 $this->assertTrue($washere);
373 public function test_some_plugins_updatable_none(): void
{
374 $pluginman = testable_core_plugin_manager
::instance();
375 $this->assertFalse($pluginman->some_plugins_updatable());
378 public function test_some_plugins_updatable_some(): void
{
379 $pluginman = testable_core_plugin_manager
::instance();
381 $foobar = testable_plugininfo_base
::fake_plugin_instance(
386 'testable_plugininfo_base',
389 $foobar->versiondb
= 2015092900;
390 $foobar->versiondisk
= 2015092900;
391 $pluginman->inject_testable_plugininfo('foo', 'bar', $foobar);
393 $this->assertTrue($pluginman->some_plugins_updatable());
396 public function test_available_updates(): void
{
397 $pluginman = testable_core_plugin_manager
::instance();
399 $foobar = testable_plugininfo_base
::fake_plugin_instance(
404 'testable_plugininfo_base',
407 $foobar->versiondb
= 2015092900;
408 $foobar->versiondisk
= 2015092900;
409 $pluginman->inject_testable_plugininfo('foo', 'bar', $foobar);
411 $updates = $pluginman->available_updates();
413 $this->assertTrue(is_array($updates));
414 $this->assertEquals(1, count($updates));
415 $update = $updates['foo_bar'];
416 $this->assertInstanceOf('\core\update\remote_info', $update);
417 $this->assertEquals('foo_bar', $update->component
);
418 $this->assertEquals(2015100400, $update->version
->version
);
421 public function test_get_remote_plugin_info(): void
{
422 $pluginman = testable_core_plugin_manager
::instance();
424 $this->assertFalse($pluginman->get_remote_plugin_info('not_exists', ANY_VERSION
, false));
426 $info = $pluginman->get_remote_plugin_info('foo_bar', 2015093000, true);
427 $this->assertEquals(2015093000, $info->version
->version
);
429 $info = $pluginman->get_remote_plugin_info('foo_bar', 2015093000, false);
430 $this->assertEquals(2015100400, $info->version
->version
);
434 * The combination of ANY_VERSION + $exactmatch is illegal.
436 public function test_get_remote_plugin_info_exception(): void
{
437 $pluginman = testable_core_plugin_manager
::instance();
438 $this->expectException(\moodle_exception
::class);
439 $pluginman->get_remote_plugin_info('any_thing', ANY_VERSION
, true);
442 public function test_is_remote_plugin_available(): void
{
443 $pluginman = testable_core_plugin_manager
::instance();
445 $this->assertFalse($pluginman->is_remote_plugin_available('not_exists', ANY_VERSION
, false));
446 $this->assertTrue($pluginman->is_remote_plugin_available('foo_bar', 2013131313, false));
447 $this->assertFalse($pluginman->is_remote_plugin_available('foo_bar', 2013131313, true));
450 public function test_resolve_requirements(): void
{
451 $pluginman = testable_core_plugin_manager
::instance();
453 // Prepare a fake pluginfo instance.
454 $pluginfo = testable_plugininfo_base
::fake_plugin_instance(
459 'testable_plugininfo_base',
462 $pluginfo->versiondisk
= 2015060600;
464 // Test no $plugin->requires is specified in version.php.
465 $pluginfo->versionrequires
= null;
466 $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015100100));
467 $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29);
468 $this->assertEquals(2015100100, $reqs['core']->hasver
);
469 $this->assertEquals(ANY_VERSION
, $reqs['core']->reqver
);
470 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK
, $reqs['core']->status
);
472 // Test plugin requires higher core version.
473 $pluginfo->versionrequires
= 2015110900;
474 $this->assertFalse($pluginfo->is_core_dependency_satisfied(2015100100));
475 $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29);
476 $this->assertEquals(2015100100, $reqs['core']->hasver
);
477 $this->assertEquals(2015110900, $reqs['core']->reqver
);
478 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OUTDATED
, $reqs['core']->status
);
480 // Test plugin requires current core version.
481 $pluginfo->versionrequires
= 2015110900;
482 $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015110900));
483 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
484 $this->assertEquals(2015110900, $reqs['core']->hasver
);
485 $this->assertEquals(2015110900, $reqs['core']->reqver
);
486 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK
, $reqs['core']->status
);
488 // Test plugin requires lower core version.
489 $pluginfo->versionrequires
= 2014122400;
490 $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015100100));
491 $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29);
492 $this->assertEquals(2015100100, $reqs['core']->hasver
);
493 $this->assertEquals(2014122400, $reqs['core']->reqver
);
494 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK
, $reqs['core']->status
);
496 // Test plugin dependencies and their availability.
497 // See {@link \core\update\testable_api} class.
499 $pluginfo->dependencies
= ['foo_bar' => ANY_VERSION
, 'not_exists' => ANY_VERSION
];
500 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
501 $this->assertNull($reqs['foo_bar']->hasver
);
502 $this->assertEquals(ANY_VERSION
, $reqs['foo_bar']->reqver
);
503 $this->assertEquals($pluginman::REQUIREMENT_STATUS_MISSING
, $reqs['foo_bar']->status
);
504 $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE
, $reqs['foo_bar']->availability
);
505 $this->assertEquals($pluginman::REQUIREMENT_UNAVAILABLE
, $reqs['not_exists']->availability
);
507 $pluginfo->dependencies
= ['foo_bar' => 2013122400];
508 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
509 $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE
, $reqs['foo_bar']->availability
);
511 $pluginfo->dependencies
= ['foo_bar' => 2015093000];
512 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
513 $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE
, $reqs['foo_bar']->availability
);
515 $pluginfo->dependencies
= ['foo_bar' => 2015100500];
516 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
517 $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE
, $reqs['foo_bar']->availability
);
519 $pluginfo->dependencies
= ['foo_bar' => 2025010100];
520 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
521 $this->assertEquals($pluginman::REQUIREMENT_UNAVAILABLE
, $reqs['foo_bar']->availability
);
523 // Plugin missing from disk - no version.php available.
524 $pluginfo = testable_plugininfo_base
::fake_plugin_instance(
529 'testable_plugininfo_base',
532 $pluginfo->versiondisk
= null;
533 $this->assertEmpty($pluginman->resolve_requirements($pluginfo, 2015110900, 30));
535 // Test plugin fails for incompatible version.
536 $pluginfo = testable_plugininfo_base
::fake_plugin_instance(
541 'testable_plugininfo_base',
544 $pluginfo->versiondisk
= 2015060600;
545 $pluginfo->pluginincompatible
= 30;
546 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
547 $this->assertEquals($pluginman::REQUIREMENT_STATUS_NEWER
, $reqs['core']->status
);
549 // Test no failure for no incompatible version.
550 $pluginfo->pluginincompatible
= 30;
551 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 29);
552 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK
, $reqs['core']->status
);
555 public function test_missing_dependencies(): void
{
556 $pluginman = testable_core_plugin_manager
::instance();
558 $one = testable_plugininfo_base
::fake_plugin_instance(
563 'testable_plugininfo_base',
566 $one->versiondisk
= 2015070800;
568 $two = testable_plugininfo_base
::fake_plugin_instance(
573 'testable_plugininfo_base',
576 $two->versiondisk
= 2015070900;
578 $pluginman->inject_testable_plugininfo('fake', 'one', $one);
579 $pluginman->inject_testable_plugininfo('fake', 'two', $two);
581 $this->assertEmpty($pluginman->missing_dependencies());
583 $one->dependencies
= ['foo_bar' => ANY_VERSION
];
584 $misdeps = $pluginman->missing_dependencies();
585 $this->assertInstanceOf('\core\update\remote_info', $misdeps['foo_bar']);
586 $this->assertEquals(2015100400, $misdeps['foo_bar']->version
->version
);
588 $two->dependencies
= ['foo_bar' => 2015100500];
589 $misdeps = $pluginman->missing_dependencies();
590 $this->assertInstanceOf('\core\update\remote_info', $misdeps['foo_bar']);
591 $this->assertEquals(2015100500, $misdeps['foo_bar']->version
->version
);
595 * Tests for check_explicitly_supported function to ensure that versions are correctly reported.
597 * @dataProvider check_explicitly_supported_provider
598 * @param array|null $supported Supported versions to inject
599 * @param string|int|null $incompatible Incompatible version to inject.
600 * @param int $version Version to test
601 * @param int $expected
604 public function test_explicitly_supported($supported, $incompatible, $version, $expected): void
{
605 $pluginman = testable_core_plugin_manager
::instance();
607 // Prepare a fake pluginfo instance.
608 $plugininfo = new testable_plugininfo_base();
609 $plugininfo->type
= 'fake';
610 $plugininfo->typerootdir
= '/dev/null';
611 $plugininfo->name
= 'example';
612 $plugininfo->rootdir
= '/dev/null/fake';
613 $plugininfo->pluginman
= $pluginman;
614 $plugininfo->versiondisk
= 2015060600;
615 $plugininfo->supported
= $supported;
616 $plugininfo->incompatible
= $incompatible;
618 $pluginman->add_fake_plugin_info($plugininfo);
620 $plugininfo->load_disk_version();
622 $this->assertEquals($expected, $pluginman->check_explicitly_supported($plugininfo, $version));
626 * Data provider for check_explicitly_supported with a range of correctly defined version support values.
630 public static function check_explicitly_supported_provider(): array {
632 'Range, branch in support, lowest' => [
633 'supported' => [29, 31],
634 'incompatible' => null,
636 'expected' => core_plugin_manager
::VERSION_SUPPORTED
,
638 'Range, branch in support, mid' => [
639 'supported' => [29, 31],
640 'incompatible' => null,
642 'expected' => core_plugin_manager
::VERSION_SUPPORTED
,
644 'Range, branch in support, highest' => [
645 'supported' => [29, 31],
646 'incompatible' => null,
648 'expected' => core_plugin_manager
::VERSION_SUPPORTED
,
651 'Range, branch not in support, high' => [
652 'supported' => [29, 31],
653 'incompatible' => null,
655 'expected' => core_plugin_manager
::VERSION_NOT_SUPPORTED
,
657 'Range, branch not in support, low' => [
658 'supported' => [29, 31],
659 'incompatible' => null,
661 'expected' => core_plugin_manager
::VERSION_NOT_SUPPORTED
,
663 'Range, incompatible, high.' => [
664 'supported' => [29, 31],
665 'incompatible' => 32,
667 'expected' => core_plugin_manager
::VERSION_NOT_SUPPORTED
,
669 'Range, incompatible, low.' => [
670 'supported' => [29, 31],
671 'incompatible' => 32,
673 'expected' => core_plugin_manager
::VERSION_SUPPORTED
,
675 'Range, incompatible, equal.' => [
676 'supported' => [29, 31],
677 'incompatible' => 32,
679 'expected' => core_plugin_manager
::VERSION_NOT_SUPPORTED
,
683 'incompatible' => null,
685 'expected' => core_plugin_manager
::VERSION_NO_SUPPORTS
,
687 'No supports, but incompatible, older' => [
689 'incompatible' => 30,
691 'expected' => core_plugin_manager
::VERSION_NOT_SUPPORTED
,
693 'No supports, but incompatible, equal' => [
695 'incompatible' => 32,
697 'expected' => core_plugin_manager
::VERSION_NOT_SUPPORTED
,
699 'No supports, but incompatible, newer' => [
701 'incompatible' => 34,
703 'expected' => core_plugin_manager
::VERSION_NO_SUPPORTS
,
709 * @dataProvider is_deleted_standard_plugin_provider
711 public function test_is_deleted_standard_plugin(
718 \core_plugin_manager
::is_deleted_standard_plugin($type, $name),
722 public static function is_deleted_standard_plugin_provider(): array {
724 // Valid deleted plugin.
725 ['h5plib', 'v124', true],
726 // Valid type, but not a valid plugin.
727 ['h5plib', 'v99', false],
729 ['marmelade', 'paddington', false],
733 public function test_get_deleted_plugins(): void
{
734 $plugins = core_plugin_manager
::get_deleted_plugins();
735 $this->assertIsArray($plugins);
737 // Pick a couple we know should be there.
738 $this->assertContains('h5plib_v124', $plugins);
739 $this->assertNotContains('h5plib_v99', $plugins);
741 $this->assertContains('editor_tinymce', $plugins);
742 $this->assertNotContains('editor_tiny', $plugins);
745 public function test_standard_plugins_list_no_type(): void
{
746 $plugins = core_plugin_manager
::standard_plugins_list('typo');
747 $this->assertFalse($plugins);
751 * @dataProvider standard_plugins_list_provider
753 public function test_standard_plugins_list(
755 array $expectedplugins,
757 $plugins = core_plugin_manager
::standard_plugins_list($type);
758 $this->assertIsArray($plugins);
759 foreach ($expectedplugins as $expected) {
760 $this->assertContains($expected, $plugins);
764 public static function standard_plugins_list_provider(): array {
768 ['forum', 'assign', 'book', 'choice'],
772 ['starredcourses', 'badges'],
781 public function test_get_standard_plugins(): void
{
782 $plugins = core_plugin_manager
::get_standard_plugins();
783 $this->assertIsArray($plugins);
785 $this->assertContains('mod_forum', $plugins);
786 $this->assertContains('block_badges', $plugins);
787 $this->assertNotContains('marmelade_paddington', $plugins);