diff options
author | David Rothstein <drothstein@gmail.com> | 2015-10-05 15:59:32 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2015-10-05 15:59:32 -0400 |
commit | 3c8b182b79850c497b24c79c1c3e56999b3da12a (patch) | |
tree | 9f55ff8da822d17bfa3f3639adab345c23b2792d /modules/simpletest | |
parent | c9d188950508f104a8115ec7a78335607d9b6037 (diff) | |
download | brdo-3c8b182b79850c497b24c79c1c3e56999b3da12a.tar.gz brdo-3c8b182b79850c497b24c79c1c3e56999b3da12a.tar.bz2 |
Issue #2263365 by donquixote, smccabe, longwave, alexpott, joelpittet, Fabianx, mikeytown2, joseph.olstad, sun: Second loop in module_implements() was being repeated for no reason (performance improvement)
Diffstat (limited to 'modules/simpletest')
-rw-r--r-- | modules/simpletest/tests/module.test | 42 | ||||
-rw-r--r-- | modules/simpletest/tests/module_test.implementations.inc | 10 | ||||
-rw-r--r-- | modules/simpletest/tests/module_test.module | 11 |
3 files changed, 63 insertions, 0 deletions
diff --git a/modules/simpletest/tests/module.test b/modules/simpletest/tests/module.test index 371339f3c..eea3b51e9 100644 --- a/modules/simpletest/tests/module.test +++ b/modules/simpletest/tests/module.test @@ -302,3 +302,45 @@ class ModuleUninstallTestCase extends DrupalWebTestCase { $this->assertEqual(0, $count, 'Permissions were all removed.'); } } + +class ModuleImplementsAlterTestCase extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Module implements alter', + 'description' => 'Tests hook_module_implements_alter().', + 'group' => 'Module', + ); + } + + /** + * Tests hook_module_implements_alter() adding an implementation. + */ + function testModuleImplementsAlter() { + module_enable(array('module_test'), FALSE); + $this->assertTrue(module_exists('module_test'), 'Test module is enabled.'); + + // Assert that module_test.module is now included. + $this->assertTrue(function_exists('module_test_permission'), + 'The file module_test.module was successfully included.'); + + $modules = module_implements('permission'); + $this->assertTrue(in_array('module_test', $modules), 'module_test implements hook_permission.'); + + $modules = module_implements('module_implements_alter'); + $this->assertTrue(in_array('module_test', $modules), 'module_test implements hook_module_implements_alter().'); + + // Assert that module_test.implementations.inc is not included yet. + $this->assertFalse(function_exists('module_test_altered_test_hook'), + 'The file module_test.implementations.inc is not included yet.'); + + // Assert that module_test_module_implements_alter(*, 'altered_test_hook') + // has added an implementation + $this->assertTrue(in_array('module_test', module_implements('altered_test_hook')), + 'module_test implements hook_altered_test_hook().'); + + // Assert that module_test.implementations.inc was included as part of the process. + $this->assertTrue(function_exists('module_test_altered_test_hook'), + 'The file module_test.implementations.inc was included.'); + } + +} diff --git a/modules/simpletest/tests/module_test.implementations.inc b/modules/simpletest/tests/module_test.implementations.inc new file mode 100644 index 000000000..63c866ea1 --- /dev/null +++ b/modules/simpletest/tests/module_test.implementations.inc @@ -0,0 +1,10 @@ +<?php + +/** + * Implements hook_altered_test_hook() + * + * @see module_test_module_implements_alter() + */ +function module_test_altered_test_hook() { + return __FUNCTION__; +} diff --git a/modules/simpletest/tests/module_test.module b/modules/simpletest/tests/module_test.module index d781350b3..60c0d799b 100644 --- a/modules/simpletest/tests/module_test.module +++ b/modules/simpletest/tests/module_test.module @@ -129,3 +129,14 @@ function module_test_modules_uninstalled($modules) { // can check that the modules were uninstalled in the correct sequence. variable_set('test_module_uninstall_order', $modules); } + +/** + * Implements hook_module_implements_alter() + */ +function module_test_module_implements_alter(&$implementations, $hook) { + if ($hook === 'altered_test_hook') { + // Add a hook implementation, that will be found in + // module_test.implementations.inc. + $implementations['module_test'] = 'implementations'; + } +} |