public function DisabledDefaultTags::test404 in Metatag 8
Test that a disabled 404 metatag default doesn't load.
File
- tests/
src/ Functional/ DisabledDefaultTags.php, line 108
Class
- DisabledDefaultTags
- Verify that disabled metatag defaults do not load.
Namespace
Drupal\Tests\metatag\FunctionalCode
public function test404() {
$metatag = $this
->loadMetatagDefault('404');
$metatag
->overwriteTags([
'canonical_url' => 'https://test.canonical',
]);
$metatag
->save();
$this
->drupalGet('i-dont-exist');
$this
->assertSession()
->statusCodeEquals(404);
$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('i-dont-exist');
$this
->assertSession()
->statusCodeEquals(404);
$xpath = $this
->xpath("//link[@rel='canonical']");
// The page url in Global will be /node's.
$this_page_url = $this
->buildUrl('<front>');
$this
->assertEquals((string) $xpath[0]
->getAttribute('href'), $this_page_url . 'i-dont-exist');
}