You are here

function FileManagedUnitTestBase::assertFileHookCalled in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/FileManagedUnitTestBase.php \Drupal\file\Tests\FileManagedUnitTestBase::assertFileHookCalled()

Assert that a hook_file_* hook was called a certain number of times.

Parameters

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

int $expected_count: Optional integer count.

string $message: Optional translated string message.

3 calls to FileManagedUnitTestBase::assertFileHookCalled()
LoadTest::testMultiple in core/modules/file/src/Tests/LoadTest.php
This will test loading file data from the database.
LoadTest::testSingleValues in core/modules/file/src/Tests/LoadTest.php
Load a single file and ensure that the correct values are returned.
LoadTest::testUuidValues in core/modules/file/src/Tests/LoadTest.php
Loads a single file and ensure that the correct values are returned.

File

core/modules/file/src/Tests/FileManagedUnitTestBase.php, line 87
Contains \Drupal\file\Tests\FileManagedUnitTestBase.

Class

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

Namespace

Drupal\file\Tests

Code

function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) {
  $actual_count = count(file_test_get_calls($hook));
  if (!isset($message)) {
    if ($actual_count == $expected_count) {
      $message = format_string('hook_file_@name was called correctly.', array(
        '@name' => $hook,
      ));
    }
    elseif ($expected_count == 0) {
      $message = \Drupal::translation()
        ->formatPlural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array(
        '@name' => $hook,
        '@count' => $actual_count,
      ));
    }
    else {
      $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', array(
        '@name' => $hook,
        '%expected' => $expected_count,
        '%actual' => $actual_count,
      ));
    }
  }
  $this
    ->assertEqual($actual_count, $expected_count, $message);
}