View source
<?php
namespace Drupal\Tests\system\Functional\Common;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class UrlTest extends BrowserTestBase {
protected static $modules = [
'common_test',
];
protected $defaultTheme = 'stark';
public function testActiveLinkAttributes() {
$options_no_query = [];
$options_query = [
'query' => [
'foo' => 'bar',
'one' => 'two',
],
];
$options_query_reverse = [
'query' => [
'one' => 'two',
'foo' => 'bar',
],
];
$path = 'common-test/type-link-active-class';
$this
->drupalGet($path, $options_no_query);
$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(),
]));
$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);
$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(),
]));
$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(),
]));
$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(),
]));
}
}