function FileHookTestCase::assertFileHookCalled in SimpleTest 7
Assert that a hook_file_* hook was called a certain number of times.
Parameters
$hook: String with the hook name, e.g. 'load', 'save', 'insert', etc.
$expected_count: Optional integer count.
$message: Optional translated string message.
2 calls to FileHookTestCase::assertFileHookCalled()
- FileLoadTest::testMultiple in tests/
file.test - This will test loading file data from the database.
- FileLoadTest::testSingleValues in tests/
file.test - Load a single file and ensure that the correct values are returned.
File
- tests/
file.test, line 255 - This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.
Class
- FileHookTestCase
- Base class for file tests that use the file_test module to test uploads and hooks.
Code
function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) {
$actual_count = count(file_test_get_calls($hook));
if (is_null($message)) {
if ($actual_count == $expected_count) {
$message = t('hook_file_@name was called correctly.', array(
'@name' => $hook,
));
}
elseif ($expected_count == 0) {
$message = format_plural($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 = t('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);
}