public function MetatagEntitiesTest::testMetatag in Metatag 8
Test Metatag migration from Drupal 7 to 8.
File
- tests/
src/ Kernel/ Migrate/ d7/ MetatagEntitiesTest.php, line 120
Class
- MetatagEntitiesTest
- Tests migration of per-entity data from Metatag-D7.
Namespace
Drupal\Tests\metatag\Kernel\Migrate\d7Code
public function testMetatag() {
/** @var \Drupal\node\Entity\Node $node */
$node = Node::load(998);
$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 = [
'keywords' => 'current revision',
'canonical_url' => 'the-node',
'robots' => 'noindex, nofollow',
];
$this
->assertSame(serialize($expected), $node->field_metatag->value);
$node = node_revision_load(998);
$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 = [
'keywords' => 'old revision',
'canonical_url' => 'the-node',
'robots' => 'noindex, nofollow',
];
$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'));
// This should have the Utf8 converted description value.
$expected = [
'keywords' => 'a user',
'canonical_url' => 'the-user',
'description' => 'Drupal™ user',
];
$this
->assertSame(serialize($expected), $user->field_metatag->value);
/** @var \Drupal\taxonomy\Entity\Term $term */
$term = Term::load(152);
$this
->assertInstanceOf(TermInterface::class, $term);
$this
->assertTrue($term
->hasField('field_metatag'));
$expected = [
'keywords' => 'a taxonomy',
'canonical_url' => 'the-term',
];
$this
->assertSame(serialize($expected), $term->field_metatag->value);
}