You are here

public function DisabledDefaultTags::testFrontpage in Metatag 8

Test that a disabled Frontpage metatag default doesn't load.

File

tests/src/Functional/DisabledDefaultTags.php, line 81

Class

DisabledDefaultTags
Verify that disabled metatag defaults do not load.

Namespace

Drupal\Tests\metatag\Functional

Code

public function testFrontpage() {
  $metatag = $this
    ->loadMetatagDefault('front');
  $metatag
    ->overwriteTags([
    'canonical_url' => 'https://test.canonical',
  ]);
  $metatag
    ->save();
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $xpath = $this
    ->xpath("//link[@rel='canonical']");
  $this
    ->assertEquals((string) $xpath[0]
    ->getAttribute('href'), 'https://test.canonical');

  // Now disable the default. Canonical should then fall back
  // to Global's default, which is page url.
  $metatag
    ->set('status', 0);
  $metatag
    ->save();
  drupal_flush_all_caches();
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $xpath = $this
    ->xpath("//link[@rel='canonical']");

  // The page url in Global will be /node's.
  $this_page_url = $this
    ->buildUrl('/node');
  $this
    ->assertEquals((string) $xpath[0]
    ->getAttribute('href'), $this_page_url);
}