Version 1
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / Migrate / d7 / MigrateCommentTypeTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel\Migrate\d7;
4
5 use Drupal\comment\CommentTypeInterface;
6 use Drupal\comment\Entity\CommentType;
7 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
8
9 /**
10  * Tests migration of comment types from Drupal 7.
11  *
12  * @group comment
13  */
14 class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
15
16   public static $modules = ['node', 'comment', 'text', 'menu_ui'];
17
18   /**
19    * {@inheritdoc}
20    */
21   protected function setUp() {
22     parent::setUp();
23     $this->installConfig(static::$modules);
24     $this->executeMigrations([
25       'd7_node_type',
26       'd7_comment_type',
27     ]);
28   }
29
30   /**
31    * Asserts a comment type entity.
32    *
33    * @param string $id
34    *   The entity ID.
35    * @param string $label
36    *   The entity label.
37    */
38   protected function assertEntity($id, $label) {
39     $entity = CommentType::load($id);
40     $this->assertTrue($entity instanceof CommentTypeInterface);
41     /** @var \Drupal\comment\CommentTypeInterface $entity */
42     $this->assertIdentical($label, $entity->label());
43     $this->assertIdentical('node', $entity->getTargetEntityTypeId());
44   }
45
46   /**
47    * Tests the migrated comment types.
48    */
49   public function testMigration() {
50     $this->assertEntity('comment_node_page', 'Basic page comment');
51     $this->assertEntity('comment_node_article', 'Article comment');
52     $this->assertEntity('comment_node_blog', 'Blog entry comment');
53     $this->assertEntity('comment_node_book', 'Book page comment');
54     $this->assertEntity('comment_node_forum', 'Forum topic comment');
55     $this->assertEntity('comment_node_test_content_type', 'Test content type comment');
56
57     $migration = $this->getMigration('d7_comment_type');
58     // Validate that the source count and processed count match up.
59     $this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
60   }
61
62 }