function UrlTest::testLActiveClass

Tests for active class in l() function.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php, line 44
Definition of Drupal\system\Tests\Common\UrlTest.

Class

UrlTest
Tests for URL generation functions.

Namespace

Drupal\system\Tests\Common

Code

function testLActiveClass() {
  $path = 'common-test/l-active-class';
  $options = array();
  $this
    ->drupalGet($path, $options);
  $links = $this
    ->xpath('//a[@href = :href and contains(@class, :class)]', array(
    ':href' => url($path, $options),
    ':class' => 'active',
  ));
  $this
    ->assertTrue(isset($links[0]), 'A link to the current page is marked active.');
  $options = array(
    'query' => array(
      'foo' => 'bar',
    ),
  );
  $links = $this
    ->xpath('//a[@href = :href and not(contains(@class, :class))]', array(
    ':href' => url($path, $options),
    ':class' => 'active',
  ));
  $this
    ->assertTrue(isset($links[0]), 'A link to the current page with a query string when the current page has no query string is not marked active.');
  $this
    ->drupalGet($path, $options);
  $links = $this
    ->xpath('//a[@href = :href and contains(@class, :class)]', array(
    ':href' => url($path, $options),
    ':class' => 'active',
  ));
  $this
    ->assertTrue(isset($links[0]), 'A link to the current page with a query string that matches the current query string is marked active.');
  $options = array();
  $links = $this
    ->xpath('//a[@href = :href and not(contains(@class, :class))]', array(
    ':href' => url($path, $options),
    ':class' => 'active',
  ));
  $this
    ->assertTrue(isset($links[0]), 'A link to the current page without a query string when the current page has a query string is not marked active.');
}