You are here

public function DisabledDefaultTags::test403 in Metatag 8

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

File

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

Class

DisabledDefaultTags
Verify that disabled metatag defaults do not load.

Namespace

Drupal\Tests\metatag\Functional

Code

public function test403() {
  $metatag = $this
    ->loadMetatagDefault('403');
  $metatag
    ->overwriteTags([
    'canonical_url' => 'https://test.canonical',
  ]);
  $metatag
    ->save();
  $this
    ->drupalGet('admin/content');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $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('admin/content');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $xpath = $this
    ->xpath("//link[@rel='canonical']");

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