1<?php
2
3namespace Drupal\Tests\comment\Kernel\Migrate\d7;
4
5use Drupal\field\Entity\FieldStorageConfig;
6use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
7
8/**
9 * Tests the migration of comment fields from Drupal 7.
10 *
11 * @group comment
12 * @group migrate_drupal_7
13 */
14class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
15
16  /**
17   * {@inheritdoc}
18   */
19  public static $modules = ['node', 'comment', 'text'];
20
21  /**
22   * {@inheritdoc}
23   */
24  protected function setUp() {
25    parent::setUp();
26    $this->migrateCommentTypes();
27    $this->executeMigration('d7_comment_field');
28  }
29
30  /**
31   * Asserts a comment field entity.
32   *
33   * @param string $comment_type
34   *   The comment type.
35   */
36  protected function assertEntity($comment_type) {
37    $entity = FieldStorageConfig::load('node.' . $comment_type);
38    $this->assertInstanceOf(FieldStorageConfig::class, $entity);
39    $this->assertSame('node', $entity->getTargetEntityTypeId());
40    $this->assertSame('comment', $entity->getType());
41    $this->assertSame($comment_type, $entity->getSetting('comment_type'));
42  }
43
44  /**
45   * Tests the migrated comment fields.
46   */
47  public function testMigration() {
48    $this->assertEntity('comment_node_page');
49    $this->assertEntity('comment_node_article');
50    $this->assertEntity('comment_node_blog');
51    $this->assertEntity('comment_node_book');
52    $this->assertEntity('comment_forum');
53    $this->assertEntity('comment_node_test_content_type');
54    $this->assertEntity('comment_node_et');
55  }
56
57}
58