You are here

public function MetatagTokenTest::testMetatagCurrentPageTokens in Metatag 8

Test current-page metatag token generation.

File

tests/src/Functional/MetatagTokenTest.php, line 59

Class

MetatagTokenTest
Verify that metatag token generation is working.

Namespace

Drupal\Tests\metatag\Functional

Code

public function testMetatagCurrentPageTokens() {
  $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.
    '[current-page:metatag:title]' => sprintf('%s | %s', $user
      ->getAccountName(), $this
      ->config('system.site')
      ->get('name')),
    '[current-page:metatag:description]' => $this
      ->config('system.site')
      ->get('name'),
    '[current-page:metatag:canonical-url]' => $user
      ->toUrl('canonical', [
      'absolute' => TRUE,
    ])
      ->toString(),
    // Test entity overridden metatags.
    '[current-page:metatag:abstract]' => 'My abstract',
    // Test metatags provided by a submodule.
    '[current-page:metatag:og-title]' => 'My OG Title',
    // Test metatags that can contain multiple values.
    '[current-page:metatag:og_image]' => 'Image 1,Image 2',
    '[current-page:metatag:og_image:0]' => 'Image 1',
    '[current-page:metatag:og_image:1]' => 'Image 2',
  ];
  $this
    ->assertPageTokens($user
    ->toUrl(), $tokens);
}