You are here

function FileUsageTest::testAddUsage in Drupal 7

Tests file_usage_add().

File

modules/simpletest/tests/file.test, line 2254
This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.

Class

FileUsageTest
Tests file usage functions.

Code

function testAddUsage() {
  $file = $this
    ->createFile();
  file_usage_add($file, 'testing', 'foo', 1);

  // Add the file twice to ensure that the count is incremented rather than
  // creating additional records.
  file_usage_add($file, 'testing', 'bar', 2);
  file_usage_add($file, 'testing', 'bar', 2);
  $usage = db_select('file_usage', 'f')
    ->fields('f')
    ->condition('f.fid', $file->fid)
    ->execute()
    ->fetchAllAssoc('id');
  $this
    ->assertEqual(count($usage), 2, 'Created two records');
  $this
    ->assertEqual($usage[1]->module, 'testing', 'Correct module');
  $this
    ->assertEqual($usage[2]->module, 'testing', 'Correct module');
  $this
    ->assertEqual($usage[1]->type, 'foo', 'Correct type');
  $this
    ->assertEqual($usage[2]->type, 'bar', 'Correct type');
  $this
    ->assertEqual($usage[1]->count, 1, 'Correct count');
  $this
    ->assertEqual($usage[2]->count, 2, 'Correct count');
}