summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.26/modules/file/tests/file_module_test.module
diff options
context:
space:
mode:
Diffstat (limited to 'kolab.org/www/drupal-7.26/modules/file/tests/file_module_test.module')
-rw-r--r--kolab.org/www/drupal-7.26/modules/file/tests/file_module_test.module69
1 files changed, 69 insertions, 0 deletions
diff --git a/kolab.org/www/drupal-7.26/modules/file/tests/file_module_test.module b/kolab.org/www/drupal-7.26/modules/file/tests/file_module_test.module
new file mode 100644
index 0000000..f66c749
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/file/tests/file_module_test.module
@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * @file
+ * Provides File module pages for testing purposes.
+ */
+
+/**
+ * Implements hook_menu().
+ */
+function file_module_test_menu() {
+ $items = array();
+
+ $items['file/test'] = array(
+ 'title' => 'Managed file test',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('file_module_test_form'),
+ 'access arguments' => array('access content'),
+ );
+
+ return $items;
+}
+
+/**
+ * Form constructor for testing a 'managed_file' element.
+ *
+ * @see file_module_test_form_submit()
+ * @ingroup forms
+ */
+function file_module_test_form($form, &$form_state, $tree = TRUE, $extended = FALSE, $default_fid = NULL) {
+ $form['#tree'] = (bool) $tree;
+
+ $form['nested']['file'] = array(
+ '#type' => 'managed_file',
+ '#title' => t('Managed file'),
+ '#upload_location' => 'public://test',
+ '#progress_message' => t('Please wait...'),
+ '#extended' => (bool) $extended,
+ '#size' => 13,
+ );
+ if ($default_fid) {
+ $form['nested']['file']['#default_value'] = $extended ? array('fid' => $default_fid) : $default_fid;
+ }
+
+ $form['textfield'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Type a value and ensure it stays'),
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ );
+
+ return $form;
+}
+
+/**
+ * Form submission handler for file_module_test_form().
+ */
+function file_module_test_form_submit($form, &$form_state) {
+ if ($form['#tree']) {
+ $fid = $form['nested']['file']['#extended'] ? $form_state['values']['nested']['file']['fid'] : $form_state['values']['nested']['file'];
+ }
+ else {
+ $fid = $form['nested']['file']['#extended'] ? $form_state['values']['file']['fid'] : $form_state['values']['file'];
+ }
+ drupal_set_message(t('The file id is %fid.', array('%fid' => $fid)));
+}