DefaultMetatagsTest.php

Same filename in this branch
  1. 11.x core/modules/system/tests/src/Functional/Page/DefaultMetatagsTest.php
Same filename and directory in other branches
  1. 10 core/modules/system/tests/src/Functional/Page/DefaultMetatagsTest.php
  2. 9 core/modules/system/tests/src/Functional/Page/DefaultMetatagsTest.php
  3. 8.9.x core/modules/system/tests/src/Functional/Page/DefaultMetatagsTest.php
  4. main core/modules/system/tests/src/Functional/Page/DefaultMetatagsTest.php
  5. main core/modules/system/tests/src/Kernel/Page/DefaultMetatagsTest.php

Namespace

Drupal\Tests\system\Kernel\Page

File

core/modules/system/tests/src/Kernel/Page/DefaultMetatagsTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\system\Kernel\Page;

use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Tests default HTML metatags on a page.
 */
class DefaultMetatagsTest extends KernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->installConfig([
      'system',
    ]);
  }
  
  /**
   * Tests meta tags.
   */
  public function testMetaTag() : void {
    $this->drupalGet('');
    // Ensures that the charset metatag is on the page.
    $this->assertSession()
      ->elementsCount('xpath', '//meta[@charset="utf-8"]', 1);
    // Ensure that the charset one is the first metatag.
    $result = $this->getSession()
      ->getPage()
      ->findAll('xpath', '//meta');
    $this->assertEquals('utf-8', (string) $result[0]->getAttribute('charset'));
    // Ensure that the icon is on the page.
    $this->assertSession()
      ->elementsCount('xpath', '//link[@rel = "icon"]', 1);
  }

}

Classes

Title Deprecated Summary
DefaultMetatagsTest Tests default HTML metatags on a page.

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