2009-01-03 08:45:28 +00:00
|
|
|
<?php
|
2009-04-26 15:14:55 +00:00
|
|
|
// $Id$
|
2009-01-03 08:45:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Tests for the module API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the module API.
|
|
|
|
*/
|
|
|
|
class ModuleUnitTest extends DrupalWebTestCase {
|
2009-03-31 01:49:55 +00:00
|
|
|
public static function getInfo() {
|
2009-01-03 08:45:28 +00:00
|
|
|
return array(
|
2009-07-13 21:51:42 +00:00
|
|
|
'name' => 'Module API',
|
|
|
|
'description' => 'Test low-level module functions.',
|
|
|
|
'group' => 'Module',
|
2009-01-03 08:45:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The basic functionality of module_list().
|
|
|
|
*/
|
|
|
|
function testModuleList() {
|
2009-06-20 06:00:24 +00:00
|
|
|
// Build a list of modules, sorted alphabetically.
|
2009-07-19 04:48:10 +00:00
|
|
|
$profile_info = install_profile_info('default', 'en');
|
|
|
|
$module_list = $profile_info['dependencies'];
|
2009-08-21 07:50:08 +00:00
|
|
|
|
|
|
|
// Install profile is a module that is expected to be loaded.
|
|
|
|
$module_list[] = 'default';
|
|
|
|
|
2009-06-20 06:00:24 +00:00
|
|
|
sort($module_list);
|
|
|
|
// Compare this list to the one returned by module_list(). We expect them
|
|
|
|
// to match, since all default profile modules have a weight equal to 0
|
|
|
|
// (except for block.module, which has a lower weight but comes first in
|
|
|
|
// the alphabet anyway).
|
2009-06-12 08:39:40 +00:00
|
|
|
$this->assertModuleList($module_list, t('Default profile'));
|
2009-01-03 08:45:28 +00:00
|
|
|
|
|
|
|
// Try to install a new module.
|
2009-06-20 06:00:24 +00:00
|
|
|
drupal_install_modules(array('contact'));
|
|
|
|
$module_list[] = 'contact';
|
|
|
|
sort($module_list);
|
2009-06-12 08:39:40 +00:00
|
|
|
$this->assertModuleList($module_list, t('After adding a module'));
|
2009-01-03 08:45:28 +00:00
|
|
|
|
|
|
|
// Try to mess with the module weights.
|
2009-05-30 11:17:32 +00:00
|
|
|
db_update('system')
|
|
|
|
->fields(array('weight' => 20))
|
2009-06-20 06:00:24 +00:00
|
|
|
->condition('name', 'contact')
|
2009-05-30 11:17:32 +00:00
|
|
|
->condition('type', 'module')
|
|
|
|
->execute();
|
2009-01-03 08:45:28 +00:00
|
|
|
// Reset the module list.
|
|
|
|
module_list(TRUE);
|
2009-06-20 06:00:24 +00:00
|
|
|
// Move contact to the end of the array.
|
|
|
|
unset($module_list[array_search('contact', $module_list)]);
|
|
|
|
$module_list[] = 'contact';
|
2009-06-12 08:39:40 +00:00
|
|
|
$this->assertModuleList($module_list, t('After changing weights'));
|
2009-01-03 08:45:28 +00:00
|
|
|
|
|
|
|
// Test the fixed list feature.
|
|
|
|
$fixed_list = array(
|
|
|
|
'system' => array('filename' => drupal_get_path('module', 'system')),
|
|
|
|
'menu' => array('filename' => drupal_get_path('module', 'menu')),
|
|
|
|
);
|
2009-08-24 00:10:46 +00:00
|
|
|
module_list(FALSE, FALSE, $fixed_list);
|
2009-01-03 08:45:28 +00:00
|
|
|
$new_module_list = array_combine(array_keys($fixed_list), array_keys($fixed_list));
|
|
|
|
$this->assertModuleList($new_module_list, t('When using a fixed list'));
|
|
|
|
|
|
|
|
// Reset the module list.
|
|
|
|
module_list(TRUE);
|
2009-06-12 08:39:40 +00:00
|
|
|
$this->assertModuleList($module_list, t('After reset'));
|
2009-01-03 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that module_list() return the expected values.
|
|
|
|
*
|
|
|
|
* @param $expected_values
|
2009-06-20 06:00:24 +00:00
|
|
|
* The expected values, sorted by weight and module name.
|
2009-01-03 08:45:28 +00:00
|
|
|
*/
|
|
|
|
protected function assertModuleList(Array $expected_values, $condition) {
|
2009-06-12 08:39:40 +00:00
|
|
|
$expected_values = array_combine($expected_values, $expected_values);
|
2009-01-03 08:45:28 +00:00
|
|
|
$this->assertIdentical($expected_values, module_list(), t('@condition: module_list() returns correct results', array('@condition' => $condition)));
|
|
|
|
ksort($expected_values);
|
2009-08-24 00:10:46 +00:00
|
|
|
$this->assertIdentical($expected_values, module_list(FALSE, TRUE), t('@condition: module_list() returns correctly sorted results', array('@condition' => $condition)));
|
2009-01-03 08:45:28 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-01 08:39:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for module uninstallation and related hooks.
|
|
|
|
*/
|
|
|
|
class ModuleUninstallTestCase extends DrupalWebTestCase {
|
|
|
|
public static function getInfo() {
|
|
|
|
return array(
|
2009-07-13 21:51:42 +00:00
|
|
|
'name' => 'Module uninstallation',
|
|
|
|
'description' => 'Checks module uninstallation',
|
|
|
|
'group' => 'Module',
|
2009-07-01 08:39:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp('module_test', 'user');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests the hook_modules_uninstalled() of the user module.
|
|
|
|
*/
|
|
|
|
function testUserPermsUninstalled() {
|
|
|
|
// Uninstalls the module_test module, so hook_modules_uninstalled()
|
|
|
|
// is executed.
|
|
|
|
drupal_uninstall_modules(array('module_test'));
|
|
|
|
|
|
|
|
// Are the perms defined by module_test removed from {role_permission}.
|
|
|
|
$count = db_query("SELECT COUNT(rid) FROM {role_permission} WHERE permission = :perm", array(':perm' => 'module_test perm'))->fetchField();
|
|
|
|
$this->assertEqual(0, $count, t('Permissions were all removed.'));
|
|
|
|
}
|
|
|
|
}
|