diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-19 08:38:09 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-19 08:38:09 +0000 |
commit | b2730e86d588bcf7fd0f036571014b75d1bc992f (patch) | |
tree | 4001412a51a8e34b981daba6828dea47cbc6d496 /modules | |
parent | af7cd743e9b9220d9909399f17703371cce9c404 (diff) | |
download | brdo-b2730e86d588bcf7fd0f036571014b75d1bc992f.tar.gz brdo-b2730e86d588bcf7fd0f036571014b75d1bc992f.tar.bz2 |
#552066 by quicksketch and pwolanin: Fix bug with file_save_upload() and trailing slashes (with tests).
Diffstat (limited to 'modules')
-rw-r--r-- | modules/simpletest/tests/file.test | 14 | ||||
-rw-r--r-- | modules/simpletest/tests/file_test.module | 14 |
2 files changed, 26 insertions, 2 deletions
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test index 26bb05154..2830e7b7b 100644 --- a/modules/simpletest/tests/file.test +++ b/modules/simpletest/tests/file.test @@ -603,11 +603,23 @@ class FileSaveUploadTest extends FileHookTestCase { $this->assertTrue(isset($files[$file1->fid]), t('File was loaded successfully')); $this->assertTrue(isset($files[$file2->fid]), t('File was loaded successfully')); + // Upload a third file to a subdirectory. + $image3 = current($this->drupalGetTestFiles('image')); + $image3_realpath = drupal_realpath($image3->uri); + $dir = $this->randomName(); + $edit = array( + 'files[file_test_upload]' => $image3_realpath, + 'file_subdir' => $dir, + ); + $this->drupalPost('file-test/upload', $edit, t('Submit')); + $this->assertResponse(200, t('Received a 200 response for posted test file.')); + $this->assertRaw(t('You WIN!')); + $this->assertTrue(is_file('temporary://' . $dir . '/' . trim(basename($image3_realpath)))); + // Check that file_load_multiple() with no arguments returns FALSE. $this->assertFalse(file_load_multiple(), t('No files were loaded.')); } - /** * Test renaming when uploading over a file that already exists. */ diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module index 9670d1ab3..635576506 100644 --- a/modules/simpletest/tests/file_test.module +++ b/modules/simpletest/tests/file_test.module @@ -54,6 +54,11 @@ function _file_test_form(&$form_state) { ), '#default_value' => FILE_EXISTS_RENAME, ); + $form['file_subdir'] = array( + '#type' => 'textfield', + '#title' => 'Subdirectory for test image', + '#default_value' => '', + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), @@ -67,7 +72,14 @@ function _file_test_form(&$form_state) { function _file_test_form_submit(&$form, &$form_state) { // Process the upload and validate that it is an image. Note: we're using the // form value for the $replace parameter. - $file = file_save_upload('file_test_upload', array('file_validate_is_image' => array()), FALSE, $form_state['values']['file_test_replace']); + if (!empty($form_state['values']['file_subdir'])) { + $destination = 'temporary://' . $form_state['values']['file_subdir']; + file_prepare_directory($destination, FILE_CREATE_DIRECTORY); + } + else { + $destination = FALSE; + } + $file = file_save_upload('file_test_upload', array('file_validate_is_image' => array()), $destination, $form_state['values']['file_test_replace']); if ($file) { $form_state['values']['file_test_upload'] = $file; drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->uri))); |