You are here

public function NodewordsEntitiesTest::testMetatag in Metatag 8

Test Nodewords migration from Drupal 6 to Metatag in 8.

File

tests/src/Kernel/Migrate/d6/NodewordsEntitiesTest.php, line 121

Class

NodewordsEntitiesTest
Tests migration of per-entity data from Nodewords-D6.

Namespace

Drupal\Tests\metatag\Kernel\Migrate\d6

Code

public function testMetatag() {

  /** @var \Drupal\node\Entity\Node $node */
  $node = Node::load(23);
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertTrue($node
    ->hasField('field_metatag'));

  // This should have the "current revision" keywords value, indicating it is
  // the current revision.
  $expected = [
    'abstract' => 'Test abstract',
    'canonical_url' => 'this/url',
    'description' => 'Test description',
    'keywords' => 'Keyword 1, keyword 2',
    'robots' => 'nofollow, nosnippet',
    'title' => 'Test title',
  ];
  $this
    ->assertSame(serialize($expected), $node->field_metatag->value);
  $node = node_revision_load(2004);
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertTrue($node
    ->hasField('field_metatag'));

  // This should have the "old revision" keywords value, indicating it is
  // a non-current revision.
  $expected = [
    'abstract' => 'Test abstract',
    'canonical_url' => 'this/url',
    'description' => 'Test description',
    'keywords' => 'Keyword 1, keyword 2',
    'robots' => 'nofollow, nosnippet',
    'title' => 'Test title',
  ];
  $this
    ->assertSame(serialize($expected), $node->field_metatag->value);

  /** @var \Drupal\user\Entity\User $user */
  $user = User::load(2);
  $this
    ->assertInstanceOf(UserInterface::class, $user);
  $this
    ->assertTrue($user
    ->hasField('field_metatag'));
  $expected = [
    'revisit_after' => '1',
    'robots' => '',
  ];
  $this
    ->assertSame(serialize($expected), $user->field_metatag->value);

  /** @var \Drupal\taxonomy\Entity\Term $term */
  $term = Term::load(16);
  $this
    ->assertInstanceOf(TermInterface::class, $term);
  $this
    ->assertTrue($term
    ->hasField('field_metatag'));
  $expected = [
    'canonical_url' => 'the-term',
    'keywords' => 'a taxonomy, term',
  ];
  $this
    ->assertSame(serialize($expected), $term->field_metatag->value);
}