public function MetatagTokenTest::testMetatagEntityTokens in Metatag 8
Test entity token generation.
File
- tests/
src/ Functional/ MetatagTokenTest.php, line 91
Class
- MetatagTokenTest
- Verify that metatag token generation is working.
Namespace
Drupal\Tests\metatag\FunctionalCode
public function testMetatagEntityTokens() {
$user = $this
->createUser();
$this
->drupalGet($user
->toUrl('edit-form'));
$this
->submitForm([
'field_metatags[0][basic][abstract]' => 'My abstract',
'field_metatags[0][open_graph][og_title]' => 'My OG Title',
'field_metatags[0][open_graph][og_image]' => 'Image 1,Image 2',
], 'Save');
$tokens = [
// Test globally configured metatags.
'[user:field_metatags:title]' => sprintf('%s | %s', $user
->getAccountName(), $this
->config('system.site')
->get('name')),
'[user:field_metatags:description]' => $this
->config('system.site')
->get('name'),
'[user:field_metatags:canonical-url]' => $user
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString(),
// Test entity overridden metatags.
'[user:field_metatags:abstract]' => 'My abstract',
// Test metatags provided by a submodule.
'[user:field_metatags:og-title]' => 'My OG Title',
// Test metatags that can contain multiple values.
'[user:field_metatags:og_image]' => 'Image 1,Image 2',
'[user:field_metatags:og_image:0]' => 'Image 1',
'[user:field_metatags:og_image:1]' => 'Image 2',
];
$this
->assertPageTokens($user
->toUrl(), $tokens, [
'user' => $user,
]);
}