Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
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 * Unit tests for plugin manager class. 19 * 20 * @package core 21 * @category phpunit 22 * @copyright 2013 Petr Skoda {@link http://skodak.org} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->dirroot.'/lib/tests/fixtures/testable_plugin_manager.php'); 30 require_once($CFG->dirroot.'/lib/tests/fixtures/testable_plugininfo_base.php'); 31 32 /** 33 * Tests of the basic API of the plugin manager. 34 */ 35 class core_plugin_manager_testcase extends advanced_testcase { 36 37 public function tearDown(): void { 38 // The caches of the testable singleton must be reset explicitly. It is 39 // safer to kill the whole testable singleton at the end of every test. 40 testable_core_plugin_manager::reset_caches(); 41 } 42 43 public function test_instance() { 44 $pluginman1 = core_plugin_manager::instance(); 45 $this->assertInstanceOf('core_plugin_manager', $pluginman1); 46 $pluginman2 = core_plugin_manager::instance(); 47 $this->assertSame($pluginman1, $pluginman2); 48 $pluginman3 = testable_core_plugin_manager::instance(); 49 $this->assertInstanceOf('core_plugin_manager', $pluginman3); 50 $this->assertInstanceOf('testable_core_plugin_manager', $pluginman3); 51 $pluginman4 = testable_core_plugin_manager::instance(); 52 $this->assertSame($pluginman3, $pluginman4); 53 $this->assertNotSame($pluginman1, $pluginman3); 54 } 55 56 public function test_reset_caches() { 57 // Make sure there are no warnings or errors. 58 core_plugin_manager::reset_caches(); 59 testable_core_plugin_manager::reset_caches(); 60 } 61 62 /** 63 * Make sure that the tearDown() really kills the singleton after this test. 64 */ 65 public function test_teardown_works_precheck() { 66 $pluginman = testable_core_plugin_manager::instance(); 67 $pluginfo = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'one', '/dev/null/fake', 68 'testable_plugininfo_base', $pluginman); 69 $pluginman->inject_testable_plugininfo('fake', 'one', $pluginfo); 70 71 $this->assertInstanceOf('\core\plugininfo\base', $pluginman->get_plugin_info('fake_one')); 72 $this->assertNull($pluginman->get_plugin_info('fake_two')); 73 } 74 75 public function test_teardown_works_postcheck() { 76 $pluginman = testable_core_plugin_manager::instance(); 77 $this->assertNull($pluginman->get_plugin_info('fake_one')); 78 $this->assertNull($pluginman->get_plugin_info('fake_two')); 79 } 80 81 public function test_get_plugin_types() { 82 // Make sure there are no warnings or errors. 83 $types = core_plugin_manager::instance()->get_plugin_types(); 84 $this->assertIsArray($types); 85 foreach ($types as $type => $fulldir) { 86 $this->assertFileExists($fulldir); 87 } 88 } 89 90 public function test_get_installed_plugins() { 91 $types = core_plugin_manager::instance()->get_plugin_types(); 92 foreach ($types as $type => $fulldir) { 93 $installed = core_plugin_manager::instance()->get_installed_plugins($type); 94 foreach ($installed as $plugin => $version) { 95 $this->assertRegExp('/^[a-z]+[a-z0-9_]*$/', $plugin); 96 $this->assertTrue(is_numeric($version), 'All plugins should have a version, plugin '.$type.'_'.$plugin.' does not have version info.'); 97 } 98 } 99 } 100 101 public function test_get_enabled_plugins() { 102 $types = core_plugin_manager::instance()->get_plugin_types(); 103 foreach ($types as $type => $fulldir) { 104 $enabled = core_plugin_manager::instance()->get_enabled_plugins($type); 105 if (is_array($enabled)) { 106 foreach ($enabled as $key => $val) { 107 $this->assertRegExp('/^[a-z]+[a-z0-9_]*$/', $key); 108 $this->assertSame($key, $val); 109 } 110 } else { 111 $this->assertNull($enabled); 112 } 113 } 114 } 115 116 public function test_get_present_plugins() { 117 $types = core_plugin_manager::instance()->get_plugin_types(); 118 foreach ($types as $type => $fulldir) { 119 $present = core_plugin_manager::instance()->get_present_plugins($type); 120 if (is_array($present)) { 121 foreach ($present as $plugin => $version) { 122 $this->assertRegExp('/^[a-z]+[a-z0-9_]*$/', $plugin, 'All plugins are supposed to have version.php file.'); 123 $this->assertIsObject($version); 124 $this->assertTrue(is_numeric($version->version), 'All plugins should have a version, plugin '.$type.'_'.$plugin.' does not have version info.'); 125 } 126 } else { 127 // No plugins of this type exist. 128 $this->assertNull($present); 129 } 130 } 131 } 132 133 public function test_get_plugins() { 134 $plugininfos1 = core_plugin_manager::instance()->get_plugins(); 135 foreach ($plugininfos1 as $type => $infos) { 136 foreach ($infos as $name => $info) { 137 $this->assertInstanceOf('\core\plugininfo\base', $info); 138 } 139 } 140 141 // The testable variant of the manager holds its own tree of the 142 // plugininfo objects. 143 $plugininfos2 = testable_core_plugin_manager::instance()->get_plugins(); 144 $this->assertNotSame($plugininfos1['mod']['forum'], $plugininfos2['mod']['forum']); 145 146 // Singletons of each manager class share the same tree. 147 $plugininfos3 = core_plugin_manager::instance()->get_plugins(); 148 $this->assertSame($plugininfos1['mod']['forum'], $plugininfos3['mod']['forum']); 149 $plugininfos4 = testable_core_plugin_manager::instance()->get_plugins(); 150 $this->assertSame($plugininfos2['mod']['forum'], $plugininfos4['mod']['forum']); 151 } 152 153 public function test_plugininfo_back_reference_to_the_plugin_manager() { 154 $plugman1 = core_plugin_manager::instance(); 155 $plugman2 = testable_core_plugin_manager::instance(); 156 157 foreach ($plugman1->get_plugins() as $type => $infos) { 158 foreach ($infos as $info) { 159 $this->assertSame($info->pluginman, $plugman1); 160 } 161 } 162 163 foreach ($plugman2->get_plugins() as $type => $infos) { 164 foreach ($infos as $info) { 165 $this->assertSame($info->pluginman, $plugman2); 166 } 167 } 168 } 169 170 public function test_get_plugins_of_type() { 171 $plugininfos = core_plugin_manager::instance()->get_plugins(); 172 foreach ($plugininfos as $type => $infos) { 173 $this->assertSame($infos, core_plugin_manager::instance()->get_plugins_of_type($type)); 174 } 175 } 176 177 public function test_get_subplugins_of_plugin() { 178 global $CFG; 179 180 // Any standard plugin with subplugins is suitable. 181 $this->assertFileExists("$CFG->dirroot/lib/editor/tinymce", 'TinyMCE is not present.'); 182 183 $subplugins = core_plugin_manager::instance()->get_subplugins_of_plugin('editor_tinymce'); 184 foreach ($subplugins as $component => $info) { 185 $this->assertInstanceOf('\core\plugininfo\base', $info); 186 } 187 } 188 189 public function test_get_subplugins() { 190 // Tested already indirectly from test_get_subplugins_of_plugin(). 191 $subplugins = core_plugin_manager::instance()->get_subplugins(); 192 $this->assertIsArray($subplugins); 193 } 194 195 public function test_get_parent_of_subplugin() { 196 global $CFG; 197 198 // Any standard plugin with subplugins is suitable. 199 $this->assertFileExists("$CFG->dirroot/lib/editor/tinymce", 'TinyMCE is not present.'); 200 201 $parent = core_plugin_manager::instance()->get_parent_of_subplugin('tinymce'); 202 $this->assertSame('editor_tinymce', $parent); 203 } 204 205 public function test_plugin_name() { 206 global $CFG; 207 208 // Any standard plugin is suitable. 209 $this->assertFileExists("$CFG->dirroot/lib/editor/tinymce", 'TinyMCE is not present.'); 210 211 $name = core_plugin_manager::instance()->plugin_name('editor_tinymce'); 212 $this->assertSame(get_string('pluginname', 'editor_tinymce'), $name); 213 } 214 215 public function test_plugintype_name() { 216 $name = core_plugin_manager::instance()->plugintype_name('editor'); 217 $this->assertSame(get_string('type_editor', 'core_plugin'), $name); 218 } 219 220 public function test_plugintype_name_plural() { 221 $name = core_plugin_manager::instance()->plugintype_name_plural('editor'); 222 $this->assertSame(get_string('type_editor_plural', 'core_plugin'), $name); 223 } 224 225 public function test_get_plugin_info() { 226 global $CFG; 227 228 // Any standard plugin is suitable. 229 $this->assertFileExists("$CFG->dirroot/lib/editor/tinymce", 'TinyMCE is not present.'); 230 231 $info = core_plugin_manager::instance()->get_plugin_info('editor_tinymce'); 232 $this->assertInstanceOf('\core\plugininfo\editor', $info); 233 } 234 235 public function test_can_uninstall_plugin() { 236 global $CFG; 237 238 // Any standard plugin that is required by some other standard plugin is ok. 239 $this->assertFileExists("$CFG->dirroot/report/competency", 'competency report is not present'); 240 $this->assertFileExists("$CFG->dirroot/$CFG->admin/tool/lp", 'tool lp is not present'); 241 242 $this->assertFalse(core_plugin_manager::instance()->can_uninstall_plugin('tool_lp')); 243 $this->assertTrue(core_plugin_manager::instance()->can_uninstall_plugin('report_competency')); 244 } 245 246 public function test_plugin_states() { 247 global $CFG; 248 $this->resetAfterTest(); 249 250 // Any standard plugin that is ok. 251 $this->assertFileExists("$CFG->dirroot/mod/assign", 'assign module is not present'); 252 $this->assertFileExists("$CFG->dirroot/mod/forum", 'forum module is not present'); 253 $this->assertFileExists("$CFG->dirroot/$CFG->admin/tool/phpunit", 'phpunit tool is not present'); 254 $this->assertFileNotExists("$CFG->dirroot/mod/xxxxxxx"); 255 $this->assertFileNotExists("$CFG->dirroot/enrol/autorize"); 256 257 // Ready for upgrade. 258 $assignversion = get_config('mod_assign', 'version'); 259 set_config('version', $assignversion - 1, 'mod_assign'); 260 // Downgrade problem. 261 $forumversion = get_config('mod_forum', 'version'); 262 set_config('version', $forumversion + 1, 'mod_forum'); 263 // Not installed yet. 264 unset_config('version', 'tool_phpunit'); 265 // Missing already installed. 266 set_config('version', 2013091300, 'mod_xxxxxxx'); 267 // Deleted present. 268 set_config('version', 2013091300, 'enrol_authorize'); 269 270 core_plugin_manager::reset_caches(); 271 272 $plugininfos = core_plugin_manager::instance()->get_plugins(); 273 foreach ($plugininfos as $type => $infos) { 274 foreach ($infos as $name => $info) { 275 /** @var core\plugininfo\base $info */ 276 if ($info->component === 'mod_assign') { 277 $this->assertSame(core_plugin_manager::PLUGIN_STATUS_UPGRADE, $info->get_status(), 'Invalid '.$info->component.' state'); 278 } else if ($info->component === 'mod_forum') { 279 $this->assertSame(core_plugin_manager::PLUGIN_STATUS_DOWNGRADE, $info->get_status(), 'Invalid '.$info->component.' state'); 280 } else if ($info->component === 'tool_phpunit') { 281 $this->assertSame(core_plugin_manager::PLUGIN_STATUS_NEW, $info->get_status(), 'Invalid '.$info->component.' state'); 282 } else if ($info->component === 'mod_xxxxxxx') { 283 $this->assertSame(core_plugin_manager::PLUGIN_STATUS_MISSING, $info->get_status(), 'Invalid '.$info->component.' state'); 284 } else if ($info->component === 'enrol_authorize') { 285 $this->assertSame(core_plugin_manager::PLUGIN_STATUS_DELETE, $info->get_status(), 'Invalid '.$info->component.' state'); 286 } else { 287 $this->assertSame(core_plugin_manager::PLUGIN_STATUS_UPTODATE, $info->get_status(), 'Invalid '.$info->component.' state'); 288 } 289 } 290 } 291 } 292 293 public function test_plugin_available_updates() { 294 $pluginman = testable_core_plugin_manager::instance(); 295 296 $foobar = testable_plugininfo_base::fake_plugin_instance('foo', '/dev/null', 'bar', '/dev/null/fake', 297 'testable_plugininfo_base', $pluginman); 298 $foobar->versiondb = 2015092900; 299 $foobar->versiondisk = 2015092900; 300 $pluginman->inject_testable_plugininfo('foo', 'bar', $foobar); 301 302 $washere = false; 303 foreach ($pluginman->get_plugins() as $type => $infos) { 304 foreach ($infos as $name => $plugin) { 305 $updates = $plugin->available_updates(); 306 if ($plugin->component != 'foo_bar') { 307 $this->assertNull($updates); 308 } else { 309 $this->assertTrue(is_array($updates)); 310 $this->assertEquals(3, count($updates)); 311 foreach ($updates as $update) { 312 $washere = true; 313 $this->assertInstanceOf('\core\update\info', $update); 314 $this->assertEquals($update->component, $plugin->component); 315 $this->assertTrue($update->version > $plugin->versiondb); 316 } 317 } 318 } 319 } 320 $this->assertTrue($washere); 321 } 322 323 public function test_some_plugins_updatable_none() { 324 $pluginman = testable_core_plugin_manager::instance(); 325 $this->assertFalse($pluginman->some_plugins_updatable()); 326 } 327 328 public function test_some_plugins_updatable_some() { 329 $pluginman = testable_core_plugin_manager::instance(); 330 331 $foobar = testable_plugininfo_base::fake_plugin_instance('foo', '/dev/null', 'bar', '/dev/null/fake', 332 'testable_plugininfo_base', $pluginman); 333 $foobar->versiondb = 2015092900; 334 $foobar->versiondisk = 2015092900; 335 $pluginman->inject_testable_plugininfo('foo', 'bar', $foobar); 336 337 $this->assertTrue($pluginman->some_plugins_updatable()); 338 } 339 340 public function test_available_updates() { 341 $pluginman = testable_core_plugin_manager::instance(); 342 343 $foobar = testable_plugininfo_base::fake_plugin_instance('foo', '/dev/null', 'bar', '/dev/null/fake', 344 'testable_plugininfo_base', $pluginman); 345 $foobar->versiondb = 2015092900; 346 $foobar->versiondisk = 2015092900; 347 $pluginman->inject_testable_plugininfo('foo', 'bar', $foobar); 348 349 $updates = $pluginman->available_updates(); 350 351 $this->assertTrue(is_array($updates)); 352 $this->assertEquals(1, count($updates)); 353 $update = $updates['foo_bar']; 354 $this->assertInstanceOf('\core\update\remote_info', $update); 355 $this->assertEquals('foo_bar', $update->component); 356 $this->assertEquals(2015100400, $update->version->version); 357 } 358 359 public function test_get_remote_plugin_info() { 360 $pluginman = testable_core_plugin_manager::instance(); 361 362 $this->assertFalse($pluginman->get_remote_plugin_info('not_exists', ANY_VERSION, false)); 363 364 $info = $pluginman->get_remote_plugin_info('foo_bar', 2015093000, true); 365 $this->assertEquals(2015093000, $info->version->version); 366 367 $info = $pluginman->get_remote_plugin_info('foo_bar', 2015093000, false); 368 $this->assertEquals(2015100400, $info->version->version); 369 } 370 371 /** 372 * The combination of ANY_VERSION + $exactmatch is illegal. 373 */ 374 public function test_get_remote_plugin_info_exception() { 375 $pluginman = testable_core_plugin_manager::instance(); 376 $this->expectException(moodle_exception::class); 377 $pluginman->get_remote_plugin_info('any_thing', ANY_VERSION, true); 378 } 379 380 public function test_is_remote_plugin_available() { 381 $pluginman = testable_core_plugin_manager::instance(); 382 383 $this->assertFalse($pluginman->is_remote_plugin_available('not_exists', ANY_VERSION, false)); 384 $this->assertTrue($pluginman->is_remote_plugin_available('foo_bar', 2013131313, false)); 385 $this->assertFalse($pluginman->is_remote_plugin_available('foo_bar', 2013131313, true)); 386 } 387 388 public function test_resolve_requirements() { 389 $pluginman = testable_core_plugin_manager::instance(); 390 391 // Prepare a fake pluginfo instance. 392 $pluginfo = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'one', '/dev/null/fake', 393 'testable_plugininfo_base', $pluginman); 394 $pluginfo->versiondisk = 2015060600; 395 396 // Test no $plugin->requires is specified in version.php. 397 $pluginfo->versionrequires = null; 398 $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015100100)); 399 $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29); 400 $this->assertEquals(2015100100, $reqs['core']->hasver); 401 $this->assertEquals(ANY_VERSION, $reqs['core']->reqver); 402 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK, $reqs['core']->status); 403 404 // Test plugin requires higher core version. 405 $pluginfo->versionrequires = 2015110900; 406 $this->assertFalse($pluginfo->is_core_dependency_satisfied(2015100100)); 407 $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29); 408 $this->assertEquals(2015100100, $reqs['core']->hasver); 409 $this->assertEquals(2015110900, $reqs['core']->reqver); 410 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OUTDATED, $reqs['core']->status); 411 412 // Test plugin requires current core version. 413 $pluginfo->versionrequires = 2015110900; 414 $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015110900)); 415 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30); 416 $this->assertEquals(2015110900, $reqs['core']->hasver); 417 $this->assertEquals(2015110900, $reqs['core']->reqver); 418 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK, $reqs['core']->status); 419 420 // Test plugin requires lower core version. 421 $pluginfo->versionrequires = 2014122400; 422 $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015100100)); 423 $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29); 424 $this->assertEquals(2015100100, $reqs['core']->hasver); 425 $this->assertEquals(2014122400, $reqs['core']->reqver); 426 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK, $reqs['core']->status); 427 428 // Test plugin dependencies and their availability. 429 // See {@link \core\update\testable_api} class. 430 431 $pluginfo->dependencies = array('foo_bar' => ANY_VERSION, 'not_exists' => ANY_VERSION); 432 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30); 433 $this->assertNull($reqs['foo_bar']->hasver); 434 $this->assertEquals(ANY_VERSION, $reqs['foo_bar']->reqver); 435 $this->assertEquals($pluginman::REQUIREMENT_STATUS_MISSING, $reqs['foo_bar']->status); 436 $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE, $reqs['foo_bar']->availability); 437 $this->assertEquals($pluginman::REQUIREMENT_UNAVAILABLE, $reqs['not_exists']->availability); 438 439 $pluginfo->dependencies = array('foo_bar' => 2013122400); 440 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30); 441 $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE, $reqs['foo_bar']->availability); 442 443 $pluginfo->dependencies = array('foo_bar' => 2015093000); 444 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30); 445 $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE, $reqs['foo_bar']->availability); 446 447 $pluginfo->dependencies = array('foo_bar' => 2015100500); 448 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30); 449 $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE, $reqs['foo_bar']->availability); 450 451 $pluginfo->dependencies = array('foo_bar' => 2025010100); 452 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30); 453 $this->assertEquals($pluginman::REQUIREMENT_UNAVAILABLE, $reqs['foo_bar']->availability); 454 455 // Plugin missing from disk - no version.php available. 456 $pluginfo = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'missing', '/dev/null/fake', 457 'testable_plugininfo_base', $pluginman); 458 $pluginfo->versiondisk = null; 459 $this->assertEmpty($pluginman->resolve_requirements($pluginfo, 2015110900, 30)); 460 461 // Test plugin fails for incompatible version. 462 $pluginfo = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'two', '/dev/null/fake', 463 'testable_plugininfo_base', $pluginman); 464 $pluginfo->versiondisk = 2015060600; 465 $pluginfo->pluginincompatible = 30; 466 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30); 467 $this->assertEquals($pluginman::REQUIREMENT_STATUS_NEWER, $reqs['core']->status); 468 469 // Test no failure for no incompatible version. 470 $pluginfo->pluginincompatible = 30; 471 $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 29); 472 $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK, $reqs['core']->status); 473 } 474 475 public function test_missing_dependencies() { 476 $pluginman = testable_core_plugin_manager::instance(); 477 478 $one = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'one', '/dev/null/fake', 479 'testable_plugininfo_base', $pluginman); 480 $one->versiondisk = 2015070800; 481 482 $two = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'two', '/dev/null/fake', 483 'testable_plugininfo_base', $pluginman); 484 $two->versiondisk = 2015070900; 485 486 $pluginman->inject_testable_plugininfo('fake', 'one', $one); 487 $pluginman->inject_testable_plugininfo('fake', 'two', $two); 488 489 $this->assertEmpty($pluginman->missing_dependencies()); 490 491 $one->dependencies = array('foo_bar' => ANY_VERSION); 492 $misdeps = $pluginman->missing_dependencies(); 493 $this->assertInstanceOf('\core\update\remote_info', $misdeps['foo_bar']); 494 $this->assertEquals(2015100400, $misdeps['foo_bar']->version->version); 495 496 $two->dependencies = array('foo_bar' => 2015100500); 497 $misdeps = $pluginman->missing_dependencies(); 498 $this->assertInstanceOf('\core\update\remote_info', $misdeps['foo_bar']); 499 $this->assertEquals(2015100500, $misdeps['foo_bar']->version->version); 500 } 501 502 /** 503 * Tests for check_explicitly_supported function to ensure that versions are correctly reported. 504 * 505 * @dataProvider check_explicitly_supported_provider 506 * @param array|null $supported Supported versions to inject 507 * @param string|int|null $incompatible Incompatible version to inject. 508 * @param int $version Version to test 509 * @param int $expected 510 * @return void 511 */ 512 public function test_explicitly_supported($supported, $incompatible, $version, $expected): void { 513 $pluginman = testable_core_plugin_manager::instance(); 514 515 // Prepare a fake pluginfo instance. 516 $plugininfo = new testable_plugininfo_base(); 517 $plugininfo->type = 'fake'; 518 $plugininfo->typerootdir = '/dev/null'; 519 $plugininfo->name = 'example'; 520 $plugininfo->rootdir = '/dev/null/fake'; 521 $plugininfo->pluginman = $pluginman; 522 $plugininfo->versiondisk = 2015060600; 523 $plugininfo->supported = $supported; 524 $plugininfo->incompatible = $incompatible; 525 526 $pluginman->add_fake_plugin_info($plugininfo); 527 528 $plugininfo->load_disk_version(); 529 530 $this->assertEquals($expected, $pluginman->check_explicitly_supported($plugininfo, $version)); 531 } 532 533 /** 534 * Data provider for check_explicitly_supported with a range of correctly defined version support values. 535 * 536 * @return array 537 */ 538 public function check_explicitly_supported_provider(): array { 539 return [ 540 'Range, branch in support, lowest' => [ 541 'supported' => [29, 31], 542 'incompatible' => null, 543 'version' => 29, 544 'expected' => core_plugin_manager::VERSION_SUPPORTED, 545 ], 546 'Range, branch in support, mid' => [ 547 'supported' => [29, 31], 548 'incompatible' => null, 549 'version' => 30, 550 'expected' => core_plugin_manager::VERSION_SUPPORTED, 551 ], 552 'Range, branch in support, highest' => [ 553 'supported' => [29, 31], 554 'incompatible' => null, 555 'version' => 31, 556 'expected' => core_plugin_manager::VERSION_SUPPORTED, 557 ], 558 559 'Range, branch not in support, high' => [ 560 'supported' => [29, 31], 561 'incompatible' => null, 562 'version' => 32, 563 'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED, 564 ], 565 'Range, branch not in support, low' => [ 566 'supported' => [29, 31], 567 'incompatible' => null, 568 'version' => 28, 569 'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED, 570 ], 571 'Range, incompatible, high.' => [ 572 'supported' => [29, 31], 573 'incompatible' => 32, 574 'version' => 33, 575 'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED, 576 ], 577 'Range, incompatible, low.' => [ 578 'supported' => [29, 31], 579 'incompatible' => 32, 580 'version' => 31, 581 'expected' => core_plugin_manager::VERSION_SUPPORTED, 582 ], 583 'Range, incompatible, equal.' => [ 584 'supported' => [29, 31], 585 'incompatible' => 32, 586 'version' => 32, 587 'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED, 588 ], 589 'No supports' => [ 590 'supported' => null, 591 'incompatible' => null, 592 'version' => 32, 593 'expected' => core_plugin_manager::VERSION_NO_SUPPORTS, 594 ], 595 'No supports, but incompatible, older' => [ 596 'supported' => null, 597 'incompatible' => 30, 598 'version' => 32, 599 'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED, 600 ], 601 'No supports, but incompatible, equal' => [ 602 'supported' => null, 603 'incompatible' => 32, 604 'version' => 32, 605 'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED, 606 ], 607 'No supports, but incompatible, newer' => [ 608 'supported' => null, 609 'incompatible' => 34, 610 'version' => 32, 611 'expected' => core_plugin_manager::VERSION_NO_SUPPORTS, 612 ], 613 ]; 614 } 615 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body