summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/form_test.module
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2014-04-16 17:48:42 -0400
committerDavid Rothstein <drothstein@gmail.com>2014-04-16 17:48:42 -0400
commit36ed5e2ef54b74bd36f9b9a1e5830dba032a82e6 (patch)
tree3f46eaaf5786b17e9416c939f803581be9edc57d /modules/simpletest/tests/form_test.module
parent95614ce35deb112da18f1f8841632b718be816c7 (diff)
parent6642fbc7001c728e218170fd286e6b8a24eef24f (diff)
downloadbrdo-36ed5e2ef54b74bd36f9b9a1e5830dba032a82e6.tar.gz
brdo-36ed5e2ef54b74bd36f9b9a1e5830dba032a82e6.tar.bz2
Merge tag '7.27' into 7.x
7.27 release Conflicts: CHANGELOG.txt includes/bootstrap.inc
Diffstat (limited to 'modules/simpletest/tests/form_test.module')
-rw-r--r--modules/simpletest/tests/form_test.module92
1 files changed, 92 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module
index c7885d7a0..602b4090d 100644
--- a/modules/simpletest/tests/form_test.module
+++ b/modules/simpletest/tests/form_test.module
@@ -90,6 +90,21 @@ function form_test_menu() {
'type' => MENU_CALLBACK,
);
+ $items['form_test/form-storage-legacy'] = array(
+ 'title' => 'Emulate legacy AHAH-style ajax callback',
+ 'page callback' => 'form_test_storage_legacy_handler',
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['form_test/form-storage-page-cache'] = array(
+ 'title' => 'Form storage with page cache test',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('form_test_storage_page_cache_form'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
+
$items['form_test/wrapper-callback'] = array(
'title' => 'Form wrapper callback test',
'page callback' => 'form_test_wrapper_callback',
@@ -746,10 +761,37 @@ function form_test_storage_form($form, &$form_state) {
$form_state['cache'] = TRUE;
}
+ if (isset($_REQUEST['immutable'])) {
+ $form_state['build_info']['immutable'] = TRUE;
+ }
+
return $form;
}
/**
+ * Emulate legacy AHAH-style ajax callback.
+ *
+ * Drupal 6 AHAH callbacks used to operate directly on forms retrieved using
+ * form_get_cache and stored using form_set_cache after manipulation. This
+ * callback helps testing whether form_set_cache prevents resaving of immutable
+ * forms.
+ */
+function form_test_storage_legacy_handler($form_build_id) {
+ $form_state = array();
+ $form = form_get_cache($form_build_id, $form_state);
+
+ drupal_json_output(array(
+ 'form' => $form,
+ 'form_state' => $form_state,
+ ));
+
+ $form['#poisoned'] = TRUE;
+ $form_state['poisoned'] = TRUE;
+
+ form_set_cache($form_build_id, $form, $form_state);
+}
+
+/**
* Form element validation handler for 'value' element in form_test_storage_form().
*
* Tests updating of cached form storage during validation.
@@ -786,6 +828,56 @@ function form_test_storage_form_submit($form, &$form_state) {
}
/**
+ * A simple form for testing form storage when page caching is enabled.
+ */
+function form_test_storage_page_cache_form($form, &$form_state) {
+ $form['title'] = array(
+ '#type' => 'textfield',
+ '#title' => 'Title',
+ '#required' => TRUE,
+ );
+
+ $form['test_build_id_old'] = array(
+ '#type' => 'item',
+ '#title' => 'Old build id',
+ '#markup' => 'No old build id',
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => 'Save',
+ );
+
+ $form['rebuild'] = array(
+ '#type' => 'submit',
+ '#value' => 'Rebuild',
+ '#submit' => array('form_test_storage_page_cache_rebuild'),
+ );
+
+ $form['#after_build'] = array('form_test_storage_page_cache_old_build_id');
+ $form_state['cache'] = TRUE;
+
+ return $form;
+}
+
+/**
+ * Form element #after_build callback: output the old form build-id.
+ */
+function form_test_storage_page_cache_old_build_id($form) {
+ if (isset($form['#build_id_old'])) {
+ $form['test_build_id_old']['#markup'] = check_plain($form['#build_id_old']);
+ }
+ return $form;
+}
+
+/**
+ * Form submit callback: Rebuild the form and continue.
+ */
+function form_test_storage_page_cache_rebuild($form, &$form_state) {
+ $form_state['rebuild'] = TRUE;
+}
+
+/**
* A form for testing form labels and required marks.
*/
function form_label_test_form() {