function UrlTest::testLinkRenderArrayText

Tests that link functions support render arrays as 'text'.

File

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

Class

UrlTest
Tests for URL generation functions.

Namespace

Drupal\system\Tests\Common

Code

function testLinkRenderArrayText() {

  // Build a link with l() for reference.
  $l = l('foo', 'http://drupal.org');

  // Test a renderable array passed to l().
  $renderable_text = array(
    '#markup' => 'foo',
  );
  $l_renderable_text = l($renderable_text, 'http://drupal.org');
  $this
    ->assertEqual($l_renderable_text, $l);

  // Test a themed link with plain text 'text'.
  $theme_link_plain_array = array(
    '#theme' => 'link',
    '#text' => 'foo',
    '#path' => 'http://drupal.org',
  );
  $theme_link_plain = drupal_render($theme_link_plain_array);
  $this
    ->assertEqual($theme_link_plain, $l);

  // Build a themed link with renderable 'text'.
  $theme_link_nested_array = array(
    '#theme' => 'link',
    '#text' => array(
      '#markup' => 'foo',
    ),
    '#path' => 'http://drupal.org',
  );
  $theme_link_nested = drupal_render($theme_link_nested_array);
  $this
    ->assertEqual($theme_link_nested, $l);
}