1 field.test FieldBulkDeleteTestCase::checkHooksInvocations($expected_hooks, $actual_hooks)

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().

File

core/modules/field/tests/field.test, line 3252
Tests for field.module.

Class

FieldBulkDeleteTestCase
Unit test class for field bulk delete and batch purge functionality.

Code

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) {
        if ($actual_arguments[1] == $argument) {
          $found = TRUE;
          break;
        }
      }
      $this->assertTrue($found, "$hook() was called on expected argument");
    }
  }
}