function LegacyHookTest::testLegacyHook

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Functional/Extension/LegacyHookTest.php \Drupal\Tests\system\Functional\Extension\LegacyHookTest::testLegacyHook()

Tests the LegacyHook attribute.

Attributes

#[IgnoreDeprecations]

File

core/modules/system/tests/src/Functional/Extension/LegacyHookTest.php, line 32

Class

LegacyHookTest
Tests the LegacyHook attribute.

Namespace

Drupal\Tests\system\Functional\Extension

Code

public function testLegacyHook() : void {
  $this->expectUserDeprecationMessage('Code in legacy_hook_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');
  // Calling legacy_hook_test1 leads to a fatal error so there's no need
  // for asserts to show it does not get called.
  \Drupal::moduleHandler()->invokeAll('test1');
  // Verify the module actually exists and works even with one LegacyHook.
  $result = \Drupal::moduleHandler()->invokeAll('test2');
  $this->assertSame([
    'ok',
  ], $result);
  \Drupal::moduleHandler()->invoke('legacy_hook_test', 'test1');
  $result = \Drupal::moduleHandler()->invoke('legacy_hook_test', 'test2');
  $this->assertSame('ok', $result);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.