class HookCollectorPassTest
Same name in this branch
- main core/modules/system/tests/src/Functional/Hook/HookCollectorPassTest.php \Drupal\Tests\system\Functional\Hook\HookCollectorPassTest
- main core/tests/Drupal/KernelTests/Core/Hook/HookCollectorPassTest.php \Drupal\KernelTests\Core\Hook\HookCollectorPassTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Hook/HookCollectorPassTest.php \Drupal\Tests\system\Functional\Hook\HookCollectorPassTest
- 11.x core/tests/Drupal/KernelTests/Core/Hook/HookCollectorPassTest.php \Drupal\KernelTests\Core\Hook\HookCollectorPassTest
- 11.x core/tests/Drupal/Tests/Core/Hook/HookCollectorPassTest.php \Drupal\Tests\Core\Hook\HookCollectorPassTest
Tests Drupal\Core\Hook\HookCollectorPass.
Attributes
#[CoversClass(HookCollectorPass::class)]
#[Group('Hook')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Hook\HookCollectorPassTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of HookCollectorPassTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Hook/ HookCollectorPassTest.php, line 19
Namespace
Drupal\Tests\Core\HookView source
class HookCollectorPassTest extends UnitTestCase {
/**
* Tests collect all hook implementations.
*
* @legacy-covers ::collectAllHookImplementations
* @legacy-covers ::filterIterator
*/
public function testCollectAllHookImplementations() : void {
vfsStream::setup('drupal_root');
$files = [
'modules/test_module/test_module_info.yml',
// This creates a submodule which is not installed.
'modules/test_module/test_sub_module/test_sub_module.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',
],
];
file_put_contents('vfs://drupal_root/modules/test_module/test_module.module', <<<__EOF__
<?php
function test_module_test_hook();
__EOF__);
// This is the not installed submodule.
file_put_contents('vfs://drupal_root/modules/test_module/test_sub_module/test_sub_module.module', <<<__EOF__
<?php
function test_module_should_be_skipped();
__EOF__);
$container = new ContainerBuilder();
$container->setParameter('container.modules', $module_filenames);
(new HookCollectorPass())->process($container);
$this->assertEquals([
'test_module_test_hook' => 'test_module',
], $container->getParameter('.hook_data')['hook_list']['test_hook']);
}
/**
* Tests prefix ownership of procedural hooks.
*
* @legacy-covers ::process
* @legacy-covers ::collectModuleHookImplementations
*/
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);
(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->assertEquals([
'test_module_theme_suggestions_alter' => 'test_module',
], $container->getParameter('.hook_data')['hook_list']['theme_suggestions_alter']);
}
}
Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|---|
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | ||
| ExpectDeprecationTrait::expectDeprecation | Deprecated | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::regularExpressionForFormatDescription | private | function | |||
| HookCollectorPassTest::testCollectAllHookImplementations | public | function | Tests collect all hook implementations. | ||
| HookCollectorPassTest::testPrefixOwnership | public | function | Tests prefix ownership of procedural hooks. | ||
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | ||
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | ||
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | ||
| UnitTestCase::$root | protected | property | The app root. | ||
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | ||
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | ||
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | ||
| UnitTestCase::setUp | protected | function | 366 | ||
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.