function ModuleHandlerTest::testImplementsHookModuleEnabled

Tests implementations methods when module is enabled.

@legacy-covers ::hasImplementations

File

core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php, line 361

Class

ModuleHandlerTest
Tests Drupal\Core\Extension\ModuleHandler.

Namespace

Drupal\Tests\Core\Extension

Code

public function testImplementsHookModuleEnabled() : void {
  $implementations = [
    'hook' => [
      'module_handler_test_hook' => 'module_handler_test',
      'module_handler_test_added_hook' => 'module_handler_test_added',
    ],
  ];
  $moduleList = [
    'module_handler_test_added' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added',
    'module_handler_test_no_hook' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_no_hook',
  ];
  $includes_per_function = [
    'hook' => [
      'module_handler_test_added_hook' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added/module_handler_test_added.hook.inc',
    ],
  ];
  $module_handler = $this->getModuleHandler($moduleList, $implementations, $includes_per_function);
  $this->assertTrue($module_handler->hasImplementations('hook', 'module_handler_test'), 'Installed module implementation found.');
  $this->assertTrue($module_handler->hasImplementations('hook', 'module_handler_test_added'), 'Runtime added module with implementation in include found.');
  $this->assertFalse($module_handler->hasImplementations('hook', 'module_handler_test_no_hook'), 'Missing implementation not found.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.