diff --git a/core/modules/comment/migration_templates/d6_comment.yml b/core/modules/comment/migration_templates/d6_comment.yml index 06820d462a..161820eeaa 100644 --- a/core/modules/comment/migration_templates/d6_comment.yml +++ b/core/modules/comment/migration_templates/d6_comment.yml @@ -16,10 +16,15 @@ process: source: pid entity_id: nid entity_type: 'constants/entity_type' - # field_name & comment_type is calculated in - # \Drupal\migrate_drupal\Plugin\migrate\source\d6\Comment::prepareRow() - field_name: field_name - comment_type: comment_type + comment_type: + - + plugin: migration_lookup + source: type + migration: d6_comment_type + - + plugin: skip_on_empty + method: row + field_name: '@comment_type' subject: subject uid: uid name: name diff --git a/core/modules/comment/migration_templates/d6_comment_entity_display.yml b/core/modules/comment/migration_templates/d6_comment_entity_display.yml index c650673188..89e159c47c 100644 --- a/core/modules/comment/migration_templates/d6_comment_entity_display.yml +++ b/core/modules/comment/migration_templates/d6_comment_entity_display.yml @@ -3,10 +3,9 @@ label: Comment display configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable + plugin: d6_node_type constants: entity_type: node - field_name: comment view_mode: default options: label: hidden @@ -14,10 +13,17 @@ source: weight: 20 process: entity_type: 'constants/entity_type' - field_name: 'constants/field_name' + field_name: + - + plugin: migration_lookup + source: type + migration: d6_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/d6_comment_entity_form_display.yml b/core/modules/comment/migration_templates/d6_comment_entity_form_display.yml index c33685feb6..274f3de96d 100644 --- a/core/modules/comment/migration_templates/d6_comment_entity_form_display.yml +++ b/core/modules/comment/migration_templates/d6_comment_entity_form_display.yml @@ -3,20 +3,26 @@ label: Comment field form display configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable + plugin: d6_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: d6_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/d6_comment_entity_form_display_subject.yml b/core/modules/comment/migration_templates/d6_comment_entity_form_display_subject.yml index abe6191b8c..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 @@ -3,7 +3,7 @@ label: Comment subject form display configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable_per_comment_type + plugin: d6_node_type constants: entity_type: comment field_name: subject @@ -16,14 +16,23 @@ process: field_name: 'constants/field_name' form_mode: 'constants/form_mode' options: 'constants/options' + bundle: + - + plugin: migration_lookup + source: type + migration: d6_comment_type + - + plugin: skip_on_empty + method: row hidden: plugin: static_map - source: comment_type - default_value: false + source: comment_subject_field map: - comment_no_subject: true # Hide subject field - comment: false - bundle: comment_type + # 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 d14d1aa4fc..5cbf5d41f4 100644 --- a/core/modules/comment/migration_templates/d6_comment_field.yml +++ b/core/modules/comment/migration_templates/d6_comment_field.yml @@ -3,20 +3,24 @@ label: Comment field configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable_per_comment_type + plugin: d6_node_type constants: entity_type: node type: comment process: entity_type: 'constants/entity_type' - field_name: comment_type + field_name: + - + plugin: migration_lookup + source: type + migration: d6_comment_type + - + plugin: skip_on_empty + method: row type: 'constants/type' - 'settings/comment_type': comment_type + '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 d708619e1e..741ccf2e91 100644 --- a/core/modules/comment/migration_templates/d6_comment_field_instance.yml +++ b/core/modules/comment/migration_templates/d6_comment_field_instance.yml @@ -3,7 +3,7 @@ label: Comment field instance configuration migration_tags: - Drupal 6 source: - plugin: d6_comment_variable + plugin: d6_node_type constants: entity_type: node label: Comments @@ -13,13 +13,24 @@ process: label: 'constants/label' required: 'constants/required' field_name: + - + plugin: migration_lookup + source: type + migration: d6_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_subject_field - default_value: comment + source: comment map: - 0: comment_no_subject - bundle: node_type - 'default_value/0/status': comment + 0: 0 + 1: 1 + 2: 2 + default_value: 2 'settings/default_mode': plugin: static_map source: comment_default_mode @@ -32,13 +43,31 @@ process: 3: 1 # COMMENT_MODE_THREADED_EXPANDED --> COMMENT_MODE_THREADED 4: 1 - 'settings/per_page': comment_default_per_page - 'settings/anonymous': comment_anonymous - 'settings/form_location': comment_form_location - 'settings/preview': comment_preview + 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 + default_value: 1 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 69a2bd8651..b86ae246e7 100644 --- a/core/modules/comment/migration_templates/d6_comment_type.yml +++ b/core/modules/comment/migration_templates/d6_comment_type.yml @@ -3,13 +3,31 @@ label: Comment type migration_tags: - Drupal 6 source: - plugin: d6_comment_variable_per_comment_type + plugin: d6_node_type constants: entity_type: node + id_prefix: 'comment_node_' + label_suffix: 'comment' process: target_entity_type_id: 'constants/entity_type' - id: comment_type - label: label - description: description + id: + - + plugin: concat + source: + - 'constants/id_prefix' + - type + - + plugin: static_map + bypass: true + # The Forum module provides its own comment type (comment_forum), which we + # want to reuse if it exists. + map: + comment_node_forum: comment_forum + 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 5e609a6556..f716d4cc90 100644 --- a/core/modules/comment/migration_templates/d7_comment.yml +++ b/core/modules/comment/migration_templates/d7_comment.yml @@ -19,7 +19,7 @@ process: comment_type: - plugin: migration_lookup - source: comment_type + source: node_type migration: d7_comment_type - plugin: skip_on_empty @@ -42,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 3ae948ecb3..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 @@ -16,14 +16,14 @@ process: field_name: - plugin: migration_lookup - source: bundle + 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 46f231d0f8..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,20 +16,23 @@ process: field_name: 'constants/field_name' form_mode: 'constants/form_mode' options: 'constants/options' - hidden: - plugin: static_map - source: subject - map: - 0: true - 1: false bundle: - plugin: migration_lookup - source: bundle + source: type migration: d7_comment_type - plugin: skip_on_empty method: row + hidden: + plugin: static_map + 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 + 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 95a4602349..cd7337c7e5 100644 --- a/core/modules/comment/migration_templates/d7_comment_field.yml +++ b/core/modules/comment/migration_templates/d7_comment_field.yml @@ -3,7 +3,7 @@ label: Comment field configuration migration_tags: - Drupal 7 source: - plugin: d7_comment_type + plugin: d7_node_type constants: entity_type: node type: comment @@ -12,7 +12,7 @@ process: field_name: - plugin: migration_lookup - source: bundle + source: type migration: d7_comment_type - plugin: skip_on_empty 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 147efcf25c..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 @@ -15,20 +15,56 @@ process: field_name: - plugin: migration_lookup - source: bundle + source: type migration: d7_comment_type - plugin: skip_on_empty method: row - 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 + 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 f94a59d211..d54ca09dbd 100644 --- a/core/modules/comment/migration_templates/d7_comment_type.yml +++ b/core/modules/comment/migration_templates/d7_comment_type.yml @@ -3,22 +3,31 @@ 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: - plugin: static_map - source: bundle - bypass: true - # The Forum module provides its own comment type (comment_forum), which we - # want to reuse if it exists. - map: - comment_node_forum: comment_forum - label: label + - + plugin: concat + source: + - 'constants/id_prefix' + - type + - + plugin: static_map + bypass: true + # The Forum module provides its own comment type (comment_forum), which we + # want to reuse if it exists. + map: + comment_node_forum: comment_forum + 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/d6/Comment.php b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php index 50a14c1065..fb1742b435 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php +++ b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php @@ -34,6 +34,8 @@ public function query() { * {@inheritdoc} */ public function prepareRow(Row $row) { + // This is a backward compatibility layer for the deprecated migrate source + // plugins d6_comment_variable and d6_comment_variable_per_comment_type. if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) { // Comment subject visible. $row->setSourceProperty('field_name', 'comment'); @@ -43,6 +45,7 @@ public function prepareRow(Row $row) { $row->setSourceProperty('field_name', 'comment_no_subject'); $row->setSourceProperty('comment_type', 'comment_no_subject'); } + // In D6, status=0 means published, while in D8 means the opposite. // See https://www.drupal.org/node/237636. $row->setSourceProperty('status', !$row->getSourceProperty('status')); diff --git a/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariable.php b/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariable.php index 398895b541..4417e912b1 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariable.php +++ b/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariable.php @@ -2,6 +2,8 @@ namespace Drupal\comment\Plugin\migrate\source\d6; +@trigger_error('CommentVariable is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.', E_USER_DEPRECATED); + use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; use Drupal\migrate\Plugin\migrate\source\DummyQueryTrait; @@ -10,6 +12,9 @@ * id = "d6_comment_variable", * source_module = "comment" * ) + * + * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use + * \Drupal\node\Plugin\migrate\source\d6\NodeType instead. */ class CommentVariable extends DrupalSqlBase { diff --git a/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariablePerCommentType.php b/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariablePerCommentType.php index 0096ecd185..03e95657e7 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariablePerCommentType.php +++ b/core/modules/comment/src/Plugin/migrate/source/d6/CommentVariablePerCommentType.php @@ -2,11 +2,16 @@ namespace Drupal\comment\Plugin\migrate\source\d6; +@trigger_error('CommentVariablePerCommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.', E_USER_DEPRECATED); + /** * @MigrateSource( * id = "d6_comment_variable_per_comment_type", * source_module = "comment" * ) + * + * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use + * \Drupal\node\Plugin\migrate\source\d6\NodeType instead. */ class CommentVariablePerCommentType extends CommentVariable { diff --git a/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php b/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php index a64fc8e065..f022b4211a 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php +++ b/core/modules/comment/src/Plugin/migrate/source/d7/CommentType.php @@ -2,6 +2,8 @@ namespace Drupal\comment\Plugin\migrate\source\d7; +@trigger_error('CommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d7\NodeType instead.', E_USER_DEPRECATED); + use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; @@ -13,6 +15,9 @@ * id = "d7_comment_type", * source_module = "comment" * ) + * + * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use + * \Drupal\node\Plugin\migrate\source\d7\NodeType instead. */ class CommentType extends DrupalSqlBase { diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php new file mode 100644 index 0000000000..4743ad1139 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php @@ -0,0 +1,70 @@ +installConfig(['comment']); + $this->migrateContentTypes(); + $this->executeMigrations([ + 'd6_node_type', + 'd6_comment_type', + 'd6_comment_field', + 'd6_comment_field_instance', + 'd6_comment_entity_display', + ]); + } + + /** + * Asserts a display entity. + * + * @param string $id + * The entity ID. + * @param string $component_id + * The ID of the display 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 the migrated display configuration. + */ + 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_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 new file mode 100644 index 0000000000..1c489a9e50 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php @@ -0,0 +1,72 @@ +installConfig(['comment']); + $this->executeMigrations([ + 'd6_comment_type', + 'd6_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 that the comment subject field is not visible for a node type. + * + * @param string $id + * The entity ID. + */ + protected function assertSubjectNotVisible($id) { + $component = EntityFormDisplay::load($id)->getComponent('subject'); + $this->assertNull($component); + } + + /** + * Tests the migrated display configuration. + */ + 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 new file mode 100644 index 0000000000..ec53d09762 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php @@ -0,0 +1,68 @@ +installConfig(['comment']); + $this->migrateContentTypes(); + $this->executeMigrations([ + 'd6_comment_type', + 'd6_comment_field', + 'd6_comment_field_instance', + 'd6_comment_entity_form_display', + ]); + } + + /** + * Asserts a display entity. + * + * @param string $id + * The entity ID. + * @param string $component_id + * The ID of the form 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 the migrated display configuration. + */ + 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_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 new file mode 100644 index 0000000000..555bb80817 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php @@ -0,0 +1,88 @@ +installConfig(['comment']); + $this->migrateContentTypes(); + $this->executeMigrations([ + 'd6_comment_type', + 'd6_comment_field', + 'd6_comment_field_instance', + ]); + } + + /** + * Asserts a comment field instance entity. + * + * @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 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 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 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_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 new file mode 100644 index 0000000000..fb50044149 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php @@ -0,0 +1,64 @@ +installConfig(['comment']); + $this->executeMigrations([ + 'd6_comment_type', + 'd6_comment_field', + ]); + } + + /** + * Asserts a comment field entity. + * + * @param string $comment_type + * The 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 comment fields. + */ + 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_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 2a13178f67..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_no_subject', $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 c28be63b97..87e7b5860a 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,20 +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() { - $comment_type = CommentType::load('comment'); - $this->assertIdentical('node', $comment_type->getTargetEntityTypeId()); - $comment_type = CommentType::load('comment_no_subject'); - $this->assertIdentical('node', $comment_type->getTargetEntityTypeId()); + 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_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/d6/MigrateCommentVariableDisplayBase.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableDisplayBase.php deleted file mode 100644 index 964185b589..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableDisplayBase.php +++ /dev/null @@ -1,31 +0,0 @@ -installConfig(['comment']); - $this->migrateContentTypes(); - $this->executeMigrations([ - 'd6_comment_type', - 'd6_comment_field', - 'd6_comment_field_instance', - ]); - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityDisplayTest.php deleted file mode 100644 index baa28bc549..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityDisplayTest.php +++ /dev/null @@ -1,39 +0,0 @@ -executeMigration('d6_comment_entity_display'); - } - - /** - * Tests comment variables migrated into an entity display. - */ - public function testCommentEntityDisplay() { - foreach (['page', 'story', 'article'] as $type) { - $component = EntityViewDisplay::load('node.' . $type . '.default')->getComponent('comment'); - $this->assertIdentical('hidden', $component['label']); - $this->assertIdentical('comment_default', $component['type']); - $this->assertIdentical(20, $component['weight']); - } - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplaySubjectTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplaySubjectTest.php deleted file mode 100644 index 31e61e0a65..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplaySubjectTest.php +++ /dev/null @@ -1,45 +0,0 @@ -installConfig(['comment']); - $this->executeMigrations([ - 'd6_comment_type', - 'd6_comment_entity_form_display_subject', - ]); - } - - /** - * Tests comment subject variable migrated into an entity display. - */ - public function testCommentEntityFormDisplay() { - $component = EntityFormDisplay::load('comment.comment.default') - ->getComponent('subject'); - $this->assertIdentical('string_textfield', $component['type']); - $this->assertIdentical(10, $component['weight']); - $component = EntityFormDisplay::load('comment.comment_no_subject.default') - ->getComponent('subject'); - $this->assertNull($component); - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplayTest.php deleted file mode 100644 index 818f9b87ea..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableEntityFormDisplayTest.php +++ /dev/null @@ -1,39 +0,0 @@ -executeMigration('d6_comment_entity_form_display'); - } - - /** - * Tests comment variables migrated into an entity display. - */ - public function testCommentEntityFormDisplay() { - foreach (['page', 'article', 'story'] as $type) { - $component = EntityFormDisplay::load('node.' . $type . '.default') - ->getComponent('comment'); - $this->assertIdentical('comment_default', $component['type']); - $this->assertIdentical(20, $component['weight']); - } - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableFieldTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableFieldTest.php deleted file mode 100644 index e2a2189559..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableFieldTest.php +++ /dev/null @@ -1,37 +0,0 @@ -installConfig(['comment']); - $this->migrateContentTypes(); - $this->executeMigrations(['d6_comment_type', 'd6_comment_field']); - } - - /** - * Tests comment variables migrated into a field entity. - */ - public function testCommentField() { - $this->assertTrue(is_object(FieldStorageConfig::load('node.comment'))); - } - -} diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableInstanceTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableInstanceTest.php deleted file mode 100644 index 90b256fb14..0000000000 --- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentVariableInstanceTest.php +++ /dev/null @@ -1,60 +0,0 @@ -installConfig(['comment']); - $this->migrateContentTypes(); - $this->executeMigrations([ - 'd6_comment_type', - 'd6_comment_field', - 'd6_comment_field_instance', - ]); - } - - /** - * Test the migrated field instance values. - */ - public function testCommentFieldInstance() { - $node = Node::create(['type' => 'page']); - $this->assertIdentical(0, $node->comment->status); - $this->assertIdentical('comment', $node->comment->getFieldDefinition()->getName()); - $settings = $node->comment->getFieldDefinition()->getSettings(); - $this->assertIdentical(CommentManagerInterface::COMMENT_MODE_THREADED, $settings['default_mode']); - $this->assertIdentical(50, $settings['per_page']); - $this->assertFalse($settings['anonymous']); - $this->assertFalse($settings['form_location']); - $this->assertTrue($settings['preview']); - - $node = Node::create(['type' => 'story']); - $this->assertIdentical(2, $node->comment_no_subject->status); - $this->assertIdentical('comment_no_subject', $node->comment_no_subject->getFieldDefinition()->getName()); - $settings = $node->comment_no_subject->getFieldDefinition()->getSettings(); - $this->assertIdentical(CommentManagerInterface::COMMENT_MODE_FLAT, $settings['default_mode']); - $this->assertIdentical(70, $settings['per_page']); - $this->assertTrue($settings['anonymous']); - $this->assertFalse($settings['form_location']); - $this->assertFalse($settings['preview']); - } - -} 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 8857f57871..cd6ff4bfdc 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 c713a45b72..b243886fde 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,47 @@ 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 a display entity. + * 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 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_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_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 8568913b16..42891024b3 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_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 f7e10d0ec8..895df97386 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_forum', 'comment_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_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 6f94df1abb..1f851cbff4 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_forum', 'comment_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_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 8d2e576dbc..8362e6a2b7 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_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 e1481c2df7..b072aa65c5 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -46146,7 +46146,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 993fdf493d..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 @@ -40,12 +40,12 @@ protected function getEntityCounts() { 'block_content' => 2, 'block_content_type' => 1, 'comment' => 6, - 'comment_type' => 3, + 'comment_type' => 14, 'contact_form' => 5, 'configurable_language' => 5, 'editor' => 2, - 'field_config' => 72, - 'field_storage_config' => 48, + 'field_config' => 86, + 'field_storage_config' => 59, 'file' => 7, 'filter_format' => 7, 'image_style' => 5, @@ -67,9 +67,9 @@ protected function getEntityCounts() { 'menu_link_content' => 4, 'view' => 16, 'date_format' => 11, - 'entity_form_display' => 19, + 'entity_form_display' => 30, 'entity_form_mode' => 1, - 'entity_view_display' => 43, + 'entity_view_display' => 54, 'entity_view_mode' => 14, 'base_field_override' => 38, ]; 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 5ec0aaeca4..c5caa12b4b 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/NodeType.php @@ -63,7 +63,7 @@ public function query() { * {@inheritdoc} */ public function fields() { - return [ + $fields = [ 'type' => $this->t('Machine name of the node type.'), 'name' => $this->t('Human name of the node type.'), 'module' => $this->t('The module providing the node type.'), @@ -79,6 +79,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'), + ]; } /** @@ -112,6 +134,13 @@ public function prepareRow(Row $row) { $row->setSourceProperty('available_menus', [$default_node_menu]); $row->setSourceProperty('parent', $default_node_menu . ':'); } + + if ($this->moduleExists('comment')) { + foreach (array_keys($this->getCommentFields()) as $field) { + $row->setSourceProperty($field, $this->variableGet($field . '_' . $type, NULL)); + } + } + return parent::prepareRow($row); } 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); }