public function UrlTest::testFormUrl in Drupal 8
Same name and namespace in other branches
- 9 core/modules/system/tests/src/Functional/Form/UrlTest.php \Drupal\Tests\system\Functional\Form\UrlTest::testFormUrl()
Tests that #type 'url' fields are properly validated and trimmed.
File
- core/
modules/ system/ tests/ src/ Functional/ Form/ UrlTest.php, line 32
Class
- UrlTest
- Tests the form API URL element.
Namespace
Drupal\Tests\system\Functional\FormCode
public function testFormUrl() {
$edit = [];
$edit['url'] = 'http://';
$edit['url_required'] = ' ';
$this
->drupalPostForm('form-test/url', $edit, 'Submit');
$this
->assertRaw(t('The URL %url is not valid.', [
'%url' => 'http://',
]));
$this
->assertRaw(t('@name field is required.', [
'@name' => 'Required URL',
]));
$edit = [];
$edit['url'] = "\n";
$edit['url_required'] = 'http://example.com/ ';
$this
->drupalPostForm('form-test/url', $edit, 'Submit');
$values = Json::decode($this
->getSession()
->getPage()
->getContent());
$this
->assertIdentical($values['url'], '');
$this
->assertEqual($values['url_required'], 'http://example.com/');
$edit = [];
$edit['url'] = 'http://foo.bar.example.com/';
$edit['url_required'] = 'https://www.drupal.org/node/1174630?page=0&foo=bar#new';
$this
->drupalPostForm('form-test/url', $edit, 'Submit');
$values = Json::decode($this
->getSession()
->getPage()
->getContent());
$this
->assertEqual($values['url'], $edit['url']);
$this
->assertEqual($values['url_required'], $edit['url_required']);
}