MDL-24627 Unknown components are considered activity modules even if their name conta...
authorDavid Mudrak <david.mudrak@gmail.com>
Tue, 12 Oct 2010 12:56:59 +0000 (12:56 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Tue, 12 Oct 2010 12:56:59 +0000 (12:56 +0000)
lib/moodlelib.php
lib/simpletest/testmoodlelib.php

index 073cf57..96d46df 100644 (file)
@@ -6867,6 +6867,11 @@ function normalize_component($component) {
 
     } else {
         list($type, $plugin) = explode('_', $component, 2);
+        $plugintypes = get_plugin_types(false);
+        if ($type !== 'core' and !array_key_exists($type, $plugintypes)) {
+            $type   = 'mod';
+            $plugin = $component;
+        }
     }
 
     return array($type, $plugin);
index dcebab8..29e7328 100644 (file)
@@ -483,4 +483,39 @@ class moodlelib_test extends UnitTestCase {
         //set the timezone back to what it was
         $USER->timezone = $userstimezone;
     }
+
+    public function test_normalize_component() {
+
+        // moodle core
+        $this->assertEqual(normalize_component('moodle'), array('core', null));
+        $this->assertEqual(normalize_component('core'), array('core', null));
+
+        // moodle core subsystems
+        $this->assertEqual(normalize_component('admin'), array('core', 'admin'));
+        $this->assertEqual(normalize_component('core_admin'), array('core', 'admin'));
+
+        // activity modules and their subplugins
+        $this->assertEqual(normalize_component('workshop'), array('mod', 'workshop'));
+        $this->assertEqual(normalize_component('mod_workshop'), array('mod', 'workshop'));
+        $this->assertEqual(normalize_component('workshopform_accumulative'), array('workshopform', 'accumulative'));
+        $this->assertEqual(normalize_component('quiz'), array('mod', 'quiz'));
+        $this->assertEqual(normalize_component('quiz_grading'), array('quiz', 'grading'));
+        $this->assertEqual(normalize_component('data'), array('mod', 'data'));
+        $this->assertEqual(normalize_component('datafield_checkbox'), array('datafield', 'checkbox'));
+
+        // other plugin types
+        $this->assertEqual(normalize_component('auth_mnet'), array('auth', 'mnet'));
+        $this->assertEqual(normalize_component('enrol_self'), array('enrol', 'self'));
+        $this->assertEqual(normalize_component('block_html'), array('block', 'html'));
+        $this->assertEqual(normalize_component('block_mnet_hosts'), array('block', 'mnet_hosts'));
+        $this->assertEqual(normalize_component('local_amos'), array('local', 'amos'));
+
+        // unknown components are supposed to be activity modules
+        $this->assertEqual(normalize_component('whothefuckwouldcomewithsuchastupidnameofcomponent'),
+                array('mod', 'whothefuckwouldcomewithsuchastupidnameofcomponent'));
+        $this->assertEqual(normalize_component('whothefuck_wouldcomewithsuchastupidnameofcomponent'),
+                array('mod', 'whothefuck_wouldcomewithsuchastupidnameofcomponent'));
+        $this->assertEqual(normalize_component('whothefuck_would_come_withsuchastupidnameofcomponent'),
+                array('mod', 'whothefuck_would_come_withsuchastupidnameofcomponent'));
+    }
 }