diff --git a/core/modules/simpletest/tests/form.test b/core/modules/simpletest/tests/form.test index cd61d93..eb77d6b 100644 --- a/core/modules/simpletest/tests/form.test +++ b/core/modules/simpletest/tests/form.test @@ -1631,3 +1631,41 @@ class FormCheckboxTestCase extends DrupalWebTestCase { } } } + +/** + * Tests url element. + */ +class FormUrlTestCase extends DrupalWebTestCase { + protected $profile = 'testing'; + + public static function getInfo() { + return array( + 'name' => 'Form API url', + 'description' => 'Tests the form API url element.', + 'group' => 'Form API', + ); + } + + public function setUp() { + parent::setUp('form_test'); + } + + /** + * Tests that #type 'url' fields are properly validated and trimmed. + */ + function testFormUrl() { + $edit = array(); + $edit['url'] = 'http://'; + $edit['url_required'] = ' '; + $this->drupalPost('form-test/url', $edit, 'Submit'); + $this->assertRaw(t('The URL %url is not valid.', array('%url' => 'http://'))); + $this->assertRaw(t('!name field is required.', array('!name' => 'Required URL'))); + + $edit = array(); + $edit['url'] = "\n"; + $edit['url_required'] = 'http://example.com/ '; + $values = drupal_json_decode($this->drupalPost('form-test/url', $edit, 'Submit')); + $this->assertIdentical($values['url'], ''); + $this->assertEqual($values['url_required'], 'http://example.com/'); + } +} diff --git a/core/modules/simpletest/tests/form_test.module b/core/modules/simpletest/tests/form_test.module index dd243b4..1d89676 100644 --- a/core/modules/simpletest/tests/form_test.module +++ b/core/modules/simpletest/tests/form_test.module @@ -125,6 +125,12 @@ function form_test_menu() { 'page arguments' => array('form_test_checkboxes_radios'), 'access callback' => TRUE, ); + $items['form-test/url'] = array( + 'title' => t('URL'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('form_test_url'), + 'access callback' => TRUE, + ); $items['form-test/disabled-elements'] = array( 'title' => t('Form test'), @@ -1098,6 +1104,39 @@ function form_test_checkboxes_radios($form, &$form_state, $customize = FALSE) { } /** + * Form consructor for testing #type 'url' elements. + * + * @see form_test_url_submit() + * @ingroup forms + */ +function form_test_url($form, &$form_state) { + $form['url'] = array( + '#type' => 'url', + '#title' => 'Optional URL', + '#description' => 'An optional URL field.', + ); + $form['url_required'] = array( + '#type' => 'url', + '#title' => 'Required URL', + '#description' => 'A required URL field.', + '#required' => TRUE, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Submit', + ); + return $form; +} + +/** + * Form submission handler for form_test_url(). + */ +function form_test_url_submit($form, &$form_state) { + drupal_json_output($form_state['values']); + exit(); +} + +/** * Build a form to test disabled elements. */ function _form_test_disabled_elements($form, &$form_state) {