You are here

function RenderElementTypesTest::testHtmlTag in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Common/RenderElementTypesTest.php \Drupal\system\Tests\Common\RenderElementTypesTest::testHtmlTag()

Tests system #type 'html_tag'.

File

core/modules/system/src/Tests/Common/RenderElementTypesTest.php, line 88
Contains \Drupal\system\Tests\Common\RenderElementTypesTest.

Class

RenderElementTypesTest
Tests the markup of core render element types passed to drupal_render().

Namespace

Drupal\system\Tests\Common

Code

function testHtmlTag() {

  // Test void element.
  $this
    ->assertElements(array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#value' => 'ignored',
    '#attributes' => array(
      'name' => 'description',
      'content' => 'Drupal test',
    ),
  ), '<meta name="description" content="Drupal test" />' . "\n", "#type 'html_tag', void element renders properly");

  // Test non-void element.
  $this
    ->assertElements(array(
    '#type' => 'html_tag',
    '#tag' => 'section',
    '#value' => 'value',
    '#attributes' => array(
      'class' => array(
        'unicorns',
      ),
    ),
  ), '<section class="unicorns">value</section>' . "\n", "#type 'html_tag', non-void element renders properly");

  // Test empty void element tag.
  $this
    ->assertElements(array(
    '#type' => 'html_tag',
    '#tag' => 'link',
  ), "<link />\n", "#type 'html_tag' empty void element renders properly");

  // Test empty non-void element tag.
  $this
    ->assertElements(array(
    '#type' => 'html_tag',
    '#tag' => 'section',
  ), "<section></section>\n", "#type 'html_tag' empty non-void element renders properly");
}