summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/tests/file.test70
-rw-r--r--modules/simpletest/tests/file_test.module12
-rw-r--r--modules/upload/upload.module3
3 files changed, 11 insertions, 74 deletions
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index 97014962e..564ecea35 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -974,18 +974,22 @@ class FileSaveTest extends FileHookTestCase {
$this->assertFileHookCalled('insert');
$this->assertNotNull($saved_file, t("Saving the file should give us back a file object."), 'File');
$this->assertTrue($saved_file->fid > 0, t("A new file ID is set when saving a new file to the database."), 'File');
- $this->assertEqual(db_result(db_query('SELECT COUNT(*) FROM {files} f WHERE f.fid = %d', array($saved_file->fid))), 1, t("Record exists in the database."));
+ $loaded_file = db_query('SELECT * FROM {files} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
+ $this->assertNotNull($loaded_file, t("Record exists in the database."));
+ $this->assertEqual($loaded_file->status, $file->status, t("Status was saved correctly."));
$this->assertEqual($saved_file->filesize, filesize($file->filepath), t("File size was set correctly."), 'File');
$this->assertTrue($saved_file->timestamp > 1, t("File size was set correctly."), 'File');
// Resave the file, updating the existing record.
file_test_reset();
+ $saved_file->status = 7;
$resaved_file = file_save($saved_file);
$this->assertFileHookCalled('update');
$this->assertEqual($resaved_file->fid, $saved_file->fid, t("The file ID of an existing file is not changed when updating the database."), 'File');
$this->assertTrue($resaved_file->timestamp >= $saved_file->timestamp, t("Timestamp didn't go backwards."), 'File');
- $count = db_result(db_query('SELECT COUNT(*) FROM {files} f WHERE f.fid = %d', array($saved_file->fid)));
- $this->assertEqual($count, 1, t("Record still exists in the database."), 'File');
+ $loaded_file = db_query('SELECT * FROM {files} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
+ $this->assertNotNull($loaded_file, t("Record still exists in the database."), 'File');
+ $this->assertEqual($loaded_file->status, $saved_file->status, t("Status was saved correctly."));
}
}
@@ -1033,66 +1037,6 @@ class FileValidateTest extends FileHookTestCase {
}
/**
- * Tests the file_set_status() function.
- */
-class FileSetStatusTest extends FileHookTestCase {
- /**
- * Implementation of getInfo().
- */
- function getInfo() {
- return array(
- 'name' => t('File set status'),
- 'description' => t('Tests the file set status functions.'),
- 'group' => t('File'),
- );
- }
-
- /**
- * Test the file_set_status() function.
- */
- function testFileSetStatus() {
- // Create a new file object.
- $file = array(
- 'uid' => 1,
- 'filename' => 'druplicon.png',
- 'filepath' => 'misc/druplicon.png',
- 'filemime' => 'image/png',
- 'timestamp' => 1,
- 'status' => FILE_STATUS_TEMPORARY,
- );
- $file = file_save($file);
- // Just a couple of sanity checks before we start the real testing.
- $this->assertTrue($file->fid, t("Make sure the file saved correctly."));
- $this->assertEqual($file->status, FILE_STATUS_TEMPORARY, t("Status was set during save."));
-
- // Change the status and make sure everything works
- file_test_reset();
- $returned = file_set_status($file);
- $this->assertEqual(count(file_test_get_calls('status')), 1, t('hook_file_status was called.'));
- $this->assertNotIdentical($returned, FALSE, t("file_set_status() worked and returned a non-false value."));
- $this->assertEqual($returned->fid, $file->fid, t("Returned the correct file."));
- $this->assertEqual($returned->status, FILE_STATUS_PERMANENT, t("File's status was changed."));
-
- // Try it resetting it to the same value.
- file_test_reset();
- $returned = file_set_status($file, FILE_STATUS_PERMANENT);
- $this->assertEqual(count(file_test_get_calls('status')), 0, t('hook_file_status was not called.'));
- $this->assertIdentical($returned, FALSE, t("file_set_status() failed since there was no change."));
- $test_file = file_load($file->fid);
- $this->assertEqual($test_file->fid, $file->fid , t("Loaded the correct file."));
- $this->assertEqual($test_file->status, FILE_STATUS_PERMANENT, t("File's status is correct."));
-
- // Now switch it.
- file_test_reset();
- $returned = file_set_status($file, FILE_STATUS_TEMPORARY);
- $this->assertEqual(count(file_test_get_calls('status')), 1, t('hook_file_status was called.'));
- $this->assertNotIdentical($returned, FALSE, t("file_set_status() worked and returned a non-false value."));
- $this->assertEqual($returned->fid, $file->fid , t("Returned the correct file."));
- $this->assertEqual($returned->status, FILE_STATUS_TEMPORARY, t("File's status is correct."));
- }
-}
-
-/**
* Tests the file_save_data() function.
*/
class FileSaveDataTest extends FileHookTestCase {
diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module
index 142748e9a..6240f4712 100644
--- a/modules/simpletest/tests/file_test.module
+++ b/modules/simpletest/tests/file_test.module
@@ -67,7 +67,6 @@ function file_test_reset() {
'validate' => array(),
'download' => array(),
'references' => array(),
- 'status' => array(),
'insert' => array(),
'update' => array(),
'copy' => array(),
@@ -91,7 +90,7 @@ function file_test_reset() {
*
* @param $op
* One of the hook_file_* operations: 'load', 'validate', 'download',
- * 'references', 'status', 'insert', 'update', 'copy', 'move', 'delete'.
+ * 'references', 'insert', 'update', 'copy', 'move', 'delete'.
* @returns
* Array of the parameters passed to each call.
* @see _file_test_log_call() and file_test_reset()
@@ -106,7 +105,7 @@ function file_test_get_calls($op) {
*
* @param $op
* One of the hook_file_* operations: 'load', 'validate', 'download',
- * 'references', 'status', 'insert', 'update', 'copy', 'move', 'delete'.
+ * 'references', 'insert', 'update', 'copy', 'move', 'delete'.
* @param $args
* Values passed to hook.
* @see file_test_get_calls() and file_test_reset()
@@ -165,13 +164,6 @@ function file_test_file_validate($file) {
}
/**
- * Implementation of hook_file_status().
- */
-function file_test_file_status($file) {
- _file_test_log_call('status', array($file));
-}
-
-/**
* Implementation of hook_file_download().
*/
function file_test_file_download($file) {
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
index e1dae1f28..8f223ad1a 100644
--- a/modules/upload/upload.module
+++ b/modules/upload/upload.module
@@ -479,7 +479,8 @@ function upload_save(&$node) {
else {
db_query("UPDATE {upload} SET list = %d, description = '%s', weight = %d WHERE fid = %d AND vid = %d", $file->list, $file->description, $file->weight, $file->fid, $node->vid);
}
- file_set_status($file, FILE_STATUS_PERMANENT);
+ $file->status &= FILE_STATUS_PERMANENT;
+ $file = file_save($file);
}
}