You are here

protected function EntityCrudHookTest::assertHookMessageOrder in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::assertHookMessageOrder()

Checks the order of CRUD hook execution messages.

Module entity_crud_hook_test implements all core entity CRUD hooks and stores a message for each in $GLOBALS['entity_crud_hook_test'].

Parameters

$messages: An array of plain-text messages in the order they should appear.

7 calls to EntityCrudHookTest::assertHookMessageOrder()
EntityCrudHookTest::testBlockHooks in core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php
Tests hook invocations for CRUD operations on blocks.
EntityCrudHookTest::testCommentHooks in core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php
Tests hook invocations for CRUD operations on comments.
EntityCrudHookTest::testFileHooks in core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php
Tests hook invocations for CRUD operations on files.
EntityCrudHookTest::testNodeHooks in core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php
Tests hook invocations for CRUD operations on nodes.
EntityCrudHookTest::testTaxonomyTermHooks in core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php
Tests hook invocations for CRUD operations on taxonomy terms.

... See full list

File

core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php, line 75

Class

EntityCrudHookTest
Tests the invocation of hooks when creating, inserting, loading, updating or deleting an entity.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function assertHookMessageOrder($messages) {
  $positions = [];
  foreach ($messages as $message) {

    // Verify that each message is found and record its position.
    $position = array_search($message, $GLOBALS['entity_crud_hook_test']);
    $this
      ->assertNotFalse($position, $message);
    $positions[] = $position;
  }

  // Sort the positions and ensure they remain in the same order.
  $sorted = $positions;
  sort($sorted);
  $this
    ->assertTrue($sorted == $positions, 'The hook messages appear in the correct order.');
}