18245634acbf34b7a95ed16da4edf9c23fa579aa
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Extension / ModuleHandlerDeprecatedHookTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Extension;
4
5 use Drupal\KernelTests\KernelTestBase;
6
7 /**
8  * Test whether deprecated hook invocations trigger errors.
9  *
10  * @group Extension
11  * @group legacy
12  *
13  * @coversDefaultClass Drupal\Core\Extension\ModuleHandler
14  */
15 class ModuleHandlerDeprecatedHookTest extends KernelTestBase {
16
17   protected static $modules = ['deprecation_test'];
18
19   /**
20    * @covers ::invokeDeprecated
21    * @expectedDeprecation The deprecated hook hook_deprecated_hook() is implemented in these functions: deprecation_test_deprecated_hook(). Use something else.
22    */
23   public function testInvokeDeprecated() {
24     /* @var $module_handler \Drupal\Core\Extension\ModuleHandlerInterface */
25     $module_handler = $this->container->get('module_handler');
26     $arg = 'an_arg';
27     $this->assertEqual(
28       $arg,
29       $module_handler->invokeDeprecated('Use something else.', 'deprecation_test', 'deprecated_hook', [$arg])
30     );
31   }
32
33   /**
34    * @covers ::invokeAllDeprecated
35    * @expectedDeprecation The deprecated hook hook_deprecated_hook() is implemented in these functions: deprecation_test_deprecated_hook(). Use something else.
36    */
37   public function testInvokeAllDeprecated() {
38     /* @var $module_handler \Drupal\Core\Extension\ModuleHandlerInterface */
39     $module_handler = $this->container->get('module_handler');
40     $arg = 'an_arg';
41     $this->assertEqual(
42       [$arg],
43       $module_handler->invokeAllDeprecated('Use something else.', 'deprecated_hook', [$arg])
44     );
45   }
46
47   /**
48    * @covers ::alterDeprecated
49    * @expectedDeprecation The deprecated alter hook hook_deprecated_alter_alter() is implemented in these functions: deprecation_test_deprecated_alter_alter. Alter something else.
50    */
51   public function testAlterDeprecated() {
52     /* @var $module_handler \Drupal\Core\Extension\ModuleHandlerInterface */
53     $module_handler = $this->container->get('module_handler');
54     $data = [];
55     $context1 = 'test1';
56     $context2 = 'test2';
57     $module_handler->alterDeprecated('Alter something else.', 'deprecated_alter', $data, $context1, $context2);
58     $this->assertEqual([$context1, $context2], $data);
59   }
60
61 }