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/Form/UrlTest.php \Drupal\Tests\system\Functional\Form\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
Confirm that the link generator works correctly.
@group Common
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\Common\UrlTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of UrlTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Common/ UrlTest.php, line 13
Namespace
Drupal\Tests\system\Functional\CommonView source
class UrlTest extends BrowserTestBase {
protected static $modules = [
'common_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests the active class in links.
*/
public function testActiveLinkAttributes() {
$options_no_query = [];
$options_query = [
'query' => [
'foo' => 'bar',
'one' => 'two',
],
];
$options_query_reverse = [
'query' => [
'one' => 'two',
'foo' => 'bar',
],
];
// Test #type link.
$path = 'common-test/type-link-active-class';
$this->drupalGet($path, $options_no_query);
// Test that a link generated by the link generator to the current page is
// marked active.
$this->assertSession()
->elementExists('xpath', $this->assertSession()
->buildXPathQuery('//a[@href = :href and contains(@class, "is-active")]', [
':href' => Url::fromRoute('common_test.l_active_class', [], $options_no_query)->toString(),
]));
// Test that a link generated by the link generator to the current page
// with a query string when the current page has no query string is not
// marked active.
$this->assertSession()
->elementExists('xpath', $this->assertSession()
->buildXPathQuery('//a[@href = :href and not(contains(@class, "is-active"))]', [
':href' => Url::fromRoute('common_test.l_active_class', [], $options_query)->toString(),
]));
$this->drupalGet($path, $options_query);
// Test that a link generated by the link generator to the current page with
// a query string that matches the current query string is marked active.
$this->assertSession()
->elementExists('xpath', $this->assertSession()
->buildXPathQuery('//a[@href = :href and contains(@class, "is-active")]', [
':href' => Url::fromRoute('common_test.l_active_class', [], $options_query)->toString(),
]));
// Test that a link generated by the link generator to the current page with
// a query string that has matching parameters to the current query string
// but in a different order is marked active.
$this->assertSession()
->elementExists('xpath', $this->assertSession()
->buildXPathQuery('//a[@href = :href and contains(@class, "is-active")]', [
':href' => Url::fromRoute('common_test.l_active_class', [], $options_query_reverse)->toString(),
]));
// Test that a link generated by the link generator to the current page
// without a query string when the current page has a query string is not
// marked active.
$this->assertSession()
->elementExists('xpath', $this->assertSession()
->buildXPathQuery('//a[@href = :href and not(contains(@class, "is-active"))]', [
':href' => Url::fromRoute('common_test.l_active_class', [], $options_no_query)->toString(),
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.