3 namespace Drupal\Tests\comment\Kernel\Migrate\d7;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
9 * Tests the migration of comment field instances from Drupal 7.
12 * @group migrate_drupal_7
14 class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
19 public static $modules = ['node', 'comment', 'text', 'menu_ui'];
24 protected function setUp() {
26 $this->installConfig(['comment', 'node']);
27 $this->executeMigrations([
31 'd7_comment_field_instance',
36 * Asserts a comment field instance entity.
38 * @param string $bundle
40 * @param string $field_name
42 * @param int $default_value
43 * The field's default_value setting.
44 * @param int $default_mode
45 * The field's default_mode setting.
46 * @param int $per_page
47 * The field's per_page setting.
48 * @param bool $anonymous
49 * The field's anonymous setting.
50 * @param int $form_location
51 * The field's form_location setting.
52 * @param bool $preview
53 * The field's preview setting.
55 protected function assertEntity($bundle, $field_name, $default_value, $default_mode, $per_page, $anonymous, $form_location, $preview) {
56 $entity = FieldConfig::load("node.$bundle.$field_name");
57 $this->assertInstanceOf(FieldConfig::class, $entity);
58 $this->assertSame('node', $entity->getTargetEntityTypeId());
59 $this->assertSame('Comments', $entity->label());
60 $this->assertTrue($entity->isRequired());
61 $this->assertSame($bundle, $entity->getTargetBundle());
62 $this->assertSame($field_name, $entity->getFieldStorageDefinition()->getName());
63 $this->assertSame($default_value, $entity->get('default_value')[0]['status']);
64 $this->assertSame($default_mode, $entity->getSetting('default_mode'));
65 $this->assertSame($per_page, $entity->getSetting('per_page'));
66 $this->assertSame($anonymous, $entity->getSetting('anonymous'));
67 $this->assertSame($form_location, $entity->getSetting('form_location'));
68 $this->assertSame($preview, $entity->getSetting('preview'));
72 * Tests the migrated fields.
74 public function testMigration() {
75 $this->assertEntity('page', 'comment_node_page', 0, 1, 50, 0, TRUE, 1);
76 $this->assertEntity('article', 'comment_node_article', 2, 1, 50, 0, TRUE, 1);
77 $this->assertEntity('blog', 'comment_node_blog', 2, 1, 50, 0, TRUE, 1);
78 $this->assertEntity('book', 'comment_node_book', 2, 1, 50, 0, TRUE, 1);
79 $this->assertEntity('forum', 'comment_forum', 2, 1, 50, 0, TRUE, 1);
80 $this->assertEntity('test_content_type', 'comment_node_test_content_type', 2, 1, 30, 0, TRUE, 1);