function HtmlResponseAttachmentsTest::assertHead

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php \Drupal\Tests\system\Functional\Render\HtmlResponseAttachmentsTest::assertHead()
  2. 10 core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php \Drupal\Tests\system\Functional\Render\HtmlResponseAttachmentsTest::assertHead()
  3. 11.x core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php \Drupal\Tests\system\Functional\Render\HtmlResponseAttachmentsTest::assertHead()

Helper function to make assertions about HTML head elements.

2 calls to HtmlResponseAttachmentsTest::assertHead()
HtmlResponseAttachmentsTest::testAttachments in core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php
Test rendering of ['#attached'].
HtmlResponseAttachmentsTest::testRenderCachedBlock in core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php
Test caching of ['#attached'].

File

core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php, line 135

Class

HtmlResponseAttachmentsTest
Functional tests for HtmlResponseAttachmentsProcessor.

Namespace

Drupal\Tests\system\Functional\Render

Code

protected function assertHead() {
    // Discover the DOM element for the meta link.
    $test_meta = $this->xpath('//head/meta[@test-attribute="testvalue"]');
    $this->assertCount(1, $test_meta, 'There\'s only one test attribute.');
    // Grab the only DOM element.
    $test_meta = reset($test_meta);
    if (empty($test_meta)) {
        $this->fail('Unable to find the head meta.');
    }
    else {
        $this->assertEqual($test_meta->getAttribute('test-attribute'), 'testvalue');
    }
}

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