diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-06-26 19:55:47 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-06-26 19:55:47 +0000 |
commit | 344f5cb850ce47e5e01ca4dac1957437a92a7fea (patch) | |
tree | ff3c15854ecf56bdb7e05f64196497c0f92062d8 /modules/simpletest/tests/file_test.module | |
parent | 151fb3f94307e2167592c0a0973e2ef46d85fbe8 (diff) | |
download | brdo-344f5cb850ce47e5e01ca4dac1957437a92a7fea.tar.gz brdo-344f5cb850ce47e5e01ca4dac1957437a92a7fea.tar.bz2 |
- Patch #693084 by dhthwy, jpmckinney, reglogge, clemens.tolboom, naxoc, chx: file_munge_filename() extension handling broken by move to File Field.
Diffstat (limited to 'modules/simpletest/tests/file_test.module')
-rw-r--r-- | modules/simpletest/tests/file_test.module | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module index 6d4d1f8c5..78b80f33d 100644 --- a/modules/simpletest/tests/file_test.module +++ b/modules/simpletest/tests/file_test.module @@ -47,7 +47,7 @@ function file_test_stream_wrappers() { function _file_test_form($form, &$form_state) { $form['file_test_upload'] = array( '#type' => 'file', - '#title' => t('Upload an image'), + '#title' => t('Upload a file'), ); $form['file_test_replace'] = array( '#type' => 'select', @@ -61,9 +61,28 @@ function _file_test_form($form, &$form_state) { ); $form['file_subdir'] = array( '#type' => 'textfield', - '#title' => 'Subdirectory for test image', + '#title' => t('Subdirectory for test file'), '#default_value' => '', ); + + $form['extensions'] = array( + '#type' => 'textfield', + '#title' => t('Allowed extensions.'), + '#default_value' => '', + ); + + $form['allow_all_extensions'] = array( + '#type' => 'checkbox', + '#title' => t('Allow all extensions?'), + '#default_value' => FALSE, + ); + + $form['is_image_file'] = array( + '#type' => 'checkbox', + '#title' => t('Is this an image file?'), + '#default_value' => TRUE, + ); + $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), @@ -75,7 +94,7 @@ function _file_test_form($form, &$form_state) { * Process the upload. */ function _file_test_form_submit(&$form, &$form_state) { - // Process the upload and validate that it is an image. Note: we're using the + // Process the upload and perform validation. Note: we're using the // form value for the $replace parameter. if (!empty($form_state['values']['file_subdir'])) { $destination = 'temporary://' . $form_state['values']['file_subdir']; @@ -84,10 +103,26 @@ function _file_test_form_submit(&$form, &$form_state) { else { $destination = FALSE; } - $file = file_save_upload('file_test_upload', array('file_validate_is_image' => array()), $destination, $form_state['values']['file_test_replace']); + + // Setup validators. + $validators = array(); + if ($form_state['values']['is_image_file']) { + $validators['file_validate_is_image'] = array(); + } + + if ($form_state['values']['allow_all_extensions']) { + $validators['file_validate_extensions'] = array(); + } + else if (!empty($form_state['values']['extensions'])) { + $validators['file_validate_extensions'] = array($form_state['values']['extensions']); + } + + $file = file_save_upload('file_test_upload', $validators, $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))); + drupal_set_message(t('File name is @filename.', array('@filename' => $file->filename))); + drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->filemime))); drupal_set_message(t('You WIN!')); } elseif ($file === FALSE) { |