summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/file.inc8
-rw-r--r--modules/simpletest/tests/file.test9
-rw-r--r--modules/simpletest/tests/file_test.module2
3 files changed, 13 insertions, 6 deletions
diff --git a/includes/file.inc b/includes/file.inc
index d047e1f7e..717eb8b97 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -845,8 +845,8 @@ function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) {
* destination directory should overwritten. A false value will generate a
* new, unique filename in the destination directory.
* @return
- * An object containing the file information, or FALSE in the event of an
- * error.
+ * An object containing the file information if the upload succeeded, FALSE
+ * in the event of an error, or NULL if no file was uploaded.
*/
function file_save_upload($source, $validators = array(), $destination = FALSE, $replace = FILE_EXISTS_RENAME) {
global $user;
@@ -859,8 +859,8 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
}
// Make sure there's an upload to process.
- if (!isset($_FILES['files']['name'][$source])) {
- return FALSE;
+ if (empty($_FILES['files']['name'][$source])) {
+ return NULL;
}
// Check for file upload errors and return FALSE if a lower level system
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index d5ca1d854..ae05be83d 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -599,6 +599,14 @@ class FileSaveUploadTest extends FileHookTestCase {
// Check that the no hooks were called while failing.
$this->assertFileHooksCalled(array());
}
+
+ /**
+ * Test for no failures when not uploading a file.
+ */
+ function testNoUpload() {
+ $this->drupalPost('file-test/upload', array(), t('Submit'));
+ $this->assertNoRaw(t('Epic upload FAIL!'), t('Failure message not found.'));
+ }
}
/**
@@ -1765,4 +1773,3 @@ class FileNameMungingTest extends FileTestCase {
$this->assertIdentical($unmunged_name, $this->name, t('The unmunged (%unmunged) filename matches the original (%original)', array('%unmunged' => $unmunged_name, '%original' => $this->name)));
}
}
-
diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module
index 899bbdc43..9d44b40ab 100644
--- a/modules/simpletest/tests/file_test.module
+++ b/modules/simpletest/tests/file_test.module
@@ -61,7 +61,7 @@ function _file_test_form_submit(&$form, &$form_state) {
drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->filepath)));
drupal_set_message(t('You WIN!'));
}
- else {
+ elseif ($file === FALSE) {
drupal_set_message(t('Epic upload FAIL!'), 'error');
}
}