You are here

function FieldBulkDeleteTestCase::checkHooksInvocations in Drupal 7

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 FieldBulkDeleteTestCase::checkHooksInvocations()
FieldBulkDeleteTestCase::testPurgeField in modules/field/tests/field.test
Verify that fields are preserved and purged correctly as multiple instances are deleted and purged.
FieldBulkDeleteTestCase::testPurgeInstance in modules/field/tests/field.test
Verify that field data items and instances are purged when an instance is deleted.

File

modules/field/tests/field.test, line 3475
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");
    }
  }
}