public function DisabledDefaultTags::testEntityBundleDefaults in Metatag 8
Test that a disabled node bundle metatag default doesn't load.
Throws
\Behat\Mink\Exception\ExpectationException
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Core\Entity\EntityMalformedException
\Drupal\Core\Entity\EntityStorageException
File
- tests/
src/ Functional/ DisabledDefaultTags.php, line 217
Class
- DisabledDefaultTags
- Verify that disabled metatag defaults do not load.
Namespace
Drupal\Tests\metatag\FunctionalCode
public function testEntityBundleDefaults() {
$node = $this
->createContentTypeNode();
$this_page_url = $node
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString();
// Change the node bundle's default's canonical to a hardcoded test string.
/** @var \Drupal\Core\Entity\EntityStorageInterface $global_metatag_manager */
$global_metatag_manager = \Drupal::entityTypeManager()
->getStorage('metatag_defaults');
/** @var \Drupal\metatag\Entity\MetatagDefaults $entity_metatags */
$entity_metatags = $global_metatag_manager
->create([
'id' => 'node__metatag_test',
]);
$entity_metatags
->overwriteTags([
'canonical_url' => 'https://test.canonical',
]);
$entity_metatags
->save();
// Load the node's entity page.
$this
->drupalGet($this_page_url);
$this
->assertSession()
->statusCodeEquals(200);
// Check the meta tags.
$xpath = $this
->xpath("//link[@rel='canonical']");
$this
->assertEquals((string) $xpath[0]
->getAttribute('href'), 'https://test.canonical');
// Now disable this metatag.
$entity_metatags
->set('status', 0);
$entity_metatags
->save();
// Clear caches.
drupal_flush_all_caches();
// Load the node's entity page.
$this
->drupalGet($this_page_url);
$this
->assertSession()
->statusCodeEquals(200);
// Check the meta tags.
$xpath = $this
->xpath("//link[@rel='canonical']");
// Should now match global or content one, which is node URL.
$this
->assertEquals((string) $xpath[0]
->getAttribute('href'), $this_page_url);
}