class MigrateCommentTest
Same name in this branch
- 9 core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTest
Same name and namespace in other branches
- 11.x core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTest
- 11.x core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTest
Tests the migration of comments from Drupal 6.
@group comment @group migrate_drupal_6
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\migrate\Kernel\MigrateTestBase extends \Drupal\migrate\MigrateMessageInterface implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase implements \Drupal\Tests\migrate\Kernel\MigrateTestBase
- class \Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase uses \Drupal\Tests\migrate_drupal\Traits\NodeMigrateTypeTestTrait implements \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase
- class \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTest uses \Drupal\comment\Tests\CommentTestTrait implements \Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase
- class \Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase uses \Drupal\Tests\migrate_drupal\Traits\NodeMigrateTypeTestTrait implements \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase
- class \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase implements \Drupal\Tests\migrate\Kernel\MigrateTestBase
- class \Drupal\Tests\migrate\Kernel\MigrateTestBase extends \Drupal\migrate\MigrateMessageInterface implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of MigrateCommentTest
File
-
core/
modules/ comment/ tests/ src/ Kernel/ Migrate/ d6/ MigrateCommentTest.php, line 16
Namespace
Drupal\Tests\comment\Kernel\Migrate\d6View source
class MigrateCommentTest extends MigrateDrupal6TestBase {
use CommentTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'comment',
'content_translation',
'language',
'menu_ui',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installSchema('comment', [
'comment_entity_statistics',
]);
$this->installSchema('node', [
'node_access',
]);
$this->installConfig([
'comment',
]);
$this->migrateContent();
$this->executeMigrations([
'language',
'd6_language_content_settings',
'd6_node',
'd6_node_translation',
'd6_comment_type',
'd6_comment_field',
'd6_comment_field_instance',
'd6_comment_entity_display',
'd6_comment_entity_form_display',
'd6_comment',
]);
}
/**
* Tests the migrated comments.
*/
public function testMigration() {
$comment = Comment::load(1);
$this->assertSame('The first comment.', $comment->getSubject());
$this->assertSame('The first comment body.', $comment->comment_body->value);
$this->assertSame('filtered_html', $comment->comment_body->format);
$this->assertSame(NULL, $comment->pid->target_id);
$this->assertSame('1', $comment->getCommentedEntityId());
$this->assertSame('node', $comment->getCommentedEntityTypeId());
$this->assertSame('en', $comment->language()
->getId());
$this->assertSame('comment_node_story', $comment->getTypeId());
$this->assertSame('203.0.113.1', $comment->getHostname());
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('1', $node->id());
$comment = Comment::load(2);
$this->assertSame('The response to the second comment.', $comment->subject->value);
$this->assertSame('3', $comment->pid->target_id);
$this->assertSame('203.0.113.2', $comment->getHostname());
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('1', $node->id());
$comment = Comment::load(3);
$this->assertSame('The second comment.', $comment->subject->value);
$this->assertSame(NULL, $comment->pid->target_id);
$this->assertSame('203.0.113.3', $comment->getHostname());
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('1', $node->id());
// Tests that the language of the comment is migrated from the node.
$comment = Comment::load(7);
$this->assertSame('Comment to John Smith - EN', $comment->subject->value);
$this->assertSame('This is an English comment.', $comment->comment_body->value);
$this->assertSame('21', $comment->getCommentedEntityId());
$this->assertSame('node', $comment->getCommentedEntityTypeId());
$this->assertSame('en', $comment->language()
->getId());
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('21', $node->id());
// Tests that the comment language is correct and that the commented entity
// is correctly migrated when the comment was posted to a node translation.
$comment = Comment::load(8);
$this->assertSame('Comment to John Smith - FR', $comment->subject->value);
$this->assertSame('This is a French comment.', $comment->comment_body->value);
$this->assertSame('21', $comment->getCommentedEntityId());
$this->assertSame('node', $comment->getCommentedEntityTypeId());
$this->assertSame('fr', $comment->language()
->getId());
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('21', $node->id());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.