function AttributeTest::testPrint

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testPrint()
  2. 10 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testPrint()
  3. 11.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::testPrint()

Tests printing of an attribute.

File

core/tests/Drupal/Tests/Core/Template/AttributeTest.php, line 343

Class

AttributeTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Template%21Attribute.php/class/Attribute/9" title="Collects, sanitizes, and renders HTML attributes." class="local">\Drupal\Core\Template\Attribute</a> @group Template

Namespace

Drupal\Tests\Core\Template

Code

public function testPrint() {
    $attribute = new Attribute([
        'class' => [
            'example-class',
        ],
        'id' => 'example-id',
        'enabled' => TRUE,
    ]);
    $content = $this->randomMachineName();
    $html = '<div' . (string) $attribute . '>' . $content . '</div>';
    $this->assertClass('example-class', $html);
    $this->assertNoClass('example-class2', $html);
    $this->assertID('example-id', $html);
    $this->assertNoID('example-id2', $html);
    $this->assertStringContainsString('enabled', $html);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.