summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/form.test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests/form.test')
-rw-r--r--modules/simpletest/tests/form.test71
1 files changed, 71 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index 3c447d14d..4683fb8d4 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -850,6 +850,77 @@ class FormsProgrammaticTestCase extends DrupalWebTestCase {
}
}
+/**
+ * Test that FAPI correctly determines $form_state['clicked_button'].
+ */
+class FormsClickedButtonTestCase extends DrupalWebTestCase {
+
+ function getInfo() {
+ return array(
+ 'name' => 'Form clicked button determination',
+ 'description' => 'Test the determination of $form_state[\'clicked_button\'].',
+ 'group' => 'Form API',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('form_test');
+ }
+
+ /**
+ * Test the determination of $form_state['clicked_button'] when no button
+ * information is included in the POST data, as is sometimes the case when
+ * the ENTER key is pressed in a textfield in Internet Explorer.
+ */
+ function testNoButtonInfoInPost() {
+ $path = 'form-test/clicked-button';
+ $edit = array();
+ $form_id = 'form-test-clicked-button';
+
+ // Ensure submitting a form with no buttons results in no
+ // $form_state['clicked_button'] and the form submit handler not running.
+ drupal_static_reset('drupal_html_id');
+ $this->drupalPost($path, $edit, NULL, array(), array(), $form_id);
+ $this->assertText('There is no clicked button.', t('$form_state[\'clicked_button\'] set to NULL.'));
+ $this->assertNoText('Submit handler for form_test_clicked_button executed.', t('Form submit handler did not execute.'));
+
+ // Ensure submitting a form with one or more submit buttons results in
+ // $form_state['clicked_button'] being set to the first one the user has
+ // access to. An argument with 'r' in it indicates a restricted
+ // (#access=FALSE) button.
+ drupal_static_reset('drupal_html_id');
+ $this->drupalPost($path . '/s', $edit, NULL, array(), array(), $form_id);
+ $this->assertText('The clicked button is button1.', t('$form_state[\'clicked_button\'] set to only button.'));
+ $this->assertText('Submit handler for form_test_clicked_button executed.', t('Form submit handler executed.'));
+ drupal_static_reset('drupal_html_id');
+ $this->drupalPost($path . '/s/s', $edit, NULL, array(), array(), $form_id);
+ $this->assertText('The clicked button is button1.', t('$form_state[\'clicked_button\'] set to first button.'));
+ $this->assertText('Submit handler for form_test_clicked_button executed.', t('Form submit handler executed.'));
+ drupal_static_reset('drupal_html_id');
+ $this->drupalPost($path . '/rs/s', $edit, NULL, array(), array(), $form_id);
+ $this->assertText('The clicked button is button2.', t('$form_state[\'clicked_button\'] set to first available button.'));
+ $this->assertText('Submit handler for form_test_clicked_button executed.', t('Form submit handler executed.'));
+
+ // Ensure submitting a form with buttons of different types results in
+ // $form_state['clicked_button'] being set to the first button, regardless
+ // of type. For the FAPI 'button' type, this should result in the submit
+ // handler not executing. The types are 's'(ubmit), 'b'(utton), and
+ // 'i'(mage_button).
+ drupal_static_reset('drupal_html_id');
+ $this->drupalPost($path . '/s/b/i', $edit, NULL, array(), array(), $form_id);
+ $this->assertText('The clicked button is button1.', t('$form_state[\'clicked_button\'] set to first button.'));
+ $this->assertText('Submit handler for form_test_clicked_button executed.', t('Form submit handler executed.'));
+ drupal_static_reset('drupal_html_id');
+ $this->drupalPost($path . '/b/s/i', $edit, NULL, array(), array(), $form_id);
+ $this->assertText('The clicked button is button1.', t('$form_state[\'clicked_button\'] set to first button.'));
+ $this->assertNoText('Submit handler for form_test_clicked_button executed.', t('Form submit handler did not execute.'));
+ drupal_static_reset('drupal_html_id');
+ $this->drupalPost($path . '/i/s/b', $edit, NULL, array(), array(), $form_id);
+ $this->assertText('The clicked button is button1.', t('$form_state[\'clicked_button\'] set to first button.'));
+ $this->assertText('Submit handler for form_test_clicked_button executed.', t('Form submit handler executed.'));
+ }
+}
+
/**
* Tests rebuilding of arbitrary forms by altering them.