X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FKernel%2FMigrate%2Fd6%2FMigrateCommentTest.php;h=e040ac0deb05aa807ab12e8573937cf530e96ee7;hb=4f1b9b4ab48a8498afac9e2213a02a23ccf4a06c;hp=2a13178f6774fb330fd796232df3de4b862fec80;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php b/web/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php index 2a13178f6..e040ac0de 100644 --- a/web/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php +++ b/web/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php @@ -2,12 +2,15 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d6; +use Drupal\comment\Entity\Comment; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; +use Drupal\node\NodeInterface; /** - * Upgrade comments. + * Tests the migration of comments from Drupal 6. * + * @group comment * @group migrate_drupal_6 */ class MigrateCommentTest extends MigrateDrupal6TestBase { @@ -17,7 +20,12 @@ class MigrateCommentTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['comment', 'menu_ui']; + public static $modules = [ + 'comment', + 'content_translation', + 'language', + 'menu_ui', + ]; /** * {@inheritdoc} @@ -28,6 +36,7 @@ class MigrateCommentTest extends MigrateDrupal6TestBase { $this->installEntitySchema('node'); $this->installEntitySchema('comment'); $this->installSchema('comment', ['comment_entity_statistics']); + $this->installSchema('node', ['node_access']); $this->installConfig(['comment']); // The entity.node.canonical route must exist when the RDF hook is called. @@ -35,7 +44,10 @@ class MigrateCommentTest extends MigrateDrupal6TestBase { $this->migrateContent(); $this->executeMigrations([ + 'language', + 'd6_language_content_settings', 'd6_node', + 'd6_node_translation', 'd6_comment_type', 'd6_comment_field', 'd6_comment_field_instance', @@ -46,32 +58,66 @@ class MigrateCommentTest extends MigrateDrupal6TestBase { } /** - * Tests the Drupal 6 to Drupal 8 comment migration. + * Tests the migrated comments. */ - public function testComments() { - /** @var \Drupal\Core\Entity\EntityStorageInterface $comment_storage */ - $comment_storage = $this->container->get('entity.manager')->getStorage('comment'); - /** @var \Drupal\comment\CommentInterface $comment */ - $comment = $comment_storage->load(1); - $this->assertIdentical('The first comment.', $comment->getSubject()); - $this->assertIdentical('The first comment body.', $comment->comment_body->value); - $this->assertIdentical('filtered_html', $comment->comment_body->format); - $this->assertIdentical(NULL, $comment->pid->target_id); - $this->assertIdentical('1', $comment->getCommentedEntityId()); - $this->assertIdentical('node', $comment->getCommentedEntityTypeId()); - $this->assertIdentical('en', $comment->language()->getId()); - $this->assertIdentical('comment_no_subject', $comment->getTypeId()); - $this->assertEquals('203.0.113.1', $comment->getHostname()); - - $comment = $comment_storage->load(2); - $this->assertIdentical('The response to the second comment.', $comment->subject->value); - $this->assertIdentical('3', $comment->pid->target_id); - $this->assertEquals('203.0.113.2', $comment->getHostname()); - - $comment = $comment_storage->load(3); - $this->assertIdentical('The second comment.', $comment->subject->value); - $this->assertIdentical(NULL, $comment->pid->target_id); - $this->assertEquals('203.0.113.3', $comment->getHostname()); + 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()); } }