Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   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() {
  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->assertInternalType('array', $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->assertInternalType('object', $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->assertInternalType('array', $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       * @expectedException moodle_exception
 375       */
 376      public function test_get_remote_plugin_info_exception() {
 377          $pluginman = testable_core_plugin_manager::instance();
 378          $pluginman->get_remote_plugin_info('any_thing', ANY_VERSION, true);
 379      }
 380  
 381      public function test_is_remote_plugin_available() {
 382          $pluginman = testable_core_plugin_manager::instance();
 383  
 384          $this->assertFalse($pluginman->is_remote_plugin_available('not_exists', ANY_VERSION, false));
 385          $this->assertTrue($pluginman->is_remote_plugin_available('foo_bar', 2013131313, false));
 386          $this->assertFalse($pluginman->is_remote_plugin_available('foo_bar', 2013131313, true));
 387      }
 388  
 389      public function test_resolve_requirements() {
 390          $pluginman = testable_core_plugin_manager::instance();
 391  
 392          // Prepare a fake pluginfo instance.
 393          $pluginfo = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'one', '/dev/null/fake',
 394              'testable_plugininfo_base', $pluginman);
 395          $pluginfo->versiondisk = 2015060600;
 396  
 397          // Test no $plugin->requires is specified in version.php.
 398          $pluginfo->versionrequires = null;
 399          $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015100100));
 400          $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29);
 401          $this->assertEquals(2015100100, $reqs['core']->hasver);
 402          $this->assertEquals(ANY_VERSION, $reqs['core']->reqver);
 403          $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK, $reqs['core']->status);
 404  
 405          // Test plugin requires higher core version.
 406          $pluginfo->versionrequires = 2015110900;
 407          $this->assertFalse($pluginfo->is_core_dependency_satisfied(2015100100));
 408          $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29);
 409          $this->assertEquals(2015100100, $reqs['core']->hasver);
 410          $this->assertEquals(2015110900, $reqs['core']->reqver);
 411          $this->assertEquals($pluginman::REQUIREMENT_STATUS_OUTDATED, $reqs['core']->status);
 412  
 413          // Test plugin requires current core version.
 414          $pluginfo->versionrequires = 2015110900;
 415          $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015110900));
 416          $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
 417          $this->assertEquals(2015110900, $reqs['core']->hasver);
 418          $this->assertEquals(2015110900, $reqs['core']->reqver);
 419          $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK, $reqs['core']->status);
 420  
 421          // Test plugin requires lower core version.
 422          $pluginfo->versionrequires = 2014122400;
 423          $this->assertTrue($pluginfo->is_core_dependency_satisfied(2015100100));
 424          $reqs = $pluginman->resolve_requirements($pluginfo, 2015100100, 29);
 425          $this->assertEquals(2015100100, $reqs['core']->hasver);
 426          $this->assertEquals(2014122400, $reqs['core']->reqver);
 427          $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK, $reqs['core']->status);
 428  
 429          // Test plugin dependencies and their availability.
 430          // See {@link \core\update\testable_api} class.
 431  
 432          $pluginfo->dependencies = array('foo_bar' => ANY_VERSION, 'not_exists' => ANY_VERSION);
 433          $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
 434          $this->assertNull($reqs['foo_bar']->hasver);
 435          $this->assertEquals(ANY_VERSION, $reqs['foo_bar']->reqver);
 436          $this->assertEquals($pluginman::REQUIREMENT_STATUS_MISSING, $reqs['foo_bar']->status);
 437          $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE, $reqs['foo_bar']->availability);
 438          $this->assertEquals($pluginman::REQUIREMENT_UNAVAILABLE, $reqs['not_exists']->availability);
 439  
 440          $pluginfo->dependencies = array('foo_bar' => 2013122400);
 441          $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
 442          $this->assertEquals($pluginman::REQUIREMENT_AVAILABLE, $reqs['foo_bar']->availability);
 443  
 444          $pluginfo->dependencies = array('foo_bar' => 2015093000);
 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' => 2015100500);
 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' => 2025010100);
 453          $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
 454          $this->assertEquals($pluginman::REQUIREMENT_UNAVAILABLE, $reqs['foo_bar']->availability);
 455  
 456          // Plugin missing from disk - no version.php available.
 457          $pluginfo = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'missing', '/dev/null/fake',
 458              'testable_plugininfo_base', $pluginman);
 459          $pluginfo->versiondisk = null;
 460          $this->assertEmpty($pluginman->resolve_requirements($pluginfo, 2015110900, 30));
 461  
 462          // Test plugin fails for incompatible version.
 463          $pluginfo = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'two', '/dev/null/fake',
 464              'testable_plugininfo_base', $pluginman);
 465          $pluginfo->versiondisk = 2015060600;
 466          $pluginfo->pluginincompatible = 30;
 467          $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 30);
 468          $this->assertEquals($pluginman::REQUIREMENT_STATUS_NEWER, $reqs['core']->status);
 469  
 470          // Test no failure for no incompatible version.
 471          $pluginfo->pluginincompatible = 30;
 472          $reqs = $pluginman->resolve_requirements($pluginfo, 2015110900, 29);
 473          $this->assertEquals($pluginman::REQUIREMENT_STATUS_OK, $reqs['core']->status);
 474      }
 475  
 476      public function test_missing_dependencies() {
 477          $pluginman = testable_core_plugin_manager::instance();
 478  
 479          $one = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'one', '/dev/null/fake',
 480              'testable_plugininfo_base', $pluginman);
 481          $one->versiondisk = 2015070800;
 482  
 483          $two = testable_plugininfo_base::fake_plugin_instance('fake', '/dev/null', 'two', '/dev/null/fake',
 484              'testable_plugininfo_base', $pluginman);
 485          $two->versiondisk = 2015070900;
 486  
 487          $pluginman->inject_testable_plugininfo('fake', 'one', $one);
 488          $pluginman->inject_testable_plugininfo('fake', 'two', $two);
 489  
 490          $this->assertEmpty($pluginman->missing_dependencies());
 491  
 492          $one->dependencies = array('foo_bar' => ANY_VERSION);
 493          $misdeps = $pluginman->missing_dependencies();
 494          $this->assertInstanceOf('\core\update\remote_info', $misdeps['foo_bar']);
 495          $this->assertEquals(2015100400, $misdeps['foo_bar']->version->version);
 496  
 497          $two->dependencies = array('foo_bar' => 2015100500);
 498          $misdeps = $pluginman->missing_dependencies();
 499          $this->assertInstanceOf('\core\update\remote_info', $misdeps['foo_bar']);
 500          $this->assertEquals(2015100500, $misdeps['foo_bar']->version->version);
 501      }
 502  
 503      /**
 504       * Tests for check_explicitly_supported function to ensure that versions are correctly reported.
 505       *
 506       * @dataProvider check_explicitly_supported_provider
 507       * @param array|null $supported Supported versions to inject
 508       * @param string|int|null $incompatible Incompatible version to inject.
 509       * @param int $version Version to test
 510       * @param int $expected
 511       * @return void
 512       */
 513      public function test_explicitly_supported($supported, $incompatible, $version, $expected): void {
 514          $pluginman = testable_core_plugin_manager::instance();
 515  
 516          // Prepare a fake pluginfo instance.
 517          $plugininfo = new testable_plugininfo_base();
 518          $plugininfo->type = 'fake';
 519          $plugininfo->typerootdir = '/dev/null';
 520          $plugininfo->name = 'example';
 521          $plugininfo->rootdir = '/dev/null/fake';
 522          $plugininfo->pluginman = $pluginman;
 523          $plugininfo->versiondisk = 2015060600;
 524          $plugininfo->supported = $supported;
 525          $plugininfo->incompatible = $incompatible;
 526  
 527          $pluginman->add_fake_plugin_info($plugininfo);
 528  
 529          $plugininfo->load_disk_version();
 530  
 531          $this->assertEquals($expected, $pluginman->check_explicitly_supported($plugininfo, $version));
 532      }
 533  
 534      /**
 535       * Data provider for check_explicitly_supported with a range of correctly defined version support values.
 536       *
 537       * @return array
 538       */
 539      public function check_explicitly_supported_provider(): array {
 540          return [
 541              'Range, branch in support, lowest' => [
 542                  'supported' => [29, 31],
 543                  'incompatible' => null,
 544                  'version' => 29,
 545                  'expected' => core_plugin_manager::VERSION_SUPPORTED,
 546              ],
 547              'Range, branch in support, mid' => [
 548                  'supported' => [29, 31],
 549                  'incompatible' => null,
 550                  'version' => 30,
 551                  'expected' => core_plugin_manager::VERSION_SUPPORTED,
 552              ],
 553              'Range, branch in support, highest' => [
 554                  'supported' => [29, 31],
 555                  'incompatible' => null,
 556                  'version' => 31,
 557                  'expected' => core_plugin_manager::VERSION_SUPPORTED,
 558              ],
 559  
 560              'Range, branch not in support, high' => [
 561                  'supported' => [29, 31],
 562                  'incompatible' => null,
 563                  'version' => 32,
 564                  'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED,
 565              ],
 566              'Range, branch not in support, low' => [
 567                  'supported' => [29, 31],
 568                  'incompatible' => null,
 569                  'version' => 28,
 570                  'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED,
 571              ],
 572              'Range, incompatible, high.' => [
 573                  'supported' => [29, 31],
 574                  'incompatible' => 32,
 575                  'version' => 33,
 576                  'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED,
 577              ],
 578              'Range, incompatible, low.' => [
 579                  'supported' => [29, 31],
 580                  'incompatible' => 32,
 581                  'version' => 31,
 582                  'expected' => core_plugin_manager::VERSION_SUPPORTED,
 583              ],
 584              'Range, incompatible, equal.' => [
 585                  'supported' => [29, 31],
 586                  'incompatible' => 32,
 587                  'version' => 32,
 588                  'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED,
 589              ],
 590              'No supports' => [
 591                  'supported' => null,
 592                  'incompatible' => null,
 593                  'version' => 32,
 594                  'expected' => core_plugin_manager::VERSION_NO_SUPPORTS,
 595              ],
 596              'No supports, but incompatible, older' => [
 597                  'supported' => null,
 598                  'incompatible' => 30,
 599                  'version' => 32,
 600                  'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED,
 601              ],
 602              'No supports, but incompatible, equal' => [
 603                  'supported' => null,
 604                  'incompatible' => 32,
 605                  'version' => 32,
 606                  'expected' => core_plugin_manager::VERSION_NOT_SUPPORTED,
 607              ],
 608              'No supports, but incompatible, newer' => [
 609                  'supported' => null,
 610                  'incompatible' => 34,
 611                  'version' => 32,
 612                  'expected' => core_plugin_manager::VERSION_NO_SUPPORTS,
 613              ],
 614          ];
 615      }
 616  }