summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/file_test.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests/file_test.module')
-rw-r--r--modules/simpletest/tests/file_test.module28
1 files changed, 26 insertions, 2 deletions
diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module
index 7a9644f0d..899bbdc43 100644
--- a/modules/simpletest/tests/file_test.module
+++ b/modules/simpletest/tests/file_test.module
@@ -32,6 +32,16 @@ function _file_test_form(&$form_state) {
'#type' => 'file',
'#title' => t('Upload an image'),
);
+ $form['file_test_replace'] = array(
+ '#type' => 'select',
+ '#title' => t('Replace existing image'),
+ '#options' => array(
+ FILE_EXISTS_RENAME => t('Appends number until name is unique'),
+ FILE_EXISTS_REPLACE => t('Replace the existing file'),
+ FILE_EXISTS_ERROR => t('Fail with an error'),
+ ),
+ '#default_value' => FILE_EXISTS_RENAME,
+ );
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
@@ -43,11 +53,13 @@ function _file_test_form(&$form_state) {
* Process the upload.
*/
function _file_test_form_submit(&$form, &$form_state) {
- // Validate the uploaded picture.
- $file = file_save_upload('file_test_upload', array('file_validate_is_image' => array()));
+ // 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 ($file) {
$form_state['values']['file_test_upload'] = $file;
drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->filepath)));
+ drupal_set_message(t('You WIN!'));
}
else {
drupal_set_message(t('Epic upload FAIL!'), 'error');
@@ -101,6 +113,18 @@ function file_test_get_calls($op) {
}
/**
+ * Get an array with the calls for all hooks.
+ *
+ * @return
+ * An array keyed by hook name ('load', 'validate', 'download',
+ * 'references', 'insert', 'update', 'copy', 'move', 'delete') with values
+ * being arrays of parameters passed to each call.
+ */
+function file_test_get_all_calls() {
+ return variable_get('file_test_results', array());
+}
+
+/**
* Store the values passed to a hook invocation.
*
* @param $op