You are here

public function BulkDeleteTest::checkHooksInvocations in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/BulkDeleteTest.php \Drupal\Tests\field\Kernel\BulkDeleteTest::checkHooksInvocations()

Tests that the expected hooks have been invoked on the expected entities.

Parameters

$expected_hooks: An array keyed by hook name, with one entry per expected invocation. Each entry is the value of the "$entity" parameter the hook is expected to have been passed.

$actual_hooks: The array of actual hook invocations recorded by field_test_memorize().

2 calls to BulkDeleteTest::checkHooksInvocations()
BulkDeleteTest::testPurgeField in core/modules/field/tests/src/Kernel/BulkDeleteTest.php
Verify that field data items and fields are purged when a field storage is deleted.
BulkDeleteTest::testPurgeFieldStorage in core/modules/field/tests/src/Kernel/BulkDeleteTest.php
Verify that field storages are preserved and purged correctly as multiple fields are deleted and purged.

File

core/modules/field/tests/src/Kernel/BulkDeleteTest.php, line 62

Class

BulkDeleteTest
Bulk delete storages and fields, and clean up afterwards.

Namespace

Drupal\Tests\field\Kernel

Code

public function checkHooksInvocations($expected_hooks, $actual_hooks) {
  foreach ($expected_hooks as $hook => $invocations) {
    $actual_invocations = $actual_hooks[$hook];

    // Check that the number of invocations is correct.
    $this
      ->assertEqual(count($actual_invocations), count($invocations), "{$hook}() was called the expected number of times.");

    // Check that the hook was called for each expected argument.
    foreach ($invocations as $argument) {
      $found = FALSE;
      foreach ($actual_invocations as $actual_arguments) {

        // The argument we are looking for is either an array of entities as
        // the second argument or a single entity object as the first.
        if ($argument instanceof EntityInterface && $actual_arguments[0]
          ->id() == $argument
          ->id()) {
          $found = TRUE;
          break;
        }
        elseif (is_array($argument) && count($actual_arguments[1]) == count($argument) && count(array_diff_key($actual_arguments[1], $argument)) == 0) {
          $found = TRUE;
          break;
        }
      }
      $this
        ->assertTrue($found, "{$hook}() was called on expected argument");
    }
  }
}