Tests hook invocations for CRUD operations on files.
public function testFileHooks() {
$this
->installSchema('file', array(
'file_managed',
'file_usage',
));
$url = 'public://entity_crud_hook_test.file';
file_put_contents($url, 'Test test test');
$file = entity_create('file', array(
'fid' => NULL,
'uid' => 1,
'filename' => 'entity_crud_hook_test.file',
'uri' => $url,
'filemime' => 'text/plain',
'filesize' => filesize($url),
'status' => 1,
'timestamp' => REQUEST_TIME,
));
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_file_create called',
'entity_crud_hook_test_entity_create called for type file',
));
$_SESSION['entity_crud_hook_test'] = array();
$file
->save();
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_file_presave called',
'entity_crud_hook_test_entity_presave called for type file',
'entity_crud_hook_test_file_insert called',
'entity_crud_hook_test_entity_insert called for type file',
));
$_SESSION['entity_crud_hook_test'] = array();
$file = file_load($file->fid);
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_entity_load called for type file',
'entity_crud_hook_test_file_load called',
));
$_SESSION['entity_crud_hook_test'] = array();
$file->filename = 'new.entity_crud_hook_test.file';
$file
->save();
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_file_presave called',
'entity_crud_hook_test_entity_presave called for type file',
'entity_crud_hook_test_file_update called',
'entity_crud_hook_test_entity_update called for type file',
));
$_SESSION['entity_crud_hook_test'] = array();
$file
->delete();
$this
->assertHookMessageOrder(array(
'entity_crud_hook_test_file_predelete called',
'entity_crud_hook_test_entity_predelete called for type file',
'entity_crud_hook_test_file_delete called',
'entity_crud_hook_test_entity_delete called for type file',
));
}