public function MetatagAdminTest::testEntityDefaultInheritence in Metatag 8
Test that the entity default values load on the entity form.
And that they can then be overridden correctly.
File
- tests/
src/ Functional/ MetatagAdminTest.php, line 365
Class
- MetatagAdminTest
- Tests the Metatag administration.
Namespace
Drupal\Tests\metatag\FunctionalCode
public function testEntityDefaultInheritence() {
// Initiate session with a user who can manage meta tags and content type
// fields.
$permissions = [
'administer site configuration',
'administer meta tags',
'access content',
'administer node fields',
'create article content',
'administer nodes',
'create article content',
'create page content',
];
$account = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($account);
// Add a Metatag field to the Article content type.
$this
->drupalGet('admin/structure/types/manage/article/fields/add-field');
$session = $this
->assertSession();
$session
->statusCodeEquals(200);
$edit = [
'new_storage_type' => 'metatag',
'label' => 'Meta tags',
'field_name' => 'meta_tags',
];
$this
->drupalPostForm(NULL, $edit, $this
->t('Save and continue'));
$this
->drupalPostForm(NULL, [], $this
->t('Save field settings'));
$session
->pageTextContains(strip_tags('Updated field Meta tags field settings.'));
$this
->drupalPostForm(NULL, [], $this
->t('Save settings'));
$session
->pageTextContains(strip_tags('Saved Meta tags configuration.'));
// Try creating an article, confirm the fields are present. This should be
// the node default values that are shown.
$this
->drupalGet('node/add/article');
$session
->statusCodeEquals(200);
$session
->fieldValueEquals('field_meta_tags[0][basic][title]', '[node:title] | [site:name]');
$session
->fieldValueEquals('field_meta_tags[0][basic][description]', '[node:summary]');
// Customize the Article content type defaults.
$this
->drupalGet('admin/config/search/metatag/add');
$session
->statusCodeEquals(200);
$values = [
'id' => 'node__article',
'title' => 'Article title override',
'description' => 'Article description override',
];
$this
->drupalPostForm(NULL, $values, 'Save');
$session
->pageTextContains(strip_tags('Created the Content: Article Metatag defaults.'));
// Try creating an article, this time with the overridden defaults.
$this
->drupalGet('node/add/article');
$session
->statusCodeEquals(200);
$session
->fieldValueEquals('field_meta_tags[0][basic][title]', 'Article title override');
$session
->fieldValueEquals('field_meta_tags[0][basic][description]', 'Article description override');
}