1 module.test ModuleUnitTest::testModuleImplements()

Test module_implements() caching.

File

core/modules/simpletest/tests/module.test, line 84
Tests for the module API.

Class

ModuleUnitTest
Unit tests for the module API.

Code

function testModuleImplements() {
  // Clear the cache.
  cache('bootstrap')->delete('module_implements');
  $this->assertFalse(cache('bootstrap')->get('module_implements'), 'The module implements cache is empty.');
  $this->backdropGet('');

  // The module_implements cache is written after delivering the page, so
  // allow a few seconds for it to be written to the cache.
  sleep(3);

  $this->assertTrue(cache('bootstrap')->get('module_implements'), 'The module implements cache is populated after requesting a page.');

  // Test again with an authenticated user.
  $this->user = $this->backdropCreateUser();
  $this->backdropLogin($this->user);
  cache('bootstrap')->delete('module_implements');
  $this->backdropGet('');
  sleep(3);
  $this->assertTrue(cache('bootstrap')->get('module_implements'), '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 = &backdrop_static('module_implements');
  $this->assertTrue(in_array('module_test', $modules), 'Hook found.');
  $this->assertEqual($static['test_hook']['module_test'], 'file', 'Include file detected.');
}