diff options
Diffstat (limited to 'modules/simpletest/tests/form_test.module')
-rw-r--r-- | modules/simpletest/tests/form_test.module | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index 4d717c04b..abaae06c1 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -98,6 +98,12 @@ function form_test_menu() { 'page arguments' => array('form_test_select'), 'access callback' => TRUE, ); + $items['form-test/checkboxes-radios'] = array( + 'title' => t('Checkboxes, Radios'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('form_test_checkboxes_radios'), + 'access callback' => TRUE, + ); $items['form-test/disabled-elements'] = array( 'title' => t('Form test'), @@ -187,6 +193,14 @@ function form_test_menu() { } /** + * Form submit handler to return form values as JSON. + */ +function _form_test_submit_values_json($form, &$form_state) { + drupal_json_output($form_state['values']); + drupal_exit(); +} + +/** * Form builder for testing hook_form_alter() and hook_form_FORM_ID_alter(). */ function form_test_alter_form($form, &$form_state) { @@ -893,6 +907,63 @@ function form_test_select_submit($form, &$form_state) { } /** + * Form constructor to test expansion of #type checkboxes and radios. + */ +function form_test_checkboxes_radios($form, &$form_state, $customize = FALSE) { + $form['#submit'] = array('_form_test_submit_values_json'); + + // Expand #type checkboxes, setting custom element properties for some but not + // all options. + $form['checkboxes'] = array( + '#type' => 'checkboxes', + '#title' => 'Checkboxes', + '#options' => array( + 0 => 'Zero', + 'foo' => 'Foo', + 1 => 'One', + 'bar' => 'Bar', + ), + ); + if ($customize) { + $form['checkboxes'] += array( + 'foo' => array( + '#description' => 'Enable to foo.', + ), + 1 => array( + '#weight' => 10, + ), + ); + } + + // Expand #type radios, setting custom element properties for some but not + // all options. + $form['radios'] = array( + '#type' => 'radios', + '#title' => 'Radios', + '#options' => array( + 0 => 'Zero', + 'foo' => 'Foo', + 1 => 'One', + 'bar' => 'Bar', + ), + ); + if ($customize) { + $form['radios'] += array( + 'foo' => array( + '#description' => 'Enable to foo.', + ), + 1 => array( + '#weight' => 10, + ), + ); + } + + $form['submit'] = array('#type' => 'submit', '#value' => 'Submit'); + + return $form; +} + +/** * Build a form to test disabled elements. */ function _form_test_disabled_elements($form, &$form_state) { |