You are here

public function EntityCrudHookTestCase::testFileHooks in Drupal 7

Tests hook invocations for CRUD operations on files.

File

modules/simpletest/tests/entity_crud_hook_test.test, line 119
CRUD hook tests for the Entity CRUD API.

Class

EntityCrudHookTestCase
Tests invocation of hooks when performing an action.

Code

public function testFileHooks() {
  $url = 'public://entity_crud_hook_test.file';
  file_put_contents($url, 'Test test test');
  $file = (object) array(
    'fid' => NULL,
    'uid' => 1,
    'filename' => 'entity_crud_hook_test.file',
    'uri' => $url,
    'filemime' => 'text/plain',
    'filesize' => filesize($url),
    'status' => 1,
    'timestamp' => REQUEST_TIME,
  );
  $_SESSION['entity_crud_hook_test'] = array();
  file_save($file);
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_presave called for type file');
  $this
    ->assertHookMessage('entity_crud_hook_test_file_presave called');
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_insert called for type file');
  $this
    ->assertHookMessage('entity_crud_hook_test_file_insert called');
  $_SESSION['entity_crud_hook_test'] = array();
  $file = file_load($file->fid);
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_load called for type file');
  $this
    ->assertHookMessage('entity_crud_hook_test_file_load called');
  $_SESSION['entity_crud_hook_test'] = array();
  $file->filename = 'new.entity_crud_hook_test.file';
  file_save($file);
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_presave called for type file');
  $this
    ->assertHookMessage('entity_crud_hook_test_file_presave called');
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_update called for type file');
  $this
    ->assertHookMessage('entity_crud_hook_test_file_update called');
  $_SESSION['entity_crud_hook_test'] = array();
  file_delete($file);
  $this
    ->assertHookMessage('entity_crud_hook_test_entity_delete called for type file');
  $this
    ->assertHookMessage('entity_crud_hook_test_file_delete called');
}