public function MetatagFieldTestBase::testEntityDefaultsInheritance in Metatag 8
Confirm that the entity default values work correctly.
File
- tests/
src/ Functional/ MetatagFieldTestBase.php, line 231
Class
- MetatagFieldTestBase
- Base class for ensuring that the Metatag field works correctly.
Namespace
Drupal\Tests\metatag\FunctionalCode
public function testEntityDefaultsInheritance() {
// This test doesn't make sense if the entity doesn't support defaults.
if (!$this->entitySupportsDefaults) {
return;
}
// Set a global default.
$this
->drupalGet('admin/config/search/metatag/global');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$global_values = [
'metatag_test_tag' => 'Global description',
];
$this
->drupalPostForm(NULL, $global_values, 'Save');
$session
->pageTextContains(strip_tags('Saved the Global Metatag defaults.'));
// Set an entity default.
$this
->drupalGet('admin/config/search/metatag/' . $this->entityType);
$session
->statusCodeEquals(200);
$entity_values = [
'metatag_test_tag' => 'Entity description',
];
$this
->drupalPostForm(NULL, $entity_values, 'Save');
$session
->pageTextContains(strip_tags("Saved the {$this->entityLabel} Metatag defaults."));
// Add the field to this entity type.
$this
->addField();
// Load the entity form for this entity type.
$this
->drupalGet($this->entityAddPath);
$session
->statusCodeEquals(200);
$session
->pageTextNotContains('Fatal error');
// Allow the fields to be customized if needed.
$title = 'Barfoo';
$edit = $this
->entityDefaultValues();
if (empty($edit)) {
$edit = [
$this->entityTitleField . '[0][value]' => $title,
];
}
// If this entity type supports defaults then verify the global default is
// not present but that the entity default *is* present.
$session
->fieldValueEquals('field_metatag[0][basic][metatag_test_tag]', $entity_values['metatag_test_tag']);
$session
->fieldValueNotEquals('field_metatag[0][basic][metatag_test_tag]', $global_values['metatag_test_tag']);
}