4b928f7a3d41f01124644b56d4adb7856ee396dc
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / Migrate / d7 / MigrateCommentFieldInstanceTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel\Migrate\d7;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
7
8 /**
9  * Tests the migration of comment field instances from Drupal 7.
10  *
11  * @group comment
12  * @group migrate_drupal_7
13  */
14 class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = ['node', 'comment', 'text', 'menu_ui'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26     $this->installConfig(['comment', 'node']);
27     $this->executeMigrations([
28       'd7_node_type',
29       'd7_comment_type',
30       'd7_comment_field',
31       'd7_comment_field_instance',
32     ]);
33   }
34
35   /**
36    * Asserts a comment field instance entity.
37    *
38    * @param string $bundle
39    *   The bundle ID.
40    * @param string $field_name
41    *   The 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.
54    */
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'));
69   }
70
71   /**
72    * Tests the migrated fields.
73    */
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);
81   }
82
83 }