function FileManagedTestBase::assertFileHooksCalled

Assert that all of the specified hook_file_* hooks were called once, other values result in failure.

Parameters

$expected: Array with string containing with the hook name, e.g. 'load', 'save', 'insert', etc.

29 calls to FileManagedTestBase::assertFileHooksCalled()
CopyTest::testExistingError in drupal/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
Test that copying over an existing file fails when FILE_EXISTS_ERROR is specified.
CopyTest::testExistingRename in drupal/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
Test renaming when copying over a file that already exists.
CopyTest::testExistingReplace in drupal/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
Test replacement when copying over a file that already exists.
CopyTest::testNormal in drupal/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
Test file copying in the normal, base case.
DeleteTest::testInUse in drupal/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php
Tries deleting a file that is in use.

... See full list

File

drupal/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php, line 40
Definition of Drupal\file\Tests\FileManagedTestBase.

Class

FileManagedTestBase
Base class for file tests that use the file_test module to test uploads and hooks.

Namespace

Drupal\file\Tests

Code

function assertFileHooksCalled($expected) {

  // Determine which hooks were called.
  $actual = array_keys(array_filter(file_test_get_all_calls()));

  // Determine if there were any expected that were not called.
  $uncalled = array_diff($expected, $actual);
  if (count($uncalled)) {
    $this
      ->assertTrue(FALSE, t('Expected hooks %expected to be called but %uncalled was not called.', array(
      '%expected' => implode(', ', $expected),
      '%uncalled' => implode(', ', $uncalled),
    )));
  }
  else {
    $this
      ->assertTrue(TRUE, t('All the expected hooks were called: %expected', array(
      '%expected' => empty($expected) ? t('(none)') : implode(', ', $expected),
    )));
  }

  // Determine if there were any unexpected calls.
  $unexpected = array_diff($actual, $expected);
  if (count($unexpected)) {
    $this
      ->assertTrue(FALSE, t('Unexpected hooks were called: %unexpected.', array(
      '%unexpected' => empty($unexpected) ? t('(none)') : implode(', ', $unexpected),
    )));
  }
  else {
    $this
      ->assertTrue(TRUE, t('No unexpected hooks were called.'));
  }
}