function HookAlterOrderTest::testAlterOrder
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Hook/HookAlterOrderTest.php \Drupal\KernelTests\Core\Hook\HookAlterOrderTest::testAlterOrder()
Test ordering alter calls.
Attributes
#[IgnoreDeprecations]
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Hook/ HookAlterOrderTest.php, line 45
Class
- HookAlterOrderTest
- Tests Hook Alter Order.
Namespace
Drupal\KernelTests\Core\HookCode
public function testAlterOrder() : void {
$this->expectUserDeprecationMessage('Code in aaa_hook_order_test.module is deprecated in drupal:11.5.0 and must be converted before drupal:13.0.0. Use classes instead. See https://www.drupal.org/node/3619765');
$this->expectUserDeprecationMessage('Code in bbb_hook_order_test.module is deprecated in drupal:11.5.0 and must be converted before drupal:13.0.0. Use classes instead. See https://www.drupal.org/node/3619765');
$this->expectUserDeprecationMessage('Code in ccc_hook_order_test.module is deprecated in drupal:11.5.0 and must be converted before drupal:13.0.0. Use classes instead. See https://www.drupal.org/node/3619765');
$this->expectUserDeprecationMessage('Code in ddd_hook_order_test.module is deprecated in drupal:11.5.0 and must be converted before drupal:13.0.0. Use classes instead. See https://www.drupal.org/node/3619765');
// The default ordering of test_alter hooks.
$this->assertAlterCallOrder([
CAlterHooks::class . '::testAlter',
AAlterHooks::class . '::testAlterAfterC',
DAlterHooks::class . '::testAlter',
], 'test');
// The default ordering of test_subtype_alter hooks.
$this->assertAlterCallOrder([
AAlterHooks::class . '::testSubtypeAlter',
BAlterHooks::class . '::testSubtypeAlter',
CAlterHooks::class . '::testSubtypeAlter',
DAlterHooks::class . '::testSubtypeAlter',
], 'test_subtype');
// Test ordering of both test_alter and test_subtype_alter hooks.
$this->assertAlterCallOrder([
AAlterHooks::class . '::testSubtypeAlter',
BAlterHooks::class . '::testSubtypeAlter',
CAlterHooks::class . '::testAlter',
CAlterHooks::class . '::testSubtypeAlter',
AAlterHooks::class . '::testAlterAfterC',
DAlterHooks::class . '::testAlter',
DAlterHooks::class . '::testSubtypeAlter',
], [
'test',
'test_subtype',
]);
$this->disableModules([
'bbb_hook_order_test',
]);
// Confirm that hooks from bbb_hook_order_test are absent.
$this->assertAlterCallOrder([
CAlterHooks::class . '::testAlter',
AAlterHooks::class . '::testAlterAfterC',
DAlterHooks::class . '::testAlter',
], 'test');
$this->assertAlterCallOrder([
AAlterHooks::class . '::testSubtypeAlter',
CAlterHooks::class . '::testSubtypeAlter',
DAlterHooks::class . '::testSubtypeAlter',
], 'test_subtype');
$this->assertAlterCallOrder([
AAlterHooks::class . '::testSubtypeAlter',
CAlterHooks::class . '::testAlter',
CAlterHooks::class . '::testSubtypeAlter',
AAlterHooks::class . '::testAlterAfterC',
DAlterHooks::class . '::testAlter',
DAlterHooks::class . '::testSubtypeAlter',
], [
'test',
'test_subtype',
]);
// Tests when a hook for a subtype is implemented but a hook is not
// implemented for the base alter.
$this->assertAlterCallOrder([
DAlterHooks::class . '::testNoBaseSubtypeAlter',
AAlterHooks::class . '::testNoBaseSubtypeAlter',
], [
'test_no_base',
'test_no_base_subtype',
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.