Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Extension / ModuleHandlerDeprecatedHookTest.php
diff --git a/web/core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerDeprecatedHookTest.php b/web/core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerDeprecatedHookTest.php
new file mode 100644 (file)
index 0000000..1824563
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+namespace Drupal\KernelTests\Core\Extension;
+
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * Test whether deprecated hook invocations trigger errors.
+ *
+ * @group Extension
+ * @group legacy
+ *
+ * @coversDefaultClass Drupal\Core\Extension\ModuleHandler
+ */
+class ModuleHandlerDeprecatedHookTest extends KernelTestBase {
+
+  protected static $modules = ['deprecation_test'];
+
+  /**
+   * @covers ::invokeDeprecated
+   * @expectedDeprecation The deprecated hook hook_deprecated_hook() is implemented in these functions: deprecation_test_deprecated_hook(). Use something else.
+   */
+  public function testInvokeDeprecated() {
+    /* @var $module_handler \Drupal\Core\Extension\ModuleHandlerInterface */
+    $module_handler = $this->container->get('module_handler');
+    $arg = 'an_arg';
+    $this->assertEqual(
+      $arg,
+      $module_handler->invokeDeprecated('Use something else.', 'deprecation_test', 'deprecated_hook', [$arg])
+    );
+  }
+
+  /**
+   * @covers ::invokeAllDeprecated
+   * @expectedDeprecation The deprecated hook hook_deprecated_hook() is implemented in these functions: deprecation_test_deprecated_hook(). Use something else.
+   */
+  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('Use something else.', 'deprecated_hook', [$arg])
+    );
+  }
+
+  /**
+   * @covers ::alterDeprecated
+   * @expectedDeprecation The deprecated alter hook hook_deprecated_alter_alter() is implemented in these functions: deprecation_test_deprecated_alter_alter. Alter something else.
+   */
+  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('Alter something else.', 'deprecated_alter', $data, $context1, $context2);
+    $this->assertEqual([$context1, $context2], $data);
+  }
+
+}