FileUsageTest::testRemoveUsage

  1. drupal
    1. 8
    2. 7
Versions
7 FileUsageTest::testRemoveUsage()

Tests file_usage_delete().

Code

modules/simpletest/tests/file.test, line 2103

<?php
function testRemoveUsage() {
  $file = $this->createFile();
  db_insert('file_usage')
      ->fields(array(
    'fid' => $file->fid, 
    'module' => 'testing', 
    'type' => 'bar', 
    'id' => 2, 
    'count' => 3,
  ))
      ->execute();

  // Normal decrement.
  file_usage_delete($file, 'testing', 'bar', 2);
  $count = db_select('file_usage', 'f')
      ->fields('f', array('count'))
      ->condition('f.fid', $file->fid)
      ->execute()
      ->fetchField();
  $this->assertEqual(2, $count, t('The count was decremented correctly.'));

  // Multiple decrement and removal.
  file_usage_delete($file, 'testing', 'bar', 2, 2);
  $count = db_select('file_usage', 'f')
      ->fields('f', array('count'))
      ->condition('f.fid', $file->fid)
      ->execute()
      ->fetchField();
  $this->assertIdentical(FALSE, $count, t('The count was removed entirely when empty.'));

  // Non-existent decrement.
  file_usage_delete($file, 'testing', 'bar', 2);
  $count = db_select('file_usage', 'f')
      ->fields('f', array('count'))
      ->condition('f.fid', $file->fid)
      ->execute()
      ->fetchField();
  $this->assertIdentical(FALSE, $count, t('Decrementing non-exist record complete.'));
}
?>