UrlTest.php

Same filename in this branch
  1. 8.9.x core/modules/system/tests/src/Functional/Common/UrlTest.php
  2. 8.9.x core/tests/Drupal/Tests/Core/UrlTest.php
Same filename in other branches
  1. 9 core/modules/system/tests/src/Kernel/Common/UrlTest.php
  2. 9 core/modules/system/tests/src/Functional/Form/UrlTest.php
  3. 9 core/modules/system/tests/src/Functional/Common/UrlTest.php
  4. 9 core/tests/Drupal/Tests/Core/UrlTest.php
  5. 10 core/modules/system/tests/src/Kernel/Common/UrlTest.php
  6. 10 core/modules/system/tests/src/Functional/Form/UrlTest.php
  7. 10 core/modules/system/tests/src/Functional/Common/UrlTest.php
  8. 10 core/tests/Drupal/Tests/Core/UrlTest.php
  9. 11.x core/modules/system/tests/src/Kernel/Common/UrlTest.php
  10. 11.x core/modules/system/tests/src/Functional/Form/UrlTest.php
  11. 11.x core/modules/system/tests/src/Functional/Common/UrlTest.php
  12. 11.x core/tests/Drupal/Tests/Core/UrlTest.php

Namespace

Drupal\Tests\system\Functional\Form

File

core/modules/system/tests/src/Functional/Form/UrlTest.php

View source
<?php

namespace Drupal\Tests\system\Functional\Form;

use Drupal\Component\Serialization\Json;
use Drupal\Tests\BrowserTestBase;

/**
 * Tests the form API URL element.
 *
 * @group Form
 */
class UrlTest extends BrowserTestBase {
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    public static $modules = [
        'form_test',
    ];
    protected $profile = 'testing';
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests that #type 'url' fields are properly validated and trimmed.
     */
    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']);
    }

}

Classes

Title Deprecated Summary
UrlTest Tests the form API URL element.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.