MDL-49329 admin: Add core_plugin_manager::available_updates() method
[moodle.git] / lib / tests / fixtures / testable_plugin_manager.php
CommitLineData
361feecd
DM
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 * Provides testable_core_plugin_manager class.
19 *
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
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
35f2b674
DM
28require_once(__DIR__.'/testable_update_api.php');
29
361feecd
DM
30/**
31 * Testable variant of the core_plugin_manager
32 *
33 * @copyright 2015 David Mudrak <david@moodle.com>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
36class testable_core_plugin_manager extends core_plugin_manager {
37
38 /** @var testable_core_plugin_manager holds the singleton instance */
39 protected static $singletoninstance;
c44bbe35 40
35f2b674
DM
41 /**
42 * Allows us to inject items directly into the plugins info tree.
43 *
44 * Do not forget to call our reset_caches() after using this method to force a new
45 * singleton instance.
46 */
47 public function inject_testable_plugininfo($type, $name, \core\plugininfo\base $plugininfo) {
cc5bc55e
DM
48
49 // Let the parent initialize the ->pluginsinfo tree.
50 parent::get_plugins();
51
52 // Inject the additional plugin info.
35f2b674
DM
53 $this->pluginsinfo[$type][$name] = $plugininfo;
54 }
55
56 /**
57 * Returns testable subclass of the client.
58 *
59 * @return \core\update\testable_api
60 */
61 protected function get_update_api_client() {
62 return \core\update\testable_api::client();
63 }
64
c44bbe35
DM
65 /**
66 * Mockup implementation of loading available updates info.
67 *
68 * This testable implementation does not actually use
69 * {@link \core\update\checker}. Instead, it provides hard-coded list of
cc5bc55e
DM
70 * fictional available updates for our foo_bar plugin.
71 *
72 * Note there is a difference in the behaviour as the actual update API
73 * does not return info of lower version than requested. To mock up well,
74 * make sure the injected foo_bar testable plugin info has version lower
75 * than the lowest one returned here.
c44bbe35
DM
76 *
77 * @param string $component
78 * @return array|null array of \core\update\info objects or null
79 */
80 public function load_available_updates_for_plugin($component) {
81
cc5bc55e 82 if ($component === 'foo_bar') {
c44bbe35
DM
83 $updates = array();
84
85 $updates[] = new \core\update\info($component, array(
cc5bc55e
DM
86 'version' => '2015093000',
87 'release' => 'Foo bar 15.09.30 beta',
88 'maturity' => MATURITY_BETA,
89 ));
90
91 $updates[] = new \core\update\info($component, array(
92 'version' => '2015100400',
93 'release' => 'Foo bar 15.10.04',
94 'maturity' => MATURITY_STABLE,
c44bbe35
DM
95 ));
96
97 $updates[] = new \core\update\info($component, array(
cc5bc55e
DM
98 'version' => '2015100500',
99 'release' => 'Foo bar 15.10.05 beta',
c44bbe35
DM
100 'maturity' => MATURITY_BETA,
101 ));
102
103 return $updates;
104 }
105
106 return null;
107 }
361feecd 108}