1 form.test FormUrlTestCase::testFormUrl()

Tests that #type 'url' fields are properly validated and trimmed.

File

core/modules/simpletest/tests/form.test, line 2256
Unit tests for the Backdrop Form API.

Class

FormUrlTestCase
Tests url element.

Code

function testFormUrl() {
  $edit = array();
  $edit['url'] = 'http://';
  $edit['url_required'] = ' ';
  $this->backdropPost('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 = backdrop_json_decode($this->backdropPost('form-test/url', $edit, 'Submit'));
  $this->assertIdentical($values['url'], '');
  $this->assertEqual($values['url_required'], 'http://example.com/');

  $edit = array();
  $edit['url'] = 'http://foo.bar.example.com/';
  $edit['url_required'] = 'https://backdropcms.org/example?page=0&foo=bar#new';
  $values = backdrop_json_decode($this->backdropPost('form-test/url', $edit, 'Submit'));
  $this->assertEqual($values['url'], $edit['url']);
  $this->assertEqual($values['url_required'], $edit['url_required']);
}