function FileManagedTestBase::assertFileHooksCalled in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Tests/FileManagedTestBase.php \Drupal\file\Tests\FileManagedTestBase::assertFileHooksCalled()
Assert that all of the specified hook_file_* hooks were called once, other values result in failure.
Parameters
array $expected: Array with string containing with the hook name, e.g. 'load', 'save', 'insert', etc.
8 calls to FileManagedTestBase::assertFileHooksCalled()
- SaveUploadTest::setUp in core/
modules/ file/ src/ Tests/ SaveUploadTest.php - Sets up a Drupal site for running functional and integration tests.
- SaveUploadTest::testExistingError in core/
modules/ file/ src/ Tests/ SaveUploadTest.php - Test for failure when uploading over a file that already exists.
- SaveUploadTest::testExistingRename in core/
modules/ file/ src/ Tests/ SaveUploadTest.php - Test renaming when uploading over a file that already exists.
- SaveUploadTest::testExistingReplace in core/
modules/ file/ src/ Tests/ SaveUploadTest.php - Test replacement when uploading over a file that already exists.
- SaveUploadTest::testHandleDangerousFile in core/
modules/ file/ src/ Tests/ SaveUploadTest.php - Test dangerous file handling.
File
- core/
modules/ file/ src/ Tests/ FileManagedTestBase.php, line 40 - Contains \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\TestsCode
function assertFileHooksCalled($expected) {
\Drupal::state()
->resetCache();
// 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, format_string('Expected hooks %expected to be called but %uncalled was not called.', array(
'%expected' => implode(', ', $expected),
'%uncalled' => implode(', ', $uncalled),
)));
}
else {
$this
->assertTrue(TRUE, format_string('All the expected hooks were called: %expected', array(
'%expected' => empty($expected) ? '(none)' : implode(', ', $expected),
)));
}
// Determine if there were any unexpected calls.
$unexpected = array_diff($actual, $expected);
if (count($unexpected)) {
$this
->assertTrue(FALSE, format_string('Unexpected hooks were called: %unexpected.', array(
'%unexpected' => empty($unexpected) ? '(none)' : implode(', ', $unexpected),
)));
}
else {
$this
->assertTrue(TRUE, 'No unexpected hooks were called.');
}
}