Verified Commit a52573d8 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

fix: #3120298 Add test coverage of alter hooks when there is no base alter

By: mxr576
By: jungle
By: andyf
By: zengenuity
By: swentel
By: donquixote
By: nicxvan
By: quietone
parent 30fe89a1
Loading
Loading
Loading
Loading
Loading
+10 −0
Changes for core/modules/system/tests/modules/HookOrder/aaa_hook_order_test/src/Hook/AAlterHooks.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -39,4 +39,14 @@ public function testSubtypeAlter(array &$calls): void {
    $calls[] = __METHOD__;
  }

  /**
   * Implements hook_test_no_base_subtype_alter().
   *
   * This implementation has no ordering modifications.
   */
  #[Hook('test_no_base_subtype_alter')]
  public function testNoBaseSubtypeAlter(array &$calls): void {
    $calls[] = __METHOD__;
  }

}
+12 −0
Changes for core/modules/system/tests/modules/HookOrder/ddd_hook_order_test/src/Hook/DAlterHooks.php: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
namespace Drupal\ddd_hook_order_test\Hook;

use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Hook\Order\OrderBefore;

/**
 * This class contains hook implementations.
@@ -36,4 +37,15 @@ public function testSubtypeAlter(array &$calls): void {
    $calls[] = __METHOD__;
  }

  /**
   * Implements hook_test_no_base_subtype_alter().
 *
   * This implementation changes its order to be before the hooks in module
   * 'aaa_hook_order_test'.
   */
  #[Hook('test_no_base_subtype_alter', order: new OrderBefore(modules: ['aaa_hook_order_test']))]
  public function testNoBaseSubtypeAlter(array &$calls): void {
    $calls[] = __METHOD__;
  }

}
+7 −0
Changes for core/tests/Drupal/KernelTests/Core/Hook/HookAlterOrderTest.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -91,6 +91,13 @@ public function testAlterOrder(): void {
      DAlterHooks::class . '::testAlter',
      DAlterHooks::class . '::testSubtypeAlter',
    ], ['test', 'test_subtype']);

    // Tests when a hook for a subtype is implemented but a hook is not
    // implemented for the base alter.
    $this->assertAlterCallOrder([
      DAlterHooks::class . '::testNoBaseSubtypeAlter',
      AAlterHooks::class . '::testNoBaseSubtypeAlter',
    ], ['test_no_base', 'test_no_base_subtype']);
  }

  /**