MDL-48493 admin: Make plugin installer able to detect plugin component

On contrary to deeper heuristic (read: guessing) we perform in the
Plugins directory (such as looking at the names of the language files),
here we simply rely on the plugin component being correctly defined in
the version.php file.

The validator class has more robust processing, to make sure the
component declaration is not provided in a commented area of the
version.php etc.  However, as it is fully acceptable that the
auto-detection fails if the version.php uses non-standard syntax, this
easier approach is valid here.
This commit is contained in:
David Mudrák
2015-01-15 12:58:14 +01:00
parent da0ef2e4cf
commit bbf3cd4e93
3 changed files with 120 additions and 0 deletions
@@ -143,6 +143,21 @@ class tool_installaddon_installer_testcase extends advanced_testcase {
$this->assertTrue(is_file($jobroot.'/moved/sub/folder/readme.txt'));
$this->assertSame('Hello world!', file_get_contents($jobroot.'/moved/sub/folder/readme.txt'));
}
public function test_detect_plugin_component() {
$jobid = md5(rand().uniqid('test_', true));
$workdir = make_temp_directory('tool_installaddon/'.$jobid.'/version');
$zipfile = __DIR__.'/fixtures/zips/bar.zip';
$installer = tool_installaddon_installer::instance();
$this->assertEquals('foo_bar', $installer->detect_plugin_component($zipfile, $workdir));
}
public function test_detect_plugin_component_from_versionphp() {
$installer = testable_tool_installaddon_installer::instance();
$this->assertEquals('bar_bar_conan', $installer->detect_plugin_component_from_versionphp('
$plugin->version = 2014121300;
$plugin->component= "bar_bar_conan" ; // Go Arnie go!'));
}
}
@@ -173,4 +188,8 @@ class testable_tool_installaddon_installer extends tool_installaddon_installer {
protected function should_send_site_info() {
return true;
}
public function detect_plugin_component_from_versionphp($code) {
return parent::detect_plugin_component_from_versionphp($code);
}
}