MDL-24627 Unknown components are considered activity modules even if their name contains underscore

This commit is contained in:
David Mudrak 2010-10-12 12:56:59 +00:00
parent e54c41da0b
commit 8dfb8a0343
2 changed files with 40 additions and 0 deletions

View 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);

View 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'));
}
}