aceb6b42027170029bbff672e1945127a680cf86
[yaffs-website] / web / core / modules / system / src / Tests / Form / UrlTest.php
1 <?php
2
3 namespace Drupal\system\Tests\Form;
4
5 use Drupal\Component\Serialization\Json;
6 use Drupal\simpletest\WebTestBase;
7
8 /**
9  * Tests the form API URL element.
10  *
11  * @group Form
12  */
13 class UrlTest extends WebTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['form_test'];
21
22   protected $profile = 'testing';
23
24   /**
25    * Tests that #type 'url' fields are properly validated and trimmed.
26    */
27   public function testFormUrl() {
28     $edit = [];
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']));
34
35     $edit = [];
36     $edit['url'] = "\n";
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/');
41
42     $edit = [];
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']);
48   }
49
50 }