diff --git a/core/modules/system/tests/modules/deprecation_test/deprecation_test.module b/core/modules/system/tests/modules/deprecation_test/deprecation_test.module index e255021d65..69217db45e 100644 --- a/core/modules/system/tests/modules/deprecation_test/deprecation_test.module +++ b/core/modules/system/tests/modules/deprecation_test/deprecation_test.module @@ -18,3 +18,17 @@ function deprecation_test_function() { @trigger_error('This is the deprecation message for deprecation_test_function().', E_USER_DEPRECATED); return 'known_return_value'; } + +/** + * Implements hook_deprecated_hook(). + */ +function deprecation_test_deprecated_hook($arg) { + return $arg; +} + +/** + * Implements hook_deprecated_alter_alter(). + */ +function deprecation_test_deprecated_alter_alter(&$data, $context1, $context2) { + $data = [$context1, $context2]; +} diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerDeprecatedTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerDeprecatedTest.php new file mode 100644 index 0000000000..0e923ff7dd --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerDeprecatedTest.php @@ -0,0 +1,61 @@ +container->get('module_handler'); + $arg = 'an_arg'; + $this->assertEqual( + $arg, + $module_handler->invokeDeprecated('deprecation_test', 'deprecated_hook', [$arg]) + ); + } + + /** + * @covers ::invokeAllDeprecated + * @expectedDeprecation The deprecated hook hook_deprecated_hook() is implemented in these functions: deprecation_test_deprecated_hook() + */ + public function testInvokeAllDeprecated() { + /* @var $module_handler \Drupal\Core\Extension\ModuleHandlerInterface */ + $module_handler = $this->container->get('module_handler'); + $arg = 'an_arg'; + $this->assertEqual( + [$arg], + $module_handler->invokeAllDeprecated('deprecated_hook', [$arg]) + ); + } + + /** + * @covers ::alterDeprecated + * @expectedDeprecation The deprecated alter hook hook_deprecated_alter_alter() is implemented in these functions: deprecation_test_deprecated_alter_alter + */ + public function testAlterDeprecated() { + /* @var $module_handler \Drupal\Core\Extension\ModuleHandlerInterface */ + $module_handler = $this->container->get('module_handler'); + $data = []; + $context1 = 'test1'; + $context2 = 'test2'; + $module_handler->alterDeprecated('deprecated_alter', $data, $context1, $context2); + $this->assertEqual([$context1, $context2], $data); + } + +}