Skip to content
Snippets Groups Projects
Commit a4b0bb58 authored by Angie Byron's avatar Angie Byron
Browse files

#310358 by drewish: Add a test for file_save_upload and clean up file.test.

parent 89b4c559
No related branches found
No related tags found
No related merge requests found
......@@ -311,6 +311,8 @@ function run() {
$this->tearDown();
}
}
// Clear out the error messages and restore error handler.
drupal_get_messages();
restore_error_handler();
}
......
This diff is collapsed.
; $Id$
name = "File test"
description = "Support module for file handling tests."
package = Testing
version = VERSION
core = 7.x
files[] = file_test.module
hidden = TRUE
<?php
// $Id$
/**
* @file
* Helper module for the file tests.
*/
/**
* Implementation of hook_menu().
*/
function file_test_menu() {
$items['file-test/upload'] = array(
'title' => t('Upload test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('_file_test_form'),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Form to test file uploads.
*/
function _file_test_form(&$form_state) {
$form['#attributes'] = array('enctype' => 'multipart/form-data');
$form['file_test_upload'] = array(
'#type' => 'file',
'#title' => t('Upload an image'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* 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()));
if ($file) {
$form_state['values']['file_test_upload'] = $file;
drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->filepath)));
}
else {
drupal_set_message(t('Epic upload FAIL!'), 'error');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment