b995bdb0a532233f1a4dc707cb59a7379cc5a76e
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / Migrate / d7 / MigrateCommentFieldTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel\Migrate\d7;
4
5 use Drupal\field\Entity\FieldStorageConfig;
6 use Drupal\field\FieldStorageConfigInterface;
7 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
8
9 /**
10  * Tests creation of comment reference fields for each comment type defined
11  * in Drupal 7.
12  *
13  * @group comment
14  */
15 class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
16
17   public static $modules = ['node', 'comment', 'text', 'menu_ui'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp() {
23     parent::setUp();
24     $this->installConfig(static::$modules);
25     $this->executeMigrations([
26       'd7_node_type',
27       'd7_comment_type',
28       'd7_comment_field',
29     ]);
30   }
31
32   /**
33    * Asserts a comment field entity.
34    *
35    * @param string $id
36    *   The entity ID.
37    * @param string $comment_type
38    *   The comment type (bundle ID) the field references.
39    */
40   protected function assertEntity($id, $comment_type) {
41     $entity = FieldStorageConfig::load($id);
42     $this->assertTrue($entity instanceof FieldStorageConfigInterface);
43     /** @var \Drupal\field\FieldStorageConfigInterface $entity */
44     $this->assertIdentical('node', $entity->getTargetEntityTypeId());
45     $this->assertIdentical('comment', $entity->getType());
46     $this->assertIdentical($comment_type, $entity->getSetting('comment_type'));
47   }
48
49   /**
50    * Tests the migrated fields.
51    */
52   public function testMigration() {
53     $this->assertEntity('node.comment_node_page', 'comment_node_page');
54     $this->assertEntity('node.comment_node_article', 'comment_node_article');
55     $this->assertEntity('node.comment_node_blog', 'comment_node_blog');
56     $this->assertEntity('node.comment_node_book', 'comment_node_book');
57     $this->assertEntity('node.comment_node_forum', 'comment_node_forum');
58     $this->assertEntity('node.comment_node_test_content_type', 'comment_node_test_content_type');
59   }
60
61 }