MDL-67271 core: Add test to find missing SVG icons
[moodle.git] / lib / tests / fixtures / testable_plugin_manager.php
blob8080157eaa27aea015cf8af1aaa0812be2eafe55
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.
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/>.
17 /**
18 * Provides testable_core_plugin_manager class.
20 * @package core
21 * @category test
22 * @copyright 2015 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 require_once(__DIR__.'/testable_update_api.php');
30 /**
31 * Testable variant of the core_plugin_manager
33 * @copyright 2015 David Mudrak <david@moodle.com>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class testable_core_plugin_manager extends core_plugin_manager {
38 /** @var testable_core_plugin_manager holds the singleton instance */
39 protected static $singletoninstance;
41 /**
42 * Allows us to inject items directly into the plugins info tree.
44 * Do not forget to call our reset_caches() after using this method to force a new
45 * singleton instance.
47 * @param string $type plugin type
48 * @param string $name plugin name
49 * @param \core\plugininfo\base $plugininfo plugin info class
51 public function inject_testable_plugininfo($type, $name, \core\plugininfo\base $plugininfo) {
53 // Let the parent initialize the ->pluginsinfo tree.
54 parent::get_plugins();
56 // Inject the additional plugin info.
57 $this->pluginsinfo[$type][$name] = $plugininfo;
60 /**
61 * Returns testable subclass of the client.
63 * @return \core\update\testable_api
65 protected function get_update_api_client() {
66 return \core\update\testable_api::client();
69 /**
70 * Mockup implementation of loading available updates info.
72 * This testable implementation does not actually use
73 * {@link \core\update\checker}. Instead, it provides hard-coded list of
74 * fictional available updates for our foo_bar plugin.
76 * Note there is a difference in the behaviour as the actual update API
77 * does not return info of lower version than requested. To mock up well,
78 * make sure the injected foo_bar testable plugin info has version lower
79 * than the lowest one returned here.
81 * @param string $component
82 * @return array|null array of \core\update\info objects or null
84 public function load_available_updates_for_plugin($component) {
86 if ($component === 'foo_bar') {
87 $updates = array();
89 $updates[] = new \core\update\info($component, array(
90 'version' => '2015093000',
91 'release' => 'Foo bar 15.09.30 beta',
92 'maturity' => MATURITY_BETA,
93 ));
95 $updates[] = new \core\update\info($component, array(
96 'version' => '2015100400',
97 'release' => 'Foo bar 15.10.04',
98 'maturity' => MATURITY_STABLE,
99 ));
101 $updates[] = new \core\update\info($component, array(
102 'version' => '2015100500',
103 'release' => 'Foo bar 15.10.05 beta',
104 'maturity' => MATURITY_BETA,
107 return $updates;
110 return null;
114 * Adds fake plugin information from record.
116 * @param testable_plugininfo_base $record
117 * @return void
119 public function add_fake_plugin_info($record): void {
120 $this->load_present_plugins();
122 $this->presentplugins[$record->type][$record->name] = $record;