summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-12-02 15:09:16 +0000
committerDries Buytaert <dries@buytaert.net>2009-12-02 15:09:16 +0000
commit99833c6289339e863a6e3b04432bf8f335351736 (patch)
tree0cf0a9d143d3ecd9c4bca17129cc3f241e376968 /modules/simpletest/tests
parent92760988b9decb01831ba89bcc54056a702c3836 (diff)
downloadbrdo-99833c6289339e863a6e3b04432bf8f335351736.tar.gz
brdo-99833c6289339e863a6e3b04432bf8f335351736.tar.bz2
- Patch #558928 by brandonojc, mgifford, Owen Barton, Everett Zufelt: improved consistency, flexibility and accessibility of form element labels.
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/form.test56
-rw-r--r--modules/simpletest/tests/form_test.module64
2 files changed, 120 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index 527b5974b..0f1769d43 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -207,6 +207,62 @@ class FormValidationTestCase extends DrupalWebTestCase {
}
/**
+ * Test form element labels, required markers and associated output.
+ */
+class FormsElementsLabelsTestCase extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Form element and label output test',
+ 'description' => 'Test form element labels, required markers and associated output.',
+ 'group' => 'Form API',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('form_test');
+ }
+
+ /**
+ * Test form elements, labels, title attibutes and required marks output
+ * correctly and have the correct label option class if needed.
+ */
+ function testFormLabels() {
+ $this->drupalGet('form_test/form-labels');
+
+ // Check that the checkbox/radio processing is not interfering with
+ // basic placement.
+ $elements = $this->xpath('//input[@id="edit-form-checkboxes-test-third-checkbox"]/following-sibling::label[@for="edit-form-checkboxes-test-third-checkbox" and @class="option"]');
+ $this->assertTrue(isset($elements[0]), t("Label follows field and label option class correct for regular checkboxes."));
+
+ $elements = $this->xpath('//input[@id="edit-form-radios-test-second-radio"]/following-sibling::label[@for="edit-form-radios-test-second-radio" and @class="option"]');
+ $this->assertTrue(isset($elements[0]), t("Label follows field and label option class correct for regular radios."));
+
+ // Exercise various defaults for checkboxes and modifications to ensure
+ // appropriate override and correct behaviour.
+ $elements = $this->xpath('//input[@id="edit-form-checkbox-test"]/following-sibling::label[@for="edit-form-checkbox-test" and @class="option"]');
+ $this->assertTrue(isset($elements[0]), t("Label follows field and label option class correct for a checkbox by default."));
+
+ // Exercise various defaults for textboxes and modifications to ensure
+ // appropriate override and correct behaviour.
+ $elements = $this->xpath('//label[@for="edit-form-textfield-test-title-and-required"]/child::span[@class="form-required"]/parent::*/following-sibling::input[@id="edit-form-textfield-test-title-and-required"]');
+ $this->assertTrue(isset($elements[0]), t("Label preceeds textfield, with required marker inside label."));
+
+ $elements = $this->xpath('//input[@id="edit-form-textfield-test-no-title-required"]/preceding-sibling::label[@for="edit-form-textfield-test-no-title-required"]/span[@class="form-required"]');
+ $this->assertTrue(isset($elements[0]), t("Label tag with required marker preceeds required textfield with no title."));
+
+ $elements = $this->xpath('//input[@id="edit-form-textfield-test-title"]/preceding-sibling::span[@class="form-required"]');
+ $this->assertFalse(isset($elements[0]), t("No required marker on non-required field."));
+
+ $elements = $this->xpath('//input[@id="edit-form-textfield-test-title-after"]/following-sibling::label[@for="edit-form-textfield-test-title-after" and @class="option"]');
+ $this->assertTrue(isset($elements[0]), t("Label after field and label option class correct for text field."));
+
+ $elements = $this->xpath('//label[@for="edit-form-textfield-test-title-no-show"]');
+ $this->assertFalse(isset($elements[0]), t("No label tag when title set not to display."));
+ }
+}
+
+/**
* Test the tableselect form element for expected behavior.
*/
class FormsElementsTableSelectFunctionalTest extends DrupalWebTestCase {
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module
index 9c253e932..c9c208d53 100644
--- a/modules/simpletest/tests/form_test.module
+++ b/modules/simpletest/tests/form_test.module
@@ -94,6 +94,14 @@ function form_test_menu() {
'type' => MENU_CALLBACK,
);
+ $items['form_test/form-labels'] = array(
+ 'title' => 'Form label test',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('form_label_test_form'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
+
return $items;
}
@@ -474,6 +482,62 @@ function form_test_storage_form_submit($form, &$form_state) {
drupal_set_message("Form constructions: ". $_SESSION['constructions']);
}
+ /**
+ * A form for testing form labels and required marks.
+ */
+function form_label_test_form(&$form_state) {
+ $form['form_checkboxes_test'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Checkboxes test'),
+ '#options' => array(
+ 'first-checkbox' => t('First checkbox'),
+ 'second-checkbox' => t('Second checkbox'),
+ 'third-checkbox' => t('Third checkbox'),
+ ),
+ );
+ $form['form_radios_test'] = array(
+ '#type' => 'radios',
+ '#title' => t('Radios test'),
+ '#options' => array(
+ 'first-radio' => t('First radio'),
+ 'second-radio' => t('Second radio'),
+ 'third-radio' => t('Third radio'),
+ ),
+ );
+ $form['form_checkbox_test'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Checkbox test'),
+ );
+ $form['form_textfield_test_title_and_required'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Textfield test for required with title'),
+ '#required' => TRUE,
+ );
+ $form['form_textfield_test_no_title_required'] = array(
+ '#type' => 'textfield',
+ // We use an empty title, since not setting #title supresses the label
+ // and required marker.
+ '#title' => '',
+ '#required' => TRUE,
+ );
+ $form['form_textfield_test_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Textfield test for title only'),
+ // Not required.
+ );
+ $form['form_textfield_test_title_after'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Textfield test for title after element'),
+ '#title_display' => 'after',
+ );
+ // Textfield test for title set not to display
+ $form['form_textfield_test_title_no_show'] = array(
+ '#type' => 'textfield',
+ );
+
+ return $form;
+}
+
/**
* Menu callback; Invokes a form builder function with a wrapper callback.
*/