Issue #2532534 by phenaproxima, miguelc303: Migration Files for Drupal 7 Comments
parent
3d9ba61e28
commit
5fb22f43a5
|
@ -39,7 +39,7 @@ migration_dependencies:
|
|||
required:
|
||||
- d6_node:*
|
||||
- d6_comment_type
|
||||
- d6_user
|
||||
- d6_comment_entity_display
|
||||
- d6_comment_entity_form_display
|
||||
- d6_user
|
||||
- d6_filter_format
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
id: d7_comment
|
||||
label: Drupal 7 comments
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment
|
||||
constants:
|
||||
entity_type: node
|
||||
process:
|
||||
cid: cid
|
||||
pid:
|
||||
plugin: migration
|
||||
migration: d7_comment
|
||||
source: pid
|
||||
entity_id: nid
|
||||
entity_type: 'constants/entity_type'
|
||||
comment_type: comment_type
|
||||
field_name: comment_type
|
||||
subject: subject
|
||||
uid: uid
|
||||
name: name
|
||||
mail: mail
|
||||
homepage: homepage
|
||||
hostname: hostname
|
||||
created: created
|
||||
changed: changed
|
||||
status: status
|
||||
thread: thread
|
||||
comment_body: comment_body
|
||||
destination:
|
||||
plugin: entity:comment
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_node:*
|
||||
- d7_comment_type
|
|
@ -0,0 +1,24 @@
|
|||
id: d7_comment_entity_display
|
||||
label: Drupal 7 comment display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
constants:
|
||||
entity_type: node
|
||||
view_mode: default
|
||||
options:
|
||||
label: hidden
|
||||
type: comment_default
|
||||
weight: 20
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
field_name: bundle
|
||||
view_mode: 'constants/view_mode'
|
||||
options: 'constants/options'
|
||||
bundle: node_type
|
||||
destination:
|
||||
plugin: component_entity_display
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_comment_field_instance
|
|
@ -0,0 +1,24 @@
|
|||
id: d7_comment_entity_form_display
|
||||
label: Drupal 7 comment field form display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment_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'
|
||||
form_mode: 'constants/form_mode'
|
||||
options: 'constants/options'
|
||||
bundle: node_type
|
||||
destination:
|
||||
plugin: component_entity_form_display
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_comment_field_instance
|
|
@ -0,0 +1,30 @@
|
|||
id: d7_comment_entity_form_display_subject
|
||||
label: Drupal 7 comment subject form display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
constants:
|
||||
entity_type: comment
|
||||
field_name: subject
|
||||
form_mode: default
|
||||
options:
|
||||
type: string_textfield
|
||||
weight: 10
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
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: bundle
|
||||
destination:
|
||||
plugin: component_entity_form_display
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_comment_type
|
|
@ -0,0 +1,19 @@
|
|||
id: d7_comment_field
|
||||
label: Drupal 7 comment field configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
constants:
|
||||
entity_type: node
|
||||
type: comment
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
field_name: bundle
|
||||
type: 'constants/type'
|
||||
'settings/comment_type': bundle
|
||||
destination:
|
||||
plugin: entity:field_storage_config
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_comment_type
|
|
@ -0,0 +1,27 @@
|
|||
id: d7_comment_field_instance
|
||||
label: Drupal 7 comment field instance configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
constants:
|
||||
entity_type: node
|
||||
label: Comments
|
||||
required: true
|
||||
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
|
||||
destination:
|
||||
plugin: entity:field_config
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_comment_field
|
|
@ -0,0 +1,17 @@
|
|||
id: d7_comment_type
|
||||
label: Drupal 7 comment type
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_comment_type
|
||||
constants:
|
||||
entity_type: node
|
||||
process:
|
||||
target_entity_type_id: 'constants/entity_type'
|
||||
id: bundle
|
||||
label: label
|
||||
destination:
|
||||
plugin: entity:comment_type
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_node_type
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Plugin\migrate\source\d7\Comment.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
||||
|
||||
/**
|
||||
* Drupal 7 comment source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_comment",
|
||||
* source_provider = "comment"
|
||||
* )
|
||||
*/
|
||||
class Comment extends FieldableEntity {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('comment', 'c')->fields('c');
|
||||
$query->innerJoin('node', 'n', 'c.nid = n.nid');
|
||||
$query->addField('n', 'type', 'node_type');
|
||||
$query->orderBy('c.created');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$cid = $row->getSourceProperty('cid');
|
||||
|
||||
$node_type = $row->getSourceProperty('node_type');
|
||||
$comment_type = 'comment_node_' . $node_type;
|
||||
$row->setSourceProperty('comment_type', 'comment_node_' . $node_type);
|
||||
|
||||
foreach (array_keys($this->getFields('comment', $comment_type)) as $field) {
|
||||
$row->setSourceProperty($field, $this->getFieldValues('comment', $field, $cid));
|
||||
}
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'cid' => $this->t('Comment ID.'),
|
||||
'pid' => $this->t('Parent comment ID. If set to 0, this comment is not a reply to an existing comment.'),
|
||||
'nid' => $this->t('The {node}.nid to which this comment is a reply.'),
|
||||
'uid' => $this->t('The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.'),
|
||||
'subject' => $this->t('The comment title.'),
|
||||
'comment' => $this->t('The comment body.'),
|
||||
'hostname' => $this->t("The author's host name."),
|
||||
'created' => $this->t('The time that the comment was created, as a Unix timestamp.'),
|
||||
'changed' => $this->t('The time that the comment was edited by its author, as a Unix timestamp.'),
|
||||
'status' => $this->t('The published status of a comment. (0 = Published, 1 = Not Published)'),
|
||||
'format' => $this->t('The {filter_formats}.format of the comment body.'),
|
||||
'thread' => $this->t("The vancode representation of the comment's place in a thread."),
|
||||
'name' => $this->t("The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form."),
|
||||
'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
|
||||
'homepage' => $this->t("The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
|
||||
'type' => $this->t("The {node}.type to which this comment is a reply."),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['cid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Plugin\migrate\source\d7\CommentType.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 7 comment type source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_comment_type",
|
||||
* source_provider = "comment"
|
||||
* )
|
||||
*/
|
||||
class CommentType extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* A map of D7 node types to their labels.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $nodeTypes = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('field_config_instance', 'fci')
|
||||
->fields('fci', array('bundle'))
|
||||
->condition('entity_type', 'comment');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
$this->nodeTypes = $this->select('node_type', 'nt')
|
||||
->fields('nt', array('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 array(
|
||||
'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 array(
|
||||
'bundle' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentEntityDisplayTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of comment display configuration.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
$this->executeMigration('d7_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->assertIdentical('hidden', $component['label']);
|
||||
$this->assertIdentical('comment_default', $component['type']);
|
||||
$this->assertIdentical(20, $component['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migrated display configuration.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$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');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentEntityFormDisplaySubjectTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of comment form's subject display configuration.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_entity_form_display_subject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a display entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
*/
|
||||
protected function assertDisplay($id) {
|
||||
$component = EntityFormDisplay::load($id)->getComponent('subject');
|
||||
$this->assertTrue(is_array($component));
|
||||
$this->assertIdentical('string_textfield', $component['type']);
|
||||
$this->assertIdentical(10, $component['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentEntityFormDisplayTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of comment form display configuration.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
$this->executeMigration('d7_comment_entity_form_display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a display entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $component
|
||||
* 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->assertIdentical('comment_default', $component['type']);
|
||||
$this->assertIdentical(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');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentFieldInstanceTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\Core\Field\FieldConfigInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests creation of comment reference fields for each comment type defined
|
||||
* in Drupal 7.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a comment field entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $field_name
|
||||
* The field name.
|
||||
* @param string $bundle
|
||||
* The bundle ID.
|
||||
* @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($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());
|
||||
$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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentFieldTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests creation of comment reference fields for each comment type defined
|
||||
* in Drupal 7.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a comment field entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $comment_type
|
||||
* The comment type (bundle ID) the field references.
|
||||
*/
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migrated 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');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests migration of comments from Drupal 7.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['filter', 'node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(static::$modules);
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
|
||||
$this->executeMigration('d7_filter_format');
|
||||
$this->executeMigration('d7_user_role');
|
||||
$this->executeMigration('d7_user');
|
||||
// The test database doesn't include uid 1, so we'll need to create it.
|
||||
User::create(array(
|
||||
'uid' => 1,
|
||||
'name' => 'admin',
|
||||
'mail' => 'admin@local.host',
|
||||
))->save();
|
||||
$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(array(
|
||||
'd7_node:*' => array(
|
||||
array(array(0), array(0)),
|
||||
),
|
||||
));
|
||||
$this->executeMigration('d7_node__test_content_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of comments from Drupal 7.
|
||||
*/
|
||||
public function testCommentMigration() {
|
||||
$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->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);
|
||||
|
||||
$node = $comment->getCommentedEntity();
|
||||
$this->assertTrue($node instanceof NodeInterface);
|
||||
$this->assertIdentical('1', $node->id());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentTypeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\comment\CommentTypeInterface;
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of comment types from Drupal 7.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['node', 'comment', 'text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts a comment type entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $label
|
||||
* The entity label.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_test_content_type', 'Test content type comment');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\comment\Unit\Migrate\d7\CommentTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\comment\Unit\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 comment source plugin.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class CommentTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\comment\Plugin\migrate\source\d7\Comment';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'd7_comment',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'cid' => '1',
|
||||
'pid' => '0',
|
||||
'nid' => '1',
|
||||
'uid' => '1',
|
||||
'subject' => 'A comment',
|
||||
'hostname' => '::1',
|
||||
'created' => '1421727536',
|
||||
'changed' => '1421727536',
|
||||
'status' => '1',
|
||||
'thread' => '01/',
|
||||
'name' => 'admin',
|
||||
'mail' => '',
|
||||
'homepage' => '',
|
||||
'language' => 'und',
|
||||
'comment_body' => array(
|
||||
array(
|
||||
'value' => 'This is a comment',
|
||||
'format' => 'filtered_html',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['comment'] = $this->expectedResults;
|
||||
unset($this->databaseContents['comment'][0]['comment_body']);
|
||||
|
||||
$this->databaseContents['node'] = array(
|
||||
array(
|
||||
'nid' => '1',
|
||||
'vid' => '1',
|
||||
'type' => 'test_content_type',
|
||||
'language' => 'en',
|
||||
'title' => 'A Node',
|
||||
'uid' => '1',
|
||||
'status' => '1',
|
||||
'created' => '1421727515',
|
||||
'changed' => '1421727515',
|
||||
'comment' => '2',
|
||||
'promote' => '1',
|
||||
'sticky' => '0',
|
||||
'tnid' => '0',
|
||||
'translate' => '0',
|
||||
),
|
||||
);
|
||||
$this->databaseContents['field_config_instance'] = array(
|
||||
array(
|
||||
'id' => '14',
|
||||
'field_id' => '1',
|
||||
'field_name' => 'comment_body',
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
$this->databaseContents['field_data_comment_body'] = array(
|
||||
array(
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'und',
|
||||
'delta' => '0',
|
||||
'comment_body_value' => 'This is a comment',
|
||||
'comment_body_format' => 'filtered_html',
|
||||
),
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\comment\Unit\Migrate\d7\CommentTypeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\comment\Unit\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 comment type source plugin.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class CommentTypeTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\comment\Plugin\migrate\source\d7\CommentType';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'd7_comment_type',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'bundle' => 'comment_node_article',
|
||||
'node_type' => 'article',
|
||||
'default_mode' => '1',
|
||||
'per_page' => '50',
|
||||
'anonymous' => '0',
|
||||
'form_location' => '1',
|
||||
'preview' => '0',
|
||||
'subject' => '1',
|
||||
'label' => 'Article comment',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['node_type'] = array(
|
||||
array(
|
||||
'type' => 'article',
|
||||
'name' => 'Article',
|
||||
'base' => 'node_content',
|
||||
'module' => 'node',
|
||||
'description' => 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.',
|
||||
'help' => 'Help text for articles',
|
||||
'has_title' => '1',
|
||||
'title_label' => 'Title',
|
||||
'custom' => '1',
|
||||
'modified' => '1',
|
||||
'locked' => '0',
|
||||
'disabled' => '0',
|
||||
'orig_type' => 'article',
|
||||
),
|
||||
);
|
||||
$this->databaseContents['field_config_instance'] = array(
|
||||
array(
|
||||
'id' => '14',
|
||||
'field_id' => '1',
|
||||
'field_name' => 'comment_body',
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_article',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
$this->databaseContents['variable'] = array(
|
||||
array(
|
||||
'name' => 'comment_default_mode_article',
|
||||
'value' => serialize(1),
|
||||
),
|
||||
array(
|
||||
'name' => 'comment_per_page_article',
|
||||
'value' => serialize(50),
|
||||
),
|
||||
array(
|
||||
'name' => 'comment_anonymous_article',
|
||||
'value' => serialize(0),
|
||||
),
|
||||
array(
|
||||
'name' => 'comment_form_location_article',
|
||||
'value' => serialize(1),
|
||||
),
|
||||
array(
|
||||
'name' => 'comment_preview_article',
|
||||
'value' => serialize(0),
|
||||
),
|
||||
array(
|
||||
'name' => 'comment_subject_article',
|
||||
'value' => serialize(1),
|
||||
),
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
|
@ -29,3 +29,6 @@ destination:
|
|||
migration_dependencies:
|
||||
required:
|
||||
- d7_field
|
||||
optional:
|
||||
- d7_node_type
|
||||
- d7_comment_type
|
||||
|
|
Loading…
Reference in New Issue