3 namespace Drupal\system\Tests\Form;
5 use Drupal\Component\Serialization\Json;
6 use Drupal\simpletest\WebTestBase;
9 * Tests the form API URL element.
13 class UrlTest extends WebTestBase {
20 public static $modules = ['form_test'];
22 protected $profile = 'testing';
25 * Tests that #type 'url' fields are properly validated and trimmed.
27 public function testFormUrl() {
29 $edit['url'] = 'http://';
30 $edit['url_required'] = ' ';
31 $this->drupalPostForm('form-test/url', $edit, 'Submit');
32 $this->assertRaw(t('The URL %url is not valid.', ['%url' => 'http://']));
33 $this->assertRaw(t('@name field is required.', ['@name' => 'Required URL']));
37 $edit['url_required'] = 'http://example.com/ ';
38 $values = Json::decode($this->drupalPostForm('form-test/url', $edit, 'Submit'));
39 $this->assertIdentical($values['url'], '');
40 $this->assertEqual($values['url_required'], 'http://example.com/');
43 $edit['url'] = 'http://foo.bar.example.com/';
44 $edit['url_required'] = 'https://www.drupal.org/node/1174630?page=0&foo=bar#new';
45 $values = Json::decode($this->drupalPostForm('form-test/url', $edit, 'Submit'));
46 $this->assertEqual($values['url'], $edit['url']);
47 $this->assertEqual($values['url_required'], $edit['url_required']);