function HookCollectorPassTest::testPrefixOwnership
Tests prefix ownership of procedural hooks.
@legacy-covers ::process @legacy-covers ::collectModuleHookImplementations
File
-
core/
tests/ Drupal/ Tests/ Core/ Hook/ HookCollectorPassTest.php, line 100
Class
Namespace
Drupal\Tests\Core\HookCode
public function testPrefixOwnership() : void {
vfsStream::setup('drupal_root');
$files = [
'modules/test_module/test_module.info.yml',
'modules/test_module_theme/test_module_theme.info.yml',
];
$file_data = [];
foreach ($files as &$filename) {
NestedArray::setValue($file_data, explode('/', $filename), '');
}
vfsStream::create($file_data);
$module_filenames = [
'test_module' => [
'pathname' => 'vfs://drupal_root/modules/test_module/test_module.info.yml',
],
'test_module_theme' => [
'pathname' => 'vfs://drupal_root/modules/test_module_theme/test_module_theme.info.yml',
],
];
file_put_contents('vfs://drupal_root/modules/test_module/test_module.module', <<<__EOF__
<?php
function test_module_theme_suggestions_alter();
__EOF__);
$implementations['theme_suggestions_alter'][ProceduralCall::class]['test_module_theme_suggestions_alter'] = 'test_module';
$container = new ContainerBuilder();
$container->setParameter('container.modules', $module_filenames);
$container->setDefinition('module_handler', new Definition());
(new HookCollectorPass())->process($container);
// Ensure that the hook is registered for the module it resides in.
// Even though there is a more specific match the current module takes
// precedence.
$this->assertSame($implementations, $container->getParameter('hook_implementations_map'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.