From 62bb48c4efc1600269d76923e437c5854c08502e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 27 Nov 2010 20:41:38 +0000 Subject: - Patch #752226 by sun, carlos8f, JohnAlbin, chx: module_invoke() doesn't work with hooks placed in include files via hook_hook_info(). --- modules/simpletest/tests/module.test | 20 ++++++++++++++ modules/simpletest/tests/module_test.file.inc | 2 +- modules/simpletest/tests/module_test.module | 39 +++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) (limited to 'modules/simpletest/tests') diff --git a/modules/simpletest/tests/module.test b/modules/simpletest/tests/module.test index d3e3dbf1b..711a739ab 100644 --- a/modules/simpletest/tests/module.test +++ b/modules/simpletest/tests/module.test @@ -111,6 +111,26 @@ class ModuleUnitTest extends DrupalWebTestCase { $this->assertEqual($static['test_hook']['module_test'], 'file', 'Include file detected.'); } + /** + * Test that module_invoke() can load a hook defined in hook_hook_info(). + */ + function testModuleInvoke() { + module_enable(array('module_test'), FALSE); + $this->resetAll(); + $this->drupalGet('module-test/hook-dynamic-loading-invoke'); + $this->assertText('success!', t('module_invoke() dynamically loads a hook defined in hook_hook_info().')); + } + + /** + * Test that module_invoke_all() can load a hook defined in hook_hook_info(). + */ + function testModuleInvokeAll() { + module_enable(array('module_test'), FALSE); + $this->resetAll(); + $this->drupalGet('module-test/hook-dynamic-loading-invoke-all'); + $this->assertText('success!', t('module_invoke_all() dynamically loads a hook defined in hook_hook_info().')); + } + /** * Test dependency resolution. */ diff --git a/modules/simpletest/tests/module_test.file.inc b/modules/simpletest/tests/module_test.file.inc index f3c354f35..72210d768 100644 --- a/modules/simpletest/tests/module_test.file.inc +++ b/modules/simpletest/tests/module_test.file.inc @@ -10,5 +10,5 @@ * Implements hook_test_hook(). */ function module_test_test_hook() { - + return array('module_test' => 'success!'); } diff --git a/modules/simpletest/tests/module_test.module b/modules/simpletest/tests/module_test.module index b1f7361a0..d3f46e2cb 100644 --- a/modules/simpletest/tests/module_test.module +++ b/modules/simpletest/tests/module_test.module @@ -51,6 +51,45 @@ function module_test_hook_info() { return $hooks; } +/** + * Implements hook_menu(). + */ +function module_test_menu() { + $items['module-test/hook-dynamic-loading-invoke'] = array( + 'title' => 'Test hook dynamic loading (invoke)', + 'page callback' => 'module_test_hook_dynamic_loading_invoke', + 'access arguments' => array('access content'), + ); + $items['module-test/hook-dynamic-loading-invoke-all'] = array( + 'title' => 'Test hook dynamic loading (invoke_all)', + 'page callback' => 'module_test_hook_dynamic_loading_invoke_all', + 'access arguments' => array('access content'), + ); + return $items; +} + +/** + * Page callback for 'hook dynamic loading' test. + * + * If the hook is dynamically loaded correctly, the menu callback should + * return 'success!'. + */ +function module_test_hook_dynamic_loading_invoke() { + $result = module_invoke('module_test', 'test_hook'); + return $result['module_test']; +} + +/** + * Page callback for 'hook dynamic loading' test. + * + * If the hook is dynamically loaded correctly, the menu callback should + * return 'success!'. + */ +function module_test_hook_dynamic_loading_invoke_all() { + $result = module_invoke_all('test_hook'); + return $result['module_test']; +} + /** * Implements hook_modules_enabled(). */ -- cgit v1.2.3