MDL-48494 admin: Fail validation of plugins with no component declared
authorDavid Mudrák <david@moodle.com>
Thu, 6 Aug 2015 13:59:40 +0000 (15:59 +0200)
committerDavid Mudrák <david@moodle.com>
Mon, 31 Aug 2015 08:01:34 +0000 (10:01 +0200)
admin/tool/installaddon/classes/validator.php
admin/tool/installaddon/lang/en/tool_installaddon.php
admin/tool/installaddon/tests/fixtures/nocomponent/baz/lang/en/auth_baz.php [new file with mode: 0644]
admin/tool/installaddon/tests/fixtures/nocomponent/baz/version.php [new file with mode: 0644]
admin/tool/installaddon/tests/fixtures/nolang/bah/version.php
admin/tool/installaddon/tests/fixtures/wronglang/bah/lang/en/bah.php [new file with mode: 0644]
admin/tool/installaddon/tests/fixtures/wronglang/bah/version.php [new file with mode: 0644]
admin/tool/installaddon/tests/validator_test.php
admin/tool/installaddon/version.php

index 0bb3a41..0ae7097 100644 (file)
@@ -322,21 +322,24 @@ class tool_installaddon_validator {
             $this->add_message(self::INFO, 'requiresmoodle', $this->versionphp['requires']);
         }
 
-        if (isset($info['plugin->component'])) {
-            $this->versionphp['component'] = $info['plugin->component'];
-            list($reqtype, $reqname) = core_component::normalize_component($this->versionphp['component']);
-            if ($reqtype !== $this->assertions['plugintype']) {
-                $this->add_message(self::ERROR, 'componentmismatchtype', array(
-                    'expected' => $this->assertions['plugintype'],
-                    'found' => $reqtype));
-                return false;
-            }
-            if ($reqname !== $this->rootdir) {
-                $this->add_message(self::ERROR, 'componentmismatchname', $reqname);
-                return false;
-            }
-            $this->add_message(self::INFO, 'componentmatch', $this->versionphp['component']);
+        if (!isset($info['plugin->component'])) {
+            $this->add_message(self::ERROR, 'missingcomponent');
+            return false;
+        }
+
+        $this->versionphp['component'] = $info['plugin->component'];
+        list($reqtype, $reqname) = core_component::normalize_component($this->versionphp['component']);
+        if ($reqtype !== $this->assertions['plugintype']) {
+            $this->add_message(self::ERROR, 'componentmismatchtype', array(
+                'expected' => $this->assertions['plugintype'],
+                'found' => $reqtype));
+            return false;
+        }
+        if ($reqname !== $this->rootdir) {
+            $this->add_message(self::ERROR, 'componentmismatchname', $reqname);
+            return false;
         }
+        $this->add_message(self::INFO, 'componentmatch', $this->versionphp['component']);
 
         if (isset($info['plugin->maturity'])) {
             $this->versionphp['maturity'] = $info['plugin->maturity'];
index ade477a..4f869ca 100644 (file)
@@ -71,6 +71,9 @@ $string['validationmsg_filestatus_info'] = 'Attempting to extract file {$a->file
 $string['validationmsg_foundlangfile'] = 'Found language file';
 $string['validationmsg_maturity'] = 'Declared maturity level';
 $string['validationmsg_maturity_help'] = 'The plugin can declare its maturity level. If the maintainer considers the plugin stable, the declared maturity level will read MATURITY_STABLE. All other maturity levels (such as alpha or beta) should be considered unstable and a warning is raised.';
+$string['validationmsg_missingcomponent'] = 'Plugin does not declare its component name';
+$string['validationmsg_missingcomponent_help'] = 'All plugins must provide their full component name via the `$plugin->component` declaration in the version.php file.';
+$string['validationmsg_missingcomponent_link'] = 'Development:version.php';
 $string['validationmsg_missingexpectedlangenfile'] = 'English language file name mismatch';
 $string['validationmsg_missingexpectedlangenfile_info'] = 'The given plugin type is missing the expected English language file {$a}.';
 $string['validationmsg_missinglangenfile'] = 'No English language file found';
diff --git a/admin/tool/installaddon/tests/fixtures/nocomponent/baz/lang/en/auth_baz.php b/admin/tool/installaddon/tests/fixtures/nocomponent/baz/lang/en/auth_baz.php
new file mode 100644 (file)
index 0000000..4422fa6
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+
+$string['pluginname'] = 'This is a plugin with $plugin->component missing in its version.php';
diff --git a/admin/tool/installaddon/tests/fixtures/nocomponent/baz/version.php b/admin/tool/installaddon/tests/fixtures/nocomponent/baz/version.php
new file mode 100644 (file)
index 0000000..f87367e
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+$plugin->version = 2015080600;
+$plugin->release = 'B.A.Z. Auth fake plugin';
+//$plugin->component is missing here so the validation must fail.
diff --git a/admin/tool/installaddon/tests/fixtures/wronglang/bah/lang/en/bah.php b/admin/tool/installaddon/tests/fixtures/wronglang/bah/lang/en/bah.php
new file mode 100644 (file)
index 0000000..70668e8
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+
+$string['pluginname'] = 'This would be valid filename for module, not a block';
diff --git a/admin/tool/installaddon/tests/fixtures/wronglang/bah/version.php b/admin/tool/installaddon/tests/fixtures/wronglang/bah/version.php
new file mode 100644 (file)
index 0000000..a4fe771
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+
+$plugin->version = 2014122455;
+$plugin->component = 'block_bah';
index 709f2cc..44eb306 100644 (file)
@@ -145,6 +145,17 @@ class tool_installaddon_validator_testcase extends basic_testcase {
         $this->assertFalse($validator->execute());
         $this->assertTrue($this->has_message($validator->get_messages(), $validator::ERROR, 'versionphpsyntax', '$module'));
 
+        $validator = testable_tool_installaddon_validator::instance($fixtures.'/nocomponent', array(
+            'baz/' => true,
+            'baz/version.php' => true,
+            'baz/lang/' => true,
+            'baz/lang/en/' => true,
+            'baz/lang/en/auth_baz.php' => true));
+        $validator->assert_plugin_type('auth');
+        $validator->assert_moodle_version(0);
+        $this->assertFalse($validator->execute());
+        $this->assertTrue($this->has_message($validator->get_messages(), $validator::ERROR, 'missingcomponent'));
+
         $validator = testable_tool_installaddon_validator::instance($fixtures.'/plugindir', array(
             'foobar/' => true,
             'foobar/version.php' => true,
@@ -216,7 +227,7 @@ class tool_installaddon_validator_testcase extends basic_testcase {
         $this->assertTrue($this->has_message($validator->get_messages(), $validator::WARNING, 'multiplelangenfiles'));
         $this->assertTrue(is_null($validator->get_language_file_name()));
 
-        $validator = testable_tool_installaddon_validator::instance($fixtures.'/nolang', array(
+        $validator = testable_tool_installaddon_validator::instance($fixtures.'/wronglang', array(
             'bah/' => true,
             'bah/version.php' => true,
             'bah/lang/' => true,
index 4c22571..00f0c61 100644 (file)
@@ -24,6 +24,6 @@
 defined('MOODLE_INTERNAL') || die();
 
 $plugin->component  = 'tool_installaddon';
-$plugin->version    = 2015051100;
+$plugin->version    = 2015080601;
 $plugin->requires   = 2015050500;
 $plugin->maturity   = MATURITY_STABLE;