function ModuleUnitTest::testModuleImplements in Drupal 7
Test module_implements() caching.
File
- modules/
simpletest/ tests/ module.test, line 87 - Tests for the module API.
Class
- ModuleUnitTest
- Unit tests for the module API.
Code
function testModuleImplements() {
// Clear the cache.
cache_clear_all('module_implements', 'cache_bootstrap');
$this
->assertFalse(cache_get('module_implements', 'cache_bootstrap'), 'The module implements cache is empty.');
$this
->drupalGet('');
$this
->assertTrue(cache_get('module_implements', 'cache_bootstrap'), 'The module implements cache is populated after requesting a page.');
// Test again with an authenticated user.
$this->user = $this
->drupalCreateUser();
$this
->drupalLogin($this->user);
cache_clear_all('module_implements', 'cache_bootstrap');
$this
->drupalGet('');
$this
->assertTrue(cache_get('module_implements', 'cache_bootstrap'), 'The module implements cache is populated after requesting a page.');
// Make sure group include files are detected properly even when the file is
// already loaded when the cache is rebuilt.
// For that activate the module_test which provides the file to load.
module_enable(array(
'module_test',
));
module_load_include('inc', 'module_test', 'module_test.file');
$modules = module_implements('test_hook');
$static = drupal_static('module_implements');
$this
->assertTrue(in_array('module_test', $modules), 'Hook found.');
$this
->assertEqual($static['test_hook']['module_test'], 'file', 'Include file detected.');
}