class UrlTest
Same name in this branch
- 9 core/modules/system/tests/src/Kernel/Common/UrlTest.php \Drupal\Tests\system\Kernel\Common\UrlTest
- 9 core/modules/system/tests/src/Functional/Common/UrlTest.php \Drupal\Tests\system\Functional\Common\UrlTest
- 9 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Kernel/Common/UrlTest.php \Drupal\Tests\system\Kernel\Common\UrlTest
- 11.x core/modules/system/tests/src/Functional/Form/UrlTest.php \Drupal\Tests\system\Functional\Form\UrlTest
- 11.x core/modules/system/tests/src/Functional/Common/UrlTest.php \Drupal\Tests\system\Functional\Common\UrlTest
- 11.x core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest
- 10 core/modules/system/tests/src/Kernel/Common/UrlTest.php \Drupal\Tests\system\Kernel\Common\UrlTest
- 10 core/modules/system/tests/src/Functional/Form/UrlTest.php \Drupal\Tests\system\Functional\Form\UrlTest
- 10 core/modules/system/tests/src/Functional/Common/UrlTest.php \Drupal\Tests\system\Functional\Common\UrlTest
- 10 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest
- 8.9.x core/modules/system/tests/src/Functional/Form/UrlTest.php \Drupal\Tests\system\Functional\Form\UrlTest
- 8.9.x core/modules/system/tests/src/Functional/Common/UrlTest.php \Drupal\Tests\system\Functional\Common\UrlTest
- 8.9.x core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest
Tests the form API URL element.
@group Form
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Form\UrlTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of UrlTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Form/ UrlTest.php, line 13
Namespace
Drupal\Tests\system\Functional\FormView source
class UrlTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
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() {
$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']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.