function ModuleApiTest::testModuleImplements

Test module_implements() caching.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php, line 88
Definition of Drupal\system\Tests\Module\ModuleApiTest.

Class

ModuleApiTest
Unit tests for the module API.

Namespace

Drupal\system\Tests\Module

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
    ->drupalGet('');
  $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
    ->drupalCreateUser();
  $this
    ->drupalLogin($this->user);
  cache('bootstrap')
    ->delete('module_implements');
  $this
    ->drupalGet('');
  $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 = drupal_static('module_implements');
  $this
    ->assertTrue(in_array('module_test', $modules), 'Hook found.');
  $this
    ->assertEqual($static['test_hook']['module_test'], 'file', 'Include file detected.');
}