diff --git a/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml b/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml index 8c293ff831..8a68f3195a 100644 --- a/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml +++ b/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml @@ -27,12 +27,12 @@ process: hidden: plugin: static_map source: comment_subject_field - bypass: true map: # If comment_subject_field = FALSE, then hidden = TRUE. 0: true # If comment_subject_field = TRUE, then hidden = FALSE. 1: false + default_value: false destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/comment/migration_templates/d6_comment_field.yml b/core/modules/comment/migration_templates/d6_comment_field.yml index b9a5dea132..5cbf5d41f4 100644 --- a/core/modules/comment/migration_templates/d6_comment_field.yml +++ b/core/modules/comment/migration_templates/d6_comment_field.yml @@ -21,9 +21,6 @@ process: 'settings/comment_type': '@field_name' destination: plugin: entity:field_storage_config - dependencies: - module: - - comment migration_dependencies: required: - d6_comment_type diff --git a/core/modules/comment/migration_templates/d6_comment_field_instance.yml b/core/modules/comment/migration_templates/d6_comment_field_instance.yml index a19699ded1..741ccf2e91 100644 --- a/core/modules/comment/migration_templates/d6_comment_field_instance.yml +++ b/core/modules/comment/migration_templates/d6_comment_field_instance.yml @@ -29,7 +29,8 @@ process: map: 0: 0 1: 1 - default_value: 1 + 2: 2 + default_value: 2 'settings/default_mode': plugin: static_map source: comment_default_mode @@ -68,5 +69,5 @@ destination: plugin: entity:field_config migration_dependencies: required: - - d6_comment_field - d6_node_type + - d6_comment_field diff --git a/core/modules/comment/migration_templates/d6_comment_type.yml b/core/modules/comment/migration_templates/d6_comment_type.yml index d3d85e4ab7..06e317a3b7 100644 --- a/core/modules/comment/migration_templates/d6_comment_type.yml +++ b/core/modules/comment/migration_templates/d6_comment_type.yml @@ -7,6 +7,7 @@ source: constants: entity_type: node id_prefix: 'comment_node_' + label_suffix: 'comment' process: target_entity_type_id: 'constants/entity_type' id: @@ -14,6 +15,11 @@ process: source: - 'constants/id_prefix' - type - label: name + label: + plugin: concat + source: + - name + - 'constants/label_suffix' + delimiter: ' ' destination: plugin: entity:comment_type diff --git a/core/modules/comment/migration_templates/d7_comment.yml b/core/modules/comment/migration_templates/d7_comment.yml index 94a2884477..f716d4cc90 100644 --- a/core/modules/comment/migration_templates/d7_comment.yml +++ b/core/modules/comment/migration_templates/d7_comment.yml @@ -16,8 +16,15 @@ process: source: pid entity_id: nid entity_type: 'constants/entity_type' - comment_type: comment_type - field_name: comment_type + comment_type: + - + plugin: migration_lookup + source: node_type + migration: d7_comment_type + - + plugin: skip_on_empty + method: row + field_name: '@comment_type' subject: subject uid: uid name: name @@ -35,3 +42,5 @@ migration_dependencies: required: - d7_node - d7_comment_type + - d7_comment_entity_display + - d7_comment_entity_form_display diff --git a/core/modules/comment/migration_templates/d7_comment_entity_display.yml b/core/modules/comment/migration_templates/d7_comment_entity_display.yml index 2004505f3c..b206552f76 100644 --- a/core/modules/comment/migration_templates/d7_comment_entity_display.yml +++ b/core/modules/comment/migration_templates/d7_comment_entity_display.yml @@ -3,7 +3,7 @@ label: Comment display configuration migration_tags: - Drupal 7 source: - plugin: d7_comment_type + plugin: d7_node_type constants: entity_type: node view_mode: default @@ -13,10 +13,17 @@ source: weight: 20 process: entity_type: 'constants/entity_type' - field_name: bundle + field_name: + - + plugin: migration_lookup + source: type + migration: d7_comment_type + - + plugin: skip_on_empty + method: row view_mode: 'constants/view_mode' options: 'constants/options' - bundle: node_type + bundle: type destination: plugin: component_entity_display migration_dependencies: diff --git a/core/modules/comment/migration_templates/d7_comment_entity_form_display.yml b/core/modules/comment/migration_templates/d7_comment_entity_form_display.yml index 0315c4a451..48bb7bc570 100644 --- a/core/modules/comment/migration_templates/d7_comment_entity_form_display.yml +++ b/core/modules/comment/migration_templates/d7_comment_entity_form_display.yml @@ -3,20 +3,26 @@ label: Comment field form display configuration migration_tags: - Drupal 7 source: - plugin: d7_comment_type + plugin: d7_node_type constants: entity_type: node - field_name: comment form_mode: default options: type: comment_default weight: 20 process: entity_type: 'constants/entity_type' - field_name: 'constants/field_name' + field_name: + - + plugin: migration_lookup + source: type + migration: d7_comment_type + - + plugin: skip_on_empty + method: row form_mode: 'constants/form_mode' options: 'constants/options' - bundle: node_type + bundle: type destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/comment/migration_templates/d7_comment_entity_form_display_subject.yml b/core/modules/comment/migration_templates/d7_comment_entity_form_display_subject.yml index c27303e876..b131c0ab62 100644 --- a/core/modules/comment/migration_templates/d7_comment_entity_form_display_subject.yml +++ b/core/modules/comment/migration_templates/d7_comment_entity_form_display_subject.yml @@ -3,7 +3,7 @@ label: Comment subject form display configuration migration_tags: - Drupal 7 source: - plugin: d7_comment_type + plugin: d7_node_type constants: entity_type: comment field_name: subject @@ -16,13 +16,23 @@ process: field_name: 'constants/field_name' form_mode: 'constants/form_mode' options: 'constants/options' + bundle: + - + plugin: migration_lookup + source: type + migration: d7_comment_type + - + plugin: skip_on_empty + method: row hidden: plugin: static_map - source: subject + source: comment_subject_field map: + # If comment_subject_field = FALSE, then hidden = TRUE. 0: true + # If comment_subject_field = TRUE, then hidden = FALSE. 1: false - bundle: bundle + default_value: false destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/comment/migration_templates/d7_comment_field.yml b/core/modules/comment/migration_templates/d7_comment_field.yml index b4b3543db1..cd7337c7e5 100644 --- a/core/modules/comment/migration_templates/d7_comment_field.yml +++ b/core/modules/comment/migration_templates/d7_comment_field.yml @@ -3,15 +3,22 @@ label: Comment field configuration migration_tags: - Drupal 7 source: - plugin: d7_comment_type + plugin: d7_node_type constants: entity_type: node type: comment process: entity_type: 'constants/entity_type' - field_name: bundle + field_name: + - + plugin: migration_lookup + source: type + migration: d7_comment_type + - + plugin: skip_on_empty + method: row type: 'constants/type' - 'settings/comment_type': bundle + 'settings/comment_type': '@field_name' destination: plugin: entity:field_storage_config migration_dependencies: diff --git a/core/modules/comment/migration_templates/d7_comment_field_instance.yml b/core/modules/comment/migration_templates/d7_comment_field_instance.yml index 80a1a5198c..89b39b9241 100644 --- a/core/modules/comment/migration_templates/d7_comment_field_instance.yml +++ b/core/modules/comment/migration_templates/d7_comment_field_instance.yml @@ -3,7 +3,7 @@ label: Comment field instance configuration migration_tags: - Drupal 7 source: - plugin: d7_comment_type + plugin: d7_node_type constants: entity_type: node label: Comments @@ -12,16 +12,59 @@ process: entity_type: 'constants/entity_type' label: 'constants/label' required: 'constants/required' - field_name: bundle - bundle: node_type - 'default_value/0/status': 'constants/required' - 'settings/default_mode': default_mode - 'settings/per_page': per_page - 'settings/anonymous': anonymous - 'settings/form_location': form_location - 'settings/preview': preview + field_name: + - + plugin: migration_lookup + source: type + migration: d7_comment_type + - + plugin: skip_on_empty + method: row + bundle: type + 'default_value/0/status': + # We're using static_map instead of default_value otherwise if the source + # is 0, the default value of 1 would be used. + plugin: static_map + source: comment + map: + 0: 0 + 1: 1 + 2: 2 + default_value: 2 + 'settings/default_mode': + # We're using static_map instead of default_value otherwise if the source + # is 0, the default value of 1 would be used. + plugin: static_map + source: comment_default_mode + map: + 0: 0 + 1: 1 + default_value: 1 + 'settings/per_page': + plugin: default_value + source: comment_default_per_page + default_value: 50 + 'settings/anonymous': + plugin: default_value + source: comment_anonymous + default_value: 0 + 'settings/form_location': + plugin: default_value + source: comment_form_location + default_value: 0 + 'settings/preview': + # We're using static_map instead of default_value otherwise if the source + # is 0, the default value of 1 would be used. + plugin: static_map + source: comment_preview + map: + 0: 0 + 1: 1 + 2: 2 + default_value: 1 destination: plugin: entity:field_config migration_dependencies: required: + - d7_node_type - d7_comment_field diff --git a/core/modules/comment/migration_templates/d7_comment_type.yml b/core/modules/comment/migration_templates/d7_comment_type.yml index 090bfdde29..6135ab32f2 100644 --- a/core/modules/comment/migration_templates/d7_comment_type.yml +++ b/core/modules/comment/migration_templates/d7_comment_type.yml @@ -3,15 +3,23 @@ label: Comment type migration_tags: - Drupal 7 source: - plugin: d7_comment_type + plugin: d7_node_type constants: entity_type: node + id_prefix: 'comment_node_' + label_suffix: 'comment' process: target_entity_type_id: 'constants/entity_type' - id: bundle - label: label + id: + plugin: concat + source: + - 'constants/id_prefix' + - type + label: + plugin: concat + source: + - name + - 'constants/label_suffix' + delimiter: ' ' destination: plugin: entity:comment_type -migration_dependencies: - required: - - d7_node_type diff --git a/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php b/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php deleted file mode 100644 index a64fc8e065..0000000000 --- a/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php +++ /dev/null @@ -1,98 +0,0 @@ -select('field_config_instance', 'fci') - ->distinct() - ->fields('fci', ['bundle']) - ->condition('fci.entity_type', 'comment'); - } - - /** - * {@inheritdoc} - */ - protected function initializeIterator() { - $this->nodeTypes = $this->select('node_type', 'nt') - ->fields('nt', ['type', 'name']) - ->execute() - ->fetchAllKeyed(); - - return parent::initializeIterator(); - } - - /** - * {@inheritdoc} - */ - public function prepareRow(Row $row) { - $node_type = substr($row->getSourceProperty('bundle'), 13); - $row->setSourceProperty('node_type', $node_type); - - $row->setSourceProperty('default_mode', $this->variableGet("comment_default_mode_$node_type", 1)); - $row->setSourceProperty('per_page', $this->variableGet("comment_default_per_page_$node_type", 50)); - $row->setSourceProperty('anonymous', $this->variableGet("comment_anonymous_$node_type", FALSE)); - $row->setSourceProperty('form_location', $this->variableGet("comment_form_location_$node_type", CommentItemInterface::FORM_BELOW)); - $row->setSourceProperty('preview', $this->variableGet("comment_preview_$node_type", TRUE)); - $row->setSourceProperty('subject', $this->variableGet("comment_subject_field_$node_type", TRUE)); - - $label = $this->t('@node_type comment', [ - '@node_type' => $this->nodeTypes[$node_type], - ]); - $row->setSourceProperty('label', $label); - - return parent::prepareRow($row); - } - - /** - * {@inheritdoc} - */ - public function fields() { - return [ - 'label' => $this->t('The label of the comment type.'), - 'bundle' => $this->t('Bundle ID of the comment type.'), - 'node_type' => $this->t('The node type to which this comment type is attached.'), - 'default_mode' => $this->t('Default comment mode.'), - 'per_page' => $this->t('Number of comments visible per page.'), - 'anonymous' => $this->t('Whether anonymous comments are allowed.'), - 'form_location' => $this->t('Location of the comment form.'), - 'preview' => $this->t('Whether previews are enabled for the comment type.'), - 'subject' => $this->t('Whether a subject field is enabled for the comment type.'), - ]; - } - - /** - * {@inheritdoc} - */ - public function getIds() { - return [ - 'bundle' => [ - 'type' => 'string', - ], - ]; - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php index 8a46a438f8..9946fcc333 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php @@ -2,12 +2,13 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d6; +use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; /** - * Upgrade comment variables to entity.display.node.*.default.yml. + * Tests the migration of comment entity displays from Drupal 6. * - * @group migrate_drupal_6 + * @group comment */ class MigrateCommentEntityDisplayTest extends MigrateDrupal6TestBase { @@ -24,6 +25,7 @@ protected function setUp() { $this->installConfig(['comment']); $this->migrateContentTypes(); $this->executeMigrations([ + 'd6_node_type', 'd6_comment_type', 'd6_comment_field', 'd6_comment_field_instance', @@ -32,28 +34,37 @@ protected function setUp() { } /** - * Asserts various aspects of the display of a node type comment field. + * Asserts a display entity. * - * @param string $node_type - * The node type ID. + * @param string $id + * The entity ID. + * @param string $component_id + * The ID of the display component. */ - protected function assertComponent($node_type) { - $component = entity_get_display('node', $node_type, 'default') - ->getComponent('comment_node_' . $node_type); - - $this->assertInternalType('array', $component); + protected function assertDisplay($id, $component_id) { + $component = EntityViewDisplay::load($id)->getComponent($component_id); + $this->assertTrue(is_array($component)); $this->assertSame('hidden', $component['label']); $this->assertSame('comment_default', $component['type']); $this->assertSame(20, $component['weight']); } /** - * Tests comment variables migrated into an entity display. + * Tests the migrated display configuration. */ - public function testCommentEntityDisplay() { - $this->assertComponent('page'); - $this->assertComponent('story'); - $this->assertComponent('article'); + public function testMigration() { + $this->assertDisplay('node.article.default', 'comment_node_article'); + $this->assertDisplay('node.company.default', 'comment_node_company'); + $this->assertDisplay('node.employee.default', 'comment_node_employee'); + $this->assertDisplay('node.event.default', 'comment_node_event'); + $this->assertDisplay('node.forum.default', 'comment_node_forum'); + $this->assertDisplay('node.page.default', 'comment_node_page'); + $this->assertDisplay('node.sponsor.default', 'comment_node_sponsor'); + $this->assertDisplay('node.story.default', 'comment_node_story'); + $this->assertDisplay('node.test_event.default', 'comment_node_test_event'); + $this->assertDisplay('node.test_page.default', 'comment_node_test_page'); + $this->assertDisplay('node.test_planet.default', 'comment_node_test_planet'); + $this->assertDisplay('node.test_story.default', 'comment_node_test_story'); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php index 6bc312204e..1c489a9e50 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php @@ -2,12 +2,13 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d6; +use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; /** - * Upgrade comment subject variable to core.entity_form_display.comment.*.default.yml + * Tests the migration of comment form's subject display from Drupal 6. * - * @group migrate_drupal_6 + * @group comment */ class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal6TestBase { @@ -31,13 +32,11 @@ protected function setUp() { /** * Asserts that the comment subject field is visible for a node type. * - * @param string $node_type - * The node type ID. + * @param string $id + * The entity ID. */ - protected function assertSubjectVisible($node_type) { - $component = entity_get_form_display('comment', "comment_node_$node_type", 'default') - ->getComponent('subject'); - + protected function assertSubjectVisible($id) { + $component = EntityFormDisplay::load($id)->getComponent('subject'); $this->assertInternalType('array', $component); $this->assertSame('string_textfield', $component['type']); $this->assertSame(10, $component['weight']); @@ -46,30 +45,28 @@ protected function assertSubjectVisible($node_type) { /** * Asserts that the comment subject field is not visible for a node type. * - * @param string $node_type - * The node type ID. + * @param string $id + * The entity ID. */ - protected function assertSubjectNotVisible($node_type) { - $component = entity_get_form_display('comment', "comment_node_$node_type", 'default') - ->getComponent('subject'); - + protected function assertSubjectNotVisible($id) { + $component = EntityFormDisplay::load($id)->getComponent('subject'); $this->assertNull($component); } /** - * Tests comment subject variable migrated into an entity display. + * Tests the migrated display configuration. */ - public function testCommentEntityFormDisplay() { - $this->assertSubjectVisible('article'); - $this->assertSubjectVisible('company'); - $this->assertSubjectVisible('employee'); - $this->assertSubjectVisible('page'); - $this->assertSubjectVisible('sponsor'); - $this->assertSubjectNotVisible('story'); - $this->assertSubjectVisible('test_event'); - $this->assertSubjectVisible('test_page'); - $this->assertSubjectVisible('test_planet'); - $this->assertSubjectVisible('test_story'); + public function testMigration() { + $this->assertSubjectVisible('comment.comment_node_article.default'); + $this->assertSubjectVisible('comment.comment_node_company.default'); + $this->assertSubjectVisible('comment.comment_node_employee.default'); + $this->assertSubjectVisible('comment.comment_node_page.default'); + $this->assertSubjectVisible('comment.comment_node_sponsor.default'); + $this->assertSubjectNotVisible('comment.comment_node_story.default'); + $this->assertSubjectVisible('comment.comment_node_test_event.default'); + $this->assertSubjectVisible('comment.comment_node_test_page.default'); + $this->assertSubjectVisible('comment.comment_node_test_planet.default'); + $this->assertSubjectVisible('comment.comment_node_test_story.default'); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php index cf7a2ee26e..2bde9f5519 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php @@ -2,12 +2,13 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d6; +use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; /** - * Upgrade comment variables to core.entity_form_display.node.*.default.yml. + * Tests the migration of comment form display from Drupal 6. * - * @group migrate_drupal_6 + * @group comment */ class MigrateCommentEntityFormDisplayTest extends MigrateDrupal6TestBase { @@ -32,27 +33,36 @@ protected function setUp() { } /** - * Asserts various aspects of the form display of a node type comment field. + * Asserts a display entity. * - * @param string $node_type - * The node type ID. + * @param string $id + * The entity ID. + * @param string $component + * The ID of the form component. */ - protected function assertComponent($node_type) { - $component = entity_get_form_display('node', $node_type, 'default') - ->getComponent('comment_node_' . $node_type); - - $this->assertInternalType('array', $component); + protected function assertDisplay($id, $component_id) { + $component = EntityFormDisplay::load($id)->getComponent($component_id); + $this->assertTrue(is_array($component)); $this->assertSame('comment_default', $component['type']); $this->assertSame(20, $component['weight']); } /** - * Tests comment variables migrated into an entity display. + * Tests the migrated display configuration. */ - public function testCommentEntityFormDisplay() { - $this->assertComponent('page'); - $this->assertComponent('article'); - $this->assertComponent('story'); + public function testMigration() { + $this->assertDisplay('node.article.default', 'comment_node_article'); + $this->assertDisplay('node.company.default', 'comment_node_company'); + $this->assertDisplay('node.employee.default', 'comment_node_employee'); + $this->assertDisplay('node.event.default', 'comment_node_event'); + $this->assertDisplay('node.forum.default', 'comment_node_forum'); + $this->assertDisplay('node.page.default', 'comment_node_page'); + $this->assertDisplay('node.sponsor.default', 'comment_node_sponsor'); + $this->assertDisplay('node.story.default', 'comment_node_story'); + $this->assertDisplay('node.test_event.default', 'comment_node_test_event'); + $this->assertDisplay('node.test_page.default', 'comment_node_test_page'); + $this->assertDisplay('node.test_planet.default', 'comment_node_test_planet'); + $this->assertDisplay('node.test_story.default', 'comment_node_test_story'); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php index 2360b87ef3..8f3f975331 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php @@ -2,14 +2,13 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d6; -use Drupal\comment\CommentManagerInterface; use Drupal\field\Entity\FieldConfig; use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; /** - * Upgrade comment variables to field.instance.node.*.comment.yml. + * Tests the migration of comment field instances from Drupal 6. * - * @group migrate_drupal_6 + * @group comment */ class MigrateCommentFieldInstanceTest extends MigrateDrupal6TestBase { @@ -33,49 +32,57 @@ protected function setUp() { } /** - * Asserts various aspects of a comment field for a node type. + * Asserts a comment field instance entity. * - * @param string $node_type - * The node type ID. - * @param mixed $default_mode - * The expected default comment mode. + * @param string $bundle + * The bundle ID. + * @param string $field_name + * The field name. + * @param int $default_value + * The field's default_value setting. + * @param int $default_mode + * The field's default_mode setting. * @param int $per_page - * The expected number of comments per page. - * @param int $anonymous - * Whether anonymous commenting is expected to be enabled. - * @param bool $form_location - * The location of the comment form. - * @param int $preview - * Whether previewing comments is expected to be enabled. + * The field's per_page setting. + * @param bool $anonymous + * The field's anonymous setting. + * @param int $form_location + * The field's form_location setting. + * @param bool $preview + * The field's preview setting. */ - protected function assertCommentField($node_type, $default_mode, $per_page, $anonymous, $form_location, $preview) { - $id = "node.$node_type.comment_node_$node_type"; - $field = FieldConfig::load($id); - - $this->assertInstanceOf(FieldConfig::class, $field); - $this->assertSame($default_mode, $field->getSetting('default_mode')); - $this->assertSame($per_page, $field->getSetting('per_page')); - $this->assertSame($anonymous, $field->getSetting('anonymous')); - $this->assertSame($form_location, $field->getSetting('form_location')); - $this->assertSame($preview, $field->getSetting('preview')); + protected function assertEntity($bundle, $field_name, $default_value, $default_mode, $per_page, $anonymous, $form_location, $preview) { + $entity = FieldConfig::load("node.$bundle.$field_name"); + $this->assertInstanceOf(FieldConfig::class, $entity); + $this->assertSame('node', $entity->getTargetEntityTypeId()); + $this->assertSame('Comments', $entity->label()); + $this->assertTrue($entity->isRequired()); + $this->assertSame($bundle, $entity->getTargetBundle()); + $this->assertSame($field_name, $entity->getFieldStorageDefinition()->getName()); + $this->assertSame($default_value, $entity->get('default_value')[0]['status']); + $this->assertSame($default_mode, $entity->getSetting('default_mode')); + $this->assertSame($per_page, $entity->getSetting('per_page')); + $this->assertSame($anonymous, $entity->getSetting('anonymous')); + $this->assertSame($form_location, $entity->getSetting('form_location')); + $this->assertSame($preview, $entity->getSetting('preview')); } /** * Test the migrated field instance values. */ - public function testCommentFieldInstance() { - $this->assertCommentField('article', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('company', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('employee', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('event', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('forum', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('page', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('sponsor', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('story', CommentManagerInterface::COMMENT_MODE_FLAT, 70, 1, FALSE, 0); - $this->assertCommentField('test_event', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('test_page', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('test_planet', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); - $this->assertCommentField('test_story', CommentManagerInterface::COMMENT_MODE_THREADED, 50, 0, FALSE, 1); + public function testMigration() { + $this->assertEntity('article', 'comment_node_article', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('company', 'comment_node_company', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('employee', 'comment_node_employee', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('event', 'comment_node_event', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('forum', 'comment_node_forum', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('page', 'comment_node_page', 0, 1, 50, 0, FALSE, 1); + $this->assertEntity('sponsor', 'comment_node_sponsor', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('story', 'comment_node_story', 2, 0, 70, 1, FALSE, 0); + $this->assertEntity('test_event', 'comment_node_test_event', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('test_page', 'comment_node_test_page', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('test_planet', 'comment_node_test_planet', 2, 1, 50, 0, FALSE, 1); + $this->assertEntity('test_story', 'comment_node_test_story', 2, 1, 50, 0, FALSE, 1); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php index dc71a63e3b..2098933cc7 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php @@ -6,9 +6,9 @@ use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; /** - * Tests the creation of comment fields for each Drupal 6 node type. + * Tests the migration of comment fields from Drupal 6. * - * @group migrate_drupal_6 + * @group comment */ class MigrateCommentFieldTest extends MigrateDrupal6TestBase { @@ -23,41 +23,42 @@ class MigrateCommentFieldTest extends MigrateDrupal6TestBase { protected function setUp() { parent::setUp(); $this->installConfig(['comment']); - $this->migrateContentTypes(); - $this->executeMigrations(['d6_comment_type', 'd6_comment_field']); + $this->executeMigrations([ + 'd6_comment_type', + 'd6_comment_field', + ]); } /** - * Asserts the existence of a node comment field. + * Asserts a comment field entity. * * @param string $comment_type - * The comment type ID. + * The comment type. */ - protected function assertCommentField($comment_type) { - $field = FieldStorageConfig::load("node.$comment_type"); - - $this->assertInstanceOf(FieldStorageConfig::class, $field); - $this->assertSame('comment', $field->getType()); - $this->assertSame('node', $field->getTargetEntityTypeId()); - $this->assertSame($comment_type, $field->getSetting('comment_type')); + protected function assertEntity($comment_type) { + $entity = FieldStorageConfig::load('node.' . $comment_type); + $this->assertInstanceOf(FieldStorageConfig::class, $entity); + $this->assertSame('node', $entity->getTargetEntityTypeId()); + $this->assertSame('comment', $entity->getType()); + $this->assertSame($comment_type, $entity->getSetting('comment_type')); } /** - * Tests the creation of a comment field for each node type. + * Tests the migrated comment fields. */ - public function testCommentField() { - $this->assertCommentField('comment_node_article'); - $this->assertCommentField('comment_node_company'); - $this->assertCommentField('comment_node_employee'); - $this->assertCommentField('comment_node_event'); - $this->assertCommentField('comment_node_forum'); - $this->assertCommentField('comment_node_page'); - $this->assertCommentField('comment_node_sponsor'); - $this->assertCommentField('comment_node_story'); - $this->assertCommentField('comment_node_test_event'); - $this->assertCommentField('comment_node_test_page'); - $this->assertCommentField('comment_node_test_planet'); - $this->assertCommentField('comment_node_test_story'); + public function testMigration() { + $this->assertEntity('comment_node_article'); + $this->assertEntity('comment_node_company'); + $this->assertEntity('comment_node_employee'); + $this->assertEntity('comment_node_event'); + $this->assertEntity('comment_node_forum'); + $this->assertEntity('comment_node_page'); + $this->assertEntity('comment_node_sponsor'); + $this->assertEntity('comment_node_story'); + $this->assertEntity('comment_node_test_event'); + $this->assertEntity('comment_node_test_page'); + $this->assertEntity('comment_node_test_planet'); + $this->assertEntity('comment_node_test_story'); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php index 88fb33e2f3..daed01202c 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php @@ -2,13 +2,15 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d6; +use Drupal\comment\Entity\Comment; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; +use Drupal\node\NodeInterface; /** - * Upgrade comments. + * Tests the migration of comments from Drupal 6. * - * @group migrate_drupal_6 + * @group comment */ class MigrateCommentTest extends MigrateDrupal6TestBase { @@ -46,32 +48,41 @@ protected function setUp() { } /** - * Tests the Drupal 6 to Drupal 8 comment migration. + * Tests the migrated comments. */ - public function testComments() { - /** @var \Drupal\Core\Entity\EntityStorageInterface $comment_storage */ - $comment_storage = $this->container->get('entity.manager')->getStorage('comment'); - /** @var \Drupal\comment\CommentInterface $comment */ - $comment = $comment_storage->load(1); - $this->assertIdentical('The first comment.', $comment->getSubject()); - $this->assertIdentical('The first comment body.', $comment->comment_body->value); - $this->assertIdentical('filtered_html', $comment->comment_body->format); - $this->assertIdentical(NULL, $comment->pid->target_id); - $this->assertIdentical('1', $comment->getCommentedEntityId()); - $this->assertIdentical('node', $comment->getCommentedEntityTypeId()); - $this->assertIdentical('en', $comment->language()->getId()); - $this->assertIdentical('comment_node_story', $comment->getTypeId()); - $this->assertEquals('203.0.113.1', $comment->getHostname()); - - $comment = $comment_storage->load(2); - $this->assertIdentical('The response to the second comment.', $comment->subject->value); - $this->assertIdentical('3', $comment->pid->target_id); - $this->assertEquals('203.0.113.2', $comment->getHostname()); - - $comment = $comment_storage->load(3); - $this->assertIdentical('The second comment.', $comment->subject->value); - $this->assertIdentical(NULL, $comment->pid->target_id); - $this->assertEquals('203.0.113.3', $comment->getHostname()); + public function testMigration() { + $comment = Comment::load(1); + $this->assertSame('The first comment.', $comment->getSubject()); + $this->assertSame('The first comment body.', $comment->comment_body->value); + $this->assertSame('filtered_html', $comment->comment_body->format); + $this->assertSame(NULL, $comment->pid->target_id); + $this->assertSame('1', $comment->getCommentedEntityId()); + $this->assertSame('node', $comment->getCommentedEntityTypeId()); + $this->assertSame('en', $comment->language()->getId()); + $this->assertSame('comment_node_story', $comment->getTypeId()); + $this->assertSame('203.0.113.1', $comment->getHostname()); + + $node = $comment->getCommentedEntity(); + $this->assertInstanceOf(NodeInterface::class, $node); + $this->assertSame('1', $node->id()); + + $comment = Comment::load(2); + $this->assertSame('The response to the second comment.', $comment->subject->value); + $this->assertSame('3', $comment->pid->target_id); + $this->assertSame('203.0.113.2', $comment->getHostname()); + + $node = $comment->getCommentedEntity(); + $this->assertInstanceOf(NodeInterface::class, $node); + $this->assertSame('1', $node->id()); + + $comment = Comment::load(3); + $this->assertSame('The second comment.', $comment->subject->value); + $this->assertSame(NULL, $comment->pid->target_id); + $this->assertSame('203.0.113.3', $comment->getHostname()); + + $node = $comment->getCommentedEntity(); + $this->assertInstanceOf(NodeInterface::class, $node); + $this->assertSame('1', $node->id()); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php index 339fc5f0d6..6d246faeff 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php @@ -6,9 +6,9 @@ use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; /** - * Upgrade comment type. + * Tests the migration of comment types from Drupal 6. * - * @group migrate_drupal_6 + * @group comment */ class MigrateCommentTypeTest extends MigrateDrupal6TestBase { @@ -22,32 +22,41 @@ class MigrateCommentTypeTest extends MigrateDrupal6TestBase { */ protected function setUp() { parent::setUp(); - $this->installEntitySchema('node'); - $this->installEntitySchema('comment'); - $this->installConfig(['node', 'comment']); + $this->installConfig(['comment']); $this->executeMigration('d6_comment_type'); } /** - * Tests the Drupal 6 to Drupal 8 comment type migration. + * Asserts a comment type entity. + * + * @param string $id + * The entity ID. + * @param string $label + * The entity label. */ - public function testCommentType() { - // There should be a comment type for each node type. - $comment_types = CommentType::loadMultiple([ - 'comment_node_article', - 'comment_node_company', - 'comment_node_employee', - 'comment_node_event', - 'comment_node_forum', - 'comment_node_page', - 'comment_node_sponsor', - 'comment_node_story', - 'comment_node_test_event', - 'comment_node_test_page', - 'comment_node_test_planet', - 'comment_node_test_story', - ]); - $this->assertCount(12, $comment_types); + protected function assertEntity($id, $label) { + $entity = CommentType::load($id); + $this->assertInstanceOf(CommentType::class, $entity); + $this->assertSame($label, $entity->label()); + $this->assertSame('node', $entity->getTargetEntityTypeId()); + } + + /** + * Tests the migrated comment types. + */ + public function testMigration() { + $this->assertEntity('comment_node_article', 'Article comment'); + $this->assertEntity('comment_node_company', 'Company comment'); + $this->assertEntity('comment_node_employee', 'Employee comment'); + $this->assertEntity('comment_node_event', 'Event comment'); + $this->assertEntity('comment_node_forum', 'Forum topic comment'); + $this->assertEntity('comment_node_page', 'Page comment'); + $this->assertEntity('comment_node_sponsor', 'Sponsor comment'); + $this->assertEntity('comment_node_story', 'Story comment'); + $this->assertEntity('comment_node_test_event', 'Migrate test event comment'); + $this->assertEntity('comment_node_test_page', 'Migrate test page comment'); + $this->assertEntity('comment_node_test_planet', 'Migrate test planet comment'); + $this->assertEntity('comment_node_test_story', 'Migrate test story comment'); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php index 871765b834..bc0c998c00 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php @@ -6,12 +6,15 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** - * Tests migration of comment display configuration. + * Tests the migration of comment entity displays from Drupal 7. * * @group comment */ class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase { + /** + * {@inheritdoc} + */ public static $modules = ['node', 'comment', 'text', 'menu_ui']; /** @@ -19,7 +22,7 @@ class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); + $this->installConfig(['comment', 'node']); $this->executeMigrations([ 'd7_node_type', 'd7_comment_type', @@ -40,9 +43,9 @@ protected function setUp() { protected function assertDisplay($id, $component_id) { $component = EntityViewDisplay::load($id)->getComponent($component_id); $this->assertTrue(is_array($component)); - $this->assertIdentical('hidden', $component['label']); - $this->assertIdentical('comment_default', $component['type']); - $this->assertIdentical(20, $component['weight']); + $this->assertSame('hidden', $component['label']); + $this->assertSame('comment_default', $component['type']); + $this->assertSame(20, $component['weight']); } /** diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php index 8ce439a9cf..be25799f96 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php @@ -6,12 +6,15 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** - * Tests migration of comment form's subject display configuration. + * Tests the migration of comment form's subject display from Drupal 7. * * @group comment */ class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase { + /** + * {@inheritdoc} + */ public static $modules = ['node', 'comment', 'text', 'menu_ui']; /** @@ -19,37 +22,48 @@ class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); + $this->installConfig(['comment']); $this->executeMigrations([ - 'd7_node_type', 'd7_comment_type', 'd7_comment_entity_form_display_subject', ]); } + + /** + * Asserts that the comment subject field is visible for a node type. + * + * @param string $id + * The entity ID. + */ + protected function assertSubjectVisible($id) { + $component = EntityFormDisplay::load($id)->getComponent('subject'); + $this->assertInternalType('array', $component); + $this->assertSame('string_textfield', $component['type']); + $this->assertSame(10, $component['weight']); + } + /** - * Asserts a display entity. + * Asserts that the comment subject field is not visible for a node type. * * @param string $id * The entity ID. */ - protected function assertDisplay($id) { + protected function assertSubjectNotVisible($id) { $component = EntityFormDisplay::load($id)->getComponent('subject'); - $this->assertTrue(is_array($component)); - $this->assertIdentical('string_textfield', $component['type']); - $this->assertIdentical(10, $component['weight']); + $this->assertNull($component); } /** * Tests the migrated display configuration. */ public function testMigration() { - $this->assertDisplay('comment.comment_node_page.default'); - $this->assertDisplay('comment.comment_node_article.default'); - $this->assertDisplay('comment.comment_node_book.default'); - $this->assertDisplay('comment.comment_node_blog.default'); - $this->assertDisplay('comment.comment_node_forum.default'); - $this->assertDisplay('comment.comment_node_test_content_type.default'); + $this->assertSubjectVisible('comment.comment_node_page.default'); + $this->assertSubjectVisible('comment.comment_node_article.default'); + $this->assertSubjectVisible('comment.comment_node_book.default'); + $this->assertSubjectVisible('comment.comment_node_blog.default'); + $this->assertSubjectVisible('comment.comment_node_forum.default'); + $this->assertSubjectNotVisible('comment.comment_node_test_content_type.default'); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php index 724db6ea45..66dc27c938 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php @@ -6,12 +6,15 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** - * Tests migration of comment form display configuration. + * Tests the migration of comment form display from Drupal 7. * * @group comment */ class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase { + /** + * {@inheritdoc} + */ public static $modules = ['node', 'comment', 'text', 'menu_ui']; /** @@ -19,7 +22,7 @@ class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); + $this->installConfig(['comment', 'node']); $this->executeMigrations([ 'd7_node_type', 'd7_comment_type', @@ -40,20 +43,20 @@ protected function setUp() { protected function assertDisplay($id, $component_id) { $component = EntityFormDisplay::load($id)->getComponent($component_id); $this->assertTrue(is_array($component)); - $this->assertIdentical('comment_default', $component['type']); - $this->assertIdentical(20, $component['weight']); + $this->assertSame('comment_default', $component['type']); + $this->assertSame(20, $component['weight']); } /** * Tests the migrated display configuration. */ public function testMigration() { - $this->assertDisplay('node.page.default', 'comment'); - $this->assertDisplay('node.article.default', 'comment'); - $this->assertDisplay('node.book.default', 'comment'); - $this->assertDisplay('node.blog.default', 'comment'); - $this->assertDisplay('node.forum.default', 'comment'); - $this->assertDisplay('node.test_content_type.default', 'comment'); + $this->assertDisplay('node.page.default', 'comment_node_page'); + $this->assertDisplay('node.article.default', 'comment_node_article'); + $this->assertDisplay('node.book.default', 'comment_node_book'); + $this->assertDisplay('node.blog.default', 'comment_node_blog'); + $this->assertDisplay('node.forum.default', 'comment_node_forum'); + $this->assertDisplay('node.test_content_type.default', 'comment_node_test_content_type'); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php index cc82c82766..27d2a7e4d5 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php @@ -2,19 +2,19 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d7; -use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; -use Drupal\Core\Field\FieldConfigInterface; use Drupal\field\Entity\FieldConfig; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** - * Tests creation of comment reference fields for each comment type defined - * in Drupal 7. + * Tests the migration of comment field instances from Drupal 7. * * @group comment */ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase { + /** + * {@inheritdoc} + */ public static $modules = ['node', 'comment', 'text', 'menu_ui']; /** @@ -22,7 +22,7 @@ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); + $this->installConfig(['comment', 'node']); $this->executeMigrations([ 'd7_node_type', 'd7_comment_type', @@ -32,14 +32,14 @@ protected function setUp() { } /** - * Asserts a comment field entity. + * Asserts a comment field instance entity. * - * @param string $id - * The entity ID. - * @param string $field_name - * The field name. * @param string $bundle * The bundle ID. + * @param string $field_name + * The field name. + * @param int $default_value + * The field's default_value setting. * @param int $default_mode * The field's default_mode setting. * @param int $per_page @@ -51,36 +51,32 @@ protected function setUp() { * @param bool $preview * The field's preview setting. */ - protected function assertEntity($id, $field_name, $bundle, $default_mode, $per_page, $anonymous, $form_location, $preview) { - $entity = FieldConfig::load($id); - $this->assertTrue($entity instanceof FieldConfigInterface); - /** @var \Drupal\field\FieldConfigInterface $entity */ - $this->assertIdentical('node', $entity->getTargetEntityTypeId()); - $this->assertIdentical('Comments', $entity->label()); + protected function assertEntity($bundle, $field_name, $default_value, $default_mode, $per_page, $anonymous, $form_location, $preview) { + $entity = FieldConfig::load("node.$bundle.$field_name"); + $this->assertInstanceOf(FieldConfig::class, $entity); + $this->assertSame('node', $entity->getTargetEntityTypeId()); + $this->assertSame('Comments', $entity->label()); $this->assertTrue($entity->isRequired()); - $this->assertIdentical($field_name, $entity->getFieldStorageDefinition()->getName()); - $this->assertIdentical($bundle, $entity->getTargetBundle()); - $this->assertTrue($entity->get('default_value')[0]['status']); - $this->assertEqual($default_mode, $entity->getSetting('default_mode')); - $this->assertIdentical($per_page, $entity->getSetting('per_page')); - $this->assertEqual($anonymous, $entity->getSetting('anonymous')); - // This assertion fails because 1 !== TRUE. It's extremely strange that - // the form_location setting is returning a boolean, but this appears to - // be a problem with the entity, not with the migration. - // $this->asserIdentical($form_location, $entity->getSetting('form_location')); - $this->assertEqual($preview, $entity->getSetting('preview')); + $this->assertSame($bundle, $entity->getTargetBundle()); + $this->assertSame($field_name, $entity->getFieldStorageDefinition()->getName()); + $this->assertSame($default_value, $entity->get('default_value')[0]['status']); + $this->assertSame($default_mode, $entity->getSetting('default_mode')); + $this->assertSame($per_page, $entity->getSetting('per_page')); + $this->assertSame($anonymous, $entity->getSetting('anonymous')); + $this->assertSame($form_location, $entity->getSetting('form_location')); + $this->assertSame($preview, $entity->getSetting('preview')); } /** * Tests the migrated fields. */ public function testMigration() { - $this->assertEntity('node.page.comment_node_page', 'comment_node_page', 'page', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); - $this->assertEntity('node.article.comment_node_article', 'comment_node_article', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); - $this->assertEntity('node.blog.comment_node_blog', 'comment_node_blog', 'blog', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); - $this->assertEntity('node.book.comment_node_book', 'comment_node_book', 'book', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); - $this->assertEntity('node.forum.comment_node_forum', 'comment_node_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE); - $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); + $this->assertEntity('page','comment_node_page', 0, 1, 50, 0, TRUE, 1); + $this->assertEntity('article','comment_node_article', 2, 1, 50, 0, TRUE, 1); + $this->assertEntity('blog','comment_node_blog', 2, 1, 50, 0, TRUE, 1); + $this->assertEntity('book','comment_node_book', 2, 1, 50, 0, TRUE, 1); + $this->assertEntity('forum','comment_node_forum', 2, 1, 50, 0, TRUE, 1); + $this->assertEntity('test_content_type','comment_node_test_content_type', 2, 1, 30, 0, TRUE, 1); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php index b995bdb0a5..69b840f8ba 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php @@ -3,27 +3,27 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d7; use Drupal\field\Entity\FieldStorageConfig; -use Drupal\field\FieldStorageConfigInterface; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** - * Tests creation of comment reference fields for each comment type defined - * in Drupal 7. + * Tests the migration of comment fields from Drupal 7. * * @group comment */ class MigrateCommentFieldTest extends MigrateDrupal7TestBase { - public static $modules = ['node', 'comment', 'text', 'menu_ui']; + /** + * {@inheritdoc} + */ + public static $modules = ['node', 'comment', 'text']; /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); + $this->installConfig(['comment']); $this->executeMigrations([ - 'd7_node_type', 'd7_comment_type', 'd7_comment_field', ]); @@ -32,30 +32,27 @@ protected function setUp() { /** * Asserts a comment field entity. * - * @param string $id - * The entity ID. * @param string $comment_type - * The comment type (bundle ID) the field references. + * The comment type. */ - protected function assertEntity($id, $comment_type) { - $entity = FieldStorageConfig::load($id); - $this->assertTrue($entity instanceof FieldStorageConfigInterface); - /** @var \Drupal\field\FieldStorageConfigInterface $entity */ - $this->assertIdentical('node', $entity->getTargetEntityTypeId()); - $this->assertIdentical('comment', $entity->getType()); - $this->assertIdentical($comment_type, $entity->getSetting('comment_type')); + protected function assertEntity($comment_type) { + $entity = FieldStorageConfig::load('node.' . $comment_type); + $this->assertInstanceOf(FieldStorageConfig::class, $entity); + $this->assertSame('node', $entity->getTargetEntityTypeId()); + $this->assertSame('comment', $entity->getType()); + $this->assertSame($comment_type, $entity->getSetting('comment_type')); } /** - * Tests the migrated fields. + * Tests the migrated comment fields. */ public function testMigration() { - $this->assertEntity('node.comment_node_page', 'comment_node_page'); - $this->assertEntity('node.comment_node_article', 'comment_node_article'); - $this->assertEntity('node.comment_node_blog', 'comment_node_blog'); - $this->assertEntity('node.comment_node_book', 'comment_node_book'); - $this->assertEntity('node.comment_node_forum', 'comment_node_forum'); - $this->assertEntity('node.comment_node_test_content_type', 'comment_node_test_content_type'); + $this->assertEntity('comment_node_page'); + $this->assertEntity('comment_node_article'); + $this->assertEntity('comment_node_blog'); + $this->assertEntity('comment_node_book'); + $this->assertEntity('comment_node_forum'); + $this->assertEntity('comment_node_test_content_type'); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php index 42c2a308bb..bc45968b03 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php @@ -2,18 +2,20 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d7; -use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; use Drupal\node\NodeInterface; /** - * Tests migration of comments from Drupal 7. + * Tests the migration of comments from Drupal 7. * * @group comment */ class MigrateCommentTest extends MigrateDrupal7TestBase { + /** + * {@inheritdoc} + */ public static $modules = ['filter', 'node', 'comment', 'text', 'menu_ui']; /** @@ -22,50 +24,44 @@ class MigrateCommentTest extends MigrateDrupal7TestBase { protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); $this->installEntitySchema('node'); $this->installEntitySchema('comment'); + $this->installConfig(['comment', 'node']); + $this->installSchema('comment', ['comment_entity_statistics']); $this->executeMigrations([ - 'd7_filter_format', 'd7_user_role', 'd7_user', - ]); - $this->executeMigration('d7_node_type'); - // We only need the test_content_type node migration to run for real, so - // mock all the others. - $this->prepareMigrations([ - 'd7_node' => [ - [[0], [0]], - ], - ]); - $this->executeMigrations([ + 'd7_node_type', 'd7_node', 'd7_comment_type', + 'd7_comment_field', + 'd7_comment_field_instance', + 'd7_comment_entity_display', + 'd7_comment_entity_form_display', 'd7_comment', ]); } /** - * Tests migration of comments from Drupal 7. + * Tests the migrated comments. */ - public function testCommentMigration() { + public function testMigration() { $comment = Comment::load(1); - $this->assertTrue($comment instanceof CommentInterface); - /** @var \Drupal\comment\CommentInterface $comment */ - $this->assertIdentical('A comment', $comment->getSubject()); - $this->assertIdentical('1421727536', $comment->getCreatedTime()); - $this->assertIdentical('1421727536', $comment->getChangedTime()); + $this->assertInstanceOf(Comment::class, $comment); + $this->assertSame('A comment', $comment->getSubject()); + $this->assertSame('1421727536', $comment->getCreatedTime()); + $this->assertSame('1421727536', $comment->getChangedTime()); $this->assertTrue($comment->getStatus()); - $this->assertIdentical('admin', $comment->getAuthorName()); - $this->assertIdentical('admin@local.host', $comment->getAuthorEmail()); - $this->assertIdentical('This is a comment', $comment->comment_body->value); - $this->assertIdentical('filtered_html', $comment->comment_body->format); - $this->assertEquals('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname()); + $this->assertSame('admin', $comment->getAuthorName()); + $this->assertSame('admin@local.host', $comment->getAuthorEmail()); + $this->assertSame('This is a comment', $comment->comment_body->value); + $this->assertSame('filtered_html', $comment->comment_body->format); + $this->assertSame('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname()); $node = $comment->getCommentedEntity(); - $this->assertTrue($node instanceof NodeInterface); - $this->assertIdentical('1', $node->id()); + $this->assertInstanceOf(NodeInterface::class, $node); + $this->assertSame('1', $node->id()); } } diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php index 60f640d297..99b3053634 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php @@ -2,29 +2,28 @@ namespace Drupal\Tests\comment\Kernel\Migrate\d7; -use Drupal\comment\CommentTypeInterface; use Drupal\comment\Entity\CommentType; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** - * Tests migration of comment types from Drupal 7. + * Tests the migration of comment types from Drupal 7. * * @group comment */ class MigrateCommentTypeTest extends MigrateDrupal7TestBase { - public static $modules = ['node', 'comment', 'text', 'menu_ui']; + /** + * {@inheritdoc} + */ + public static $modules = ['node', 'comment', 'text']; /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); - $this->executeMigrations([ - 'd7_node_type', - 'd7_comment_type', - ]); + $this->installConfig(['comment']); + $this->executeMigration('d7_comment_type'); } /** @@ -37,26 +36,21 @@ protected function setUp() { */ protected function assertEntity($id, $label) { $entity = CommentType::load($id); - $this->assertTrue($entity instanceof CommentTypeInterface); - /** @var \Drupal\comment\CommentTypeInterface $entity */ - $this->assertIdentical($label, $entity->label()); - $this->assertIdentical('node', $entity->getTargetEntityTypeId()); + $this->assertInstanceOf(CommentType::class, $entity); + $this->assertSame($label, $entity->label()); + $this->assertSame('node', $entity->getTargetEntityTypeId()); } /** * Tests the migrated comment types. */ public function testMigration() { - $this->assertEntity('comment_node_page', 'Basic page comment'); $this->assertEntity('comment_node_article', 'Article comment'); $this->assertEntity('comment_node_blog', 'Blog entry comment'); $this->assertEntity('comment_node_book', 'Book page comment'); $this->assertEntity('comment_node_forum', 'Forum topic comment'); + $this->assertEntity('comment_node_page', 'Basic page comment'); $this->assertEntity('comment_node_test_content_type', 'Test content type comment'); - - $migration = $this->getMigration('d7_comment_type'); - // Validate that the source count and processed count match up. - $this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount()); } } diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index 5c9fea9f92..cba249e5f8 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -44016,7 +44016,7 @@ )) ->values(array( 'name' => 'comment_subject_field_test_content_type', - 'value' => 'i:1;', + 'value' => 'i:0;', )) ->values(array( 'name' => 'comment_test_content_type', diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php index 2ff3b87d9b..d7c879c577 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php @@ -44,7 +44,7 @@ protected function getEntityCounts() { 'contact_form' => 5, 'configurable_language' => 5, 'editor' => 2, - 'field_config' => 84, + 'field_config' => 86, 'field_storage_config' => 59, 'file' => 7, 'filter_format' => 7, diff --git a/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php b/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php index a989ccb33c..c5caa12b4b 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php @@ -95,9 +95,7 @@ protected function getCommentFields() { return [ 'comment' => $this->t('Default comment setting'), 'comment_default_mode' => $this->t('Default display mode'), - 'comment_default_order' => $this->t('Default display order'), 'comment_default_per_page' => $this->t('Default comments per page'), - 'comment_controls' => $this->t('Comment controls'), 'comment_anonymous' => $this->t('Anonymous commenting'), 'comment_subject_field' => $this->t('Comment subject field'), 'comment_preview' => $this->t('Preview comment'), diff --git a/core/modules/node/src/Plugin/migrate/source/d7/NodeType.php b/core/modules/node/src/Plugin/migrate/source/d7/NodeType.php index 7f8290f245..44f0b5e060 100644 --- a/core/modules/node/src/Plugin/migrate/source/d7/NodeType.php +++ b/core/modules/node/src/Plugin/migrate/source/d7/NodeType.php @@ -54,6 +54,28 @@ public function fields() { 'orig_type' => $this->t('The original type.'), 'teaser_length' => $this->t('Teaser length'), ]; + if ($this->moduleExists('comment')) { + $fields += $this->getCommentFields(); + } + return $fields; + } + + /** + * Returns the fields containing comment settings for each node type. + * + * @return string[] + * An associative array of field descriptions, keyed by field. + */ + protected function getCommentFields() { + return [ + 'comment' => $this->t('Default comment setting'), + 'comment_default_mode' => $this->t('Default display mode'), + 'comment_default_per_page' => $this->t('Default comments per page'), + 'comment_anonymous' => $this->t('Anonymous commenting'), + 'comment_subject_field' => $this->t('Comment subject field'), + 'comment_preview' => $this->t('Preview comment'), + 'comment_form_location' => $this->t('Location of comment submission form'), + ]; } /** @@ -107,6 +129,13 @@ public function prepareRow(Row $row) { if ($parent = $this->variableGet('menu_parent_' . $type, NULL)) { $row->setSourceProperty('parent', $parent . ':'); } + + if ($this->moduleExists('comment')) { + foreach (array_keys($this->getCommentFields()) as $field) { + $row->setSourceProperty($field, $this->variableGet($field . '_' . $type, NULL)); + } + } + return parent::prepareRow($row); }