Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

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