function EntityCrudHookTest::assertHookMessageOrder

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::assertHookMessageOrder()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php \Drupal\KernelTests\Core\Entity\EntityCrudHookTest::assertHookMessageOrder()
  3. 10 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'].

@internal

Parameters

array $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 80

Class

EntityCrudHookTest
Tests entity CRUD via hooks.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function assertHookMessageOrder(array $messages) : void {
    $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->assertSame($positions, $sorted, 'The hook messages appear in the correct order.');
}

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