MDL-49329 admin: Add core_plugin_manager::available_updates() method

The new method is going to be used to support the "Update all plugins"
feature.
This commit is contained in:
David Mudrák
2015-10-08 23:32:04 +02:00
parent 3bca7dbfa6
commit cc5bc55ead
3 changed files with 135 additions and 20 deletions
+23 -10
View File
@@ -45,6 +45,11 @@ class testable_core_plugin_manager extends core_plugin_manager {
* singleton instance.
*/
public function inject_testable_plugininfo($type, $name, \core\plugininfo\base $plugininfo) {
// Let the parent initialize the ->pluginsinfo tree.
parent::get_plugins();
// Inject the additional plugin info.
$this->pluginsinfo[$type][$name] = $plugininfo;
}
@@ -62,28 +67,36 @@ class testable_core_plugin_manager extends core_plugin_manager {
*
* This testable implementation does not actually use
* {@link \core\update\checker}. Instead, it provides hard-coded list of
* fictional available updates for some standard plugin.
* fictional available updates for our foo_bar plugin.
*
* Note there is a difference in the behaviour as the actual update API
* does not return info of lower version than requested. To mock up well,
* make sure the injected foo_bar testable plugin info has version lower
* than the lowest one returned here.
*
* @param string $component
* @return array|null array of \core\update\info objects or null
*/
public function load_available_updates_for_plugin($component) {
if ($component === 'mod_forum') {
if ($component === 'foo_bar') {
$updates = array();
$updates[] = new \core\update\info($component, array(
'version' => '2002073008',
'release' => 'Forum 0.1',
'maturity' => MATURITY_ALPHA,
'url' => 'https://en.wikipedia.org/wiki/Moodle',
'download' => 'https://moodle.org/plugins/pluginversion.php?id=1',
'downloadmd5' => md5('I can not think of anything funny to type here'),
'version' => '2015093000',
'release' => 'Foo bar 15.09.30 beta',
'maturity' => MATURITY_BETA,
));
$updates[] = new \core\update\info($component, array(
'version' => '2999122400',
'release' => 'Forum NG',
'version' => '2015100400',
'release' => 'Foo bar 15.10.04',
'maturity' => MATURITY_STABLE,
));
$updates[] = new \core\update\info($component, array(
'version' => '2015100500',
'release' => 'Foo bar 15.10.05 beta',
'maturity' => MATURITY_BETA,
));
+46 -10
View File
@@ -291,30 +291,66 @@ class core_plugin_manager_testcase extends advanced_testcase {
}
public function test_plugin_available_updates() {
$pluginman = testable_core_plugin_manager::instance();
$foobar = testable_plugininfo_base::fake_plugin_instance('foo', '/dev/null', 'bar', '/dev/null/fake',
'testable_plugininfo_base', $pluginman);
$foobar->versiondb = 2015092900;
$foobar->versiondisk = 2015092900;
foreach ($pluginman->get_plugins() as $type => $infos) {
foreach ($infos as $name => $info) {
$updates = $info->available_updates();
if ($info->component != 'mod_forum') {
foreach ($infos as $name => $plugin) {
$updates = $plugin->available_updates();
if ($plugin->component != 'foo_bar') {
$this->assertNull($updates);
} else {
$this->assertEquals(1, count($updates));
$update = array_shift($updates);
$this->assertInstanceOf('\core\update\info', $update);
$this->assertEquals('mod_forum', $update->component);
$this->assertEquals('2999122400', $update->version);
$this->assertTrue(is_array($updates));
$this->assertEquals(3, count($updates));
foreach ($updates as $update) {
$this->assertInstanceOf('\core\update\info', $update);
$this->assertEquals($update->component, $plugin->component);
$this->assertTrue($update->version > $plugin->versiondb);
}
}
}
}
}
public function test_some_plugins_updatable() {
public function test_some_plugins_updatable_none() {
$pluginman = testable_core_plugin_manager::instance();
$this->assertFalse($pluginman->some_plugins_updatable());
}
public function test_some_plugins_updatable_some() {
$pluginman = testable_core_plugin_manager::instance();
$foobar = testable_plugininfo_base::fake_plugin_instance('foo', '/dev/null', 'bar', '/dev/null/fake',
'testable_plugininfo_base', $pluginman);
$foobar->versiondb = 2015092900;
$foobar->versiondisk = 2015092900;
$pluginman->inject_testable_plugininfo('foo', 'bar', $foobar);
$this->assertTrue($pluginman->some_plugins_updatable());
}
public function test_available_updates() {
$pluginman = testable_core_plugin_manager::instance();
$foobar = testable_plugininfo_base::fake_plugin_instance('foo', '/dev/null', 'bar', '/dev/null/fake',
'testable_plugininfo_base', $pluginman);
$foobar->versiondb = 2015092900;
$foobar->versiondisk = 2015092900;
$pluginman->inject_testable_plugininfo('foo', 'bar', $foobar);
$updates = $pluginman->available_updates();
$this->assertTrue(is_array($updates));
$this->assertEquals(1, count($updates));
$update = $updates['foo_bar'];
$this->assertEquals('foo_bar', $update->component);
$this->assertEquals(2015100400, $update->version->version);
}
public function test_get_remote_plugin_info() {
$pluginman = testable_core_plugin_manager::instance();