function UrlTest::testFormUrl in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/system/src/Tests/Form/UrlTest.php \Drupal\system\Tests\Form\UrlTest::testFormUrl()
Tests that #type 'url' fields are properly validated and trimmed.
File
- core/
modules/ system/ src/ Tests/ Form/ UrlTest.php, line 32 - Contains \Drupal\system\Tests\Form\UrlTest.
Class
- UrlTest
- Tests the form API URL element.
Namespace
Drupal\system\Tests\FormCode
function testFormUrl() {
$edit = array();
$edit['url'] = 'http://';
$edit['url_required'] = ' ';
$this
->drupalPostForm('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 = Json::decode($this
->drupalPostForm('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://www.drupal.org/node/1174630?page=0&foo=bar#new';
$values = Json::decode($this
->drupalPostForm('form-test/url', $edit, 'Submit'));
$this
->assertEqual($values['url'], $edit['url']);
$this
->assertEqual($values['url_required'], $edit['url_required']);
}