summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries Buytaert2011-08-02 00:50:59 (GMT)
committerDries Buytaert2011-08-02 00:50:59 (GMT)
commite67898ffa96b716f052ae1ebda9fa0c3f64db7da (patch)
tree191c3f8bbeacf74575749418d1241067dab8e9d7
parent233bdf565020449f0acb7e0c51827542dbae2d11 (diff)
- Patch #1222576 by jox: file_usage_list() is defective (might return incomplete results).
-rw-r--r--includes/file.inc5
-rw-r--r--modules/simpletest/tests/file.test10
2 files changed, 8 insertions, 7 deletions
diff --git a/includes/file.inc b/includes/file.inc
index 1278d39..bc8ae79 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -605,7 +605,8 @@ function file_save(stdClass $file) {
*
* @return
* A nested array with usage data. The first level is keyed by module name,
- * the second by object type, the third has 'id' and 'count' keys.
+ * the second by object type and the third by the object id. The value
+ * of the third level contains the usage count.
*
* @see file_usage_add()
* @see file_usage_delete()
@@ -618,7 +619,7 @@ function file_usage_list(stdClass $file) {
->execute();
$references = array();
foreach ($result as $usage) {
- $references[$usage->module][$usage->type] = array('id' => $usage->id, 'count' => $usage->count);
+ $references[$usage->module][$usage->type][$usage->id] = $usage->count;
}
return $references;
}
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index 9dbe546..db4097c 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -1563,7 +1563,7 @@ class FileDeleteTest extends FileHookTestCase {
file_usage_delete($file, 'testing', 'test', 1);
file_delete($file);
$usage = file_usage_list($file);
- $this->assertEqual($usage['testing']['test'], array('id' => 1, 'count' => 1), t('Test file is still in use.'));
+ $this->assertEqual($usage['testing']['test'], array(1 => 1), t('Test file is still in use.'));
$this->assertTrue(file_exists($file->uri), t('File still exists on the disk.'));
$this->assertTrue(file_load($file->fid), t('File still exists in the database.'));
@@ -2066,10 +2066,10 @@ class FileUsageTest extends FileTestCase {
$usage = file_usage_list($file);
$this->assertEqual(count($usage['testing']), 2, t('Returned the correct number of items.'));
- $this->assertEqual($usage['testing']['foo']['id'], 1, t('Returned the correct id.'));
- $this->assertEqual($usage['testing']['bar']['id'], 2, t('Returned the correct id.'));
- $this->assertEqual($usage['testing']['foo']['count'], 1, t('Returned the correct count.'));
- $this->assertEqual($usage['testing']['bar']['count'], 2, t('Returned the correct count.'));
+ $this->assertTrue(isset($usage['testing']['foo'][1]), t('Returned the correct id.'));
+ $this->assertTrue(isset($usage['testing']['bar'][2]), t('Returned the correct id.'));
+ $this->assertEqual($usage['testing']['foo'][1], 1, t('Returned the correct count.'));
+ $this->assertEqual($usage['testing']['bar'][2], 2, t('Returned the correct count.'));
}
/**