function LegacyHookTest::testLegacyHook

Tests the LegacyHook attribute.

File

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

Class

LegacyHookTest
Tests the LegacyHook attribute.

Namespace

Drupal\Tests\system\Functional\Extension

Code

public function testLegacyHook() : void {
  // 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.