3 namespace Drupal\Tests\comment\Kernel\Migrate\d7;
5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
6 use Drupal\Core\Field\FieldConfigInterface;
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
11 * Tests creation of comment reference fields for each comment type defined
16 class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
18 public static $modules = ['node', 'comment', 'text', 'menu_ui'];
23 protected function setUp() {
25 $this->installConfig(static::$modules);
26 $this->executeMigrations([
30 'd7_comment_field_instance',
35 * Asserts a comment field entity.
39 * @param string $field_name
41 * @param string $bundle
43 * @param int $default_mode
44 * The field's default_mode setting.
45 * @param int $per_page
46 * The field's per_page setting.
47 * @param bool $anonymous
48 * The field's anonymous setting.
49 * @param int $form_location
50 * The field's form_location setting.
51 * @param bool $preview
52 * The field's preview setting.
54 protected function assertEntity($id, $field_name, $bundle, $default_mode, $per_page, $anonymous, $form_location, $preview) {
55 $entity = FieldConfig::load($id);
56 $this->assertTrue($entity instanceof FieldConfigInterface);
57 /** @var \Drupal\field\FieldConfigInterface $entity */
58 $this->assertIdentical('node', $entity->getTargetEntityTypeId());
59 $this->assertIdentical('Comments', $entity->label());
60 $this->assertTrue($entity->isRequired());
61 $this->assertIdentical($field_name, $entity->getFieldStorageDefinition()->getName());
62 $this->assertIdentical($bundle, $entity->getTargetBundle());
63 $this->assertTrue($entity->get('default_value')[0]['status']);
64 $this->assertEqual($default_mode, $entity->getSetting('default_mode'));
65 $this->assertIdentical($per_page, $entity->getSetting('per_page'));
66 $this->assertEqual($anonymous, $entity->getSetting('anonymous'));
67 // This assertion fails because 1 !== TRUE. It's extremely strange that
68 // the form_location setting is returning a boolean, but this appears to
69 // be a problem with the entity, not with the migration.
70 // $this->asserIdentical($form_location, $entity->getSetting('form_location'));
71 $this->assertEqual($preview, $entity->getSetting('preview'));
75 * Tests the migrated fields.
77 public function testMigration() {
78 $this->assertEntity('node.page.comment_node_page', 'comment_node_page', 'page', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
79 $this->assertEntity('node.article.comment_node_article', 'comment_node_article', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
80 $this->assertEntity('node.blog.comment_node_blog', 'comment_node_blog', 'blog', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
81 $this->assertEntity('node.book.comment_node_book', 'comment_node_book', 'book', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
82 $this->assertEntity('node.forum.comment_node_forum', 'comment_node_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
83 $this->assertEntity('node.test_content_type.comment_node_test_content_type', 'comment_node_test_content_type', 'test_content_type', TRUE, 30, FALSE, CommentItemInterface::FORM_BELOW, TRUE);