UrlTest.php

Same filename in this branch
  1. 11.x core/modules/system/tests/src/Kernel/Common/UrlTest.php
  2. 11.x core/modules/system/tests/src/Functional/Common/UrlTest.php
  3. 11.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. 8.9.x core/modules/system/tests/src/Functional/Form/UrlTest.php
  6. 8.9.x core/modules/system/tests/src/Functional/Common/UrlTest.php
  7. 8.9.x core/tests/Drupal/Tests/Core/UrlTest.php
  8. 10 core/modules/system/tests/src/Kernel/Common/UrlTest.php
  9. 10 core/modules/system/tests/src/Functional/Form/UrlTest.php
  10. 10 core/modules/system/tests/src/Functional/Common/UrlTest.php
  11. 10 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

declare (strict_types=1);
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 {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'form_test',
    ];
    protected $profile = 'testing';
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests that #type 'url' fields are properly validated and trimmed.
     */
    public function testFormUrl() : void {
        $edit = [];
        $edit['url'] = 'http://';
        $edit['url_required'] = ' ';
        $this->drupalGet('form-test/url');
        $this->submitForm($edit, 'Submit');
        $this->assertSession()
            ->pageTextContains("The URL http:// is not valid.");
        $this->assertSession()
            ->pageTextContains("Required URL field is required.");
        $edit = [];
        $edit['url'] = "\n";
        $edit['url_required'] = 'http://example.com/   ';
        $this->drupalGet('form-test/url');
        $this->submitForm($edit, 'Submit');
        $values = Json::decode($this->getSession()
            ->getPage()
            ->getContent());
        $this->assertSame('', $values['url']);
        $this->assertEquals('http://example.com/', $values['url_required']);
        $edit = [];
        $edit['url'] = 'http://foo.bar.example.com/';
        $edit['url_required'] = 'https://www.drupal.org/node/1174630?page=0&foo=bar#new';
        $this->drupalGet('form-test/url');
        $this->submitForm($edit, 'Submit');
        $values = Json::decode($this->getSession()
            ->getPage()
            ->getContent());
        $this->assertEquals($edit['url'], $values['url']);
        $this->assertEquals($edit['url_required'], $values['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.