function UrlTest::testLinkCustomClass

Tests for custom class in links produced by l() and theme_link() functions.

File

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

Class

UrlTest
Tests for URL generation functions.

Namespace

Drupal\system\Tests\Common

Code

function testLinkCustomClass() {

  // Test l().
  $class_l = $this
    ->randomName();
  $link_l = l($this
    ->randomName(), current_path(), array(
    'attributes' => array(
      'class' => array(
        $class_l,
      ),
    ),
  ));
  $this
    ->assertTrue($this
    ->hasClass($link_l, $class_l), format_string('Custom class @class is present on link when requested by l()', array(
    '@class' => $class_l,
  )));

  // Test #theme.
  $class_theme = $this
    ->randomName();
  $theme_link = array(
    '#theme' => 'link',
    '#text' => $this
      ->randomName(),
    '#path' => current_path(),
    '#options' => array(
      'attributes' => array(
        'class' => array(
          $class_theme,
        ),
      ),
    ),
  );
  $link_theme = drupal_render($theme_link);
  $this
    ->assertTrue($this
    ->hasClass($link_theme, $class_theme), format_string('Custom class @class is present on link when requested by #theme', array(
    '@class' => $class_theme,
  )));
}