#30520 follow-up by Dave Reid: Fix error message about upload when not uploading a file (with tests, so we don't break it again).

merge-requests/26/head
Angie Byron 2009-01-20 02:56:05 +00:00
parent 09ed948a25
commit cb07c9992b
3 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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)));
}
}

View File

@ -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');
}
}