updated core to 8.6.3
This commit is contained in:
@@ -25,6 +25,7 @@ use Drupal\field\FieldConfigInterface;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Anonymous posters cannot enter their contact information.
|
||||
@@ -518,7 +519,7 @@ function comment_node_search_result(EntityInterface $node) {
|
||||
/**
|
||||
* Implements hook_user_cancel().
|
||||
*/
|
||||
function comment_user_cancel($edit, $account, $method) {
|
||||
function comment_user_cancel($edit, UserInterface $account, $method) {
|
||||
switch ($method) {
|
||||
case 'user_cancel_block_unpublish':
|
||||
$comments = entity_load_multiple_by_properties('comment', ['uid' => $account->id()]);
|
||||
|
||||
@@ -16,7 +16,16 @@ process:
|
||||
plugin: migration_lookup
|
||||
migration: d6_comment
|
||||
source: pid
|
||||
entity_id: nid
|
||||
entity_id:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
migration:
|
||||
- d6_node
|
||||
- d6_node_translation
|
||||
source: nid
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
entity_type: 'constants/entity_type'
|
||||
comment_type:
|
||||
-
|
||||
@@ -26,6 +35,7 @@ process:
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
langcode: language
|
||||
field_name: '@comment_type'
|
||||
subject: subject
|
||||
uid: uid
|
||||
@@ -52,3 +62,5 @@ migration_dependencies:
|
||||
- d6_comment_entity_form_display
|
||||
- d6_user
|
||||
- d6_filter_format
|
||||
optional:
|
||||
- d6_node_translation
|
||||
|
||||
@@ -17,7 +17,16 @@ process:
|
||||
plugin: migration_lookup
|
||||
migration: d7_comment
|
||||
source: pid
|
||||
entity_id: nid
|
||||
entity_id:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
migration:
|
||||
- d7_node
|
||||
- d7_node_translation
|
||||
source: nid
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
entity_type: 'constants/entity_type'
|
||||
comment_type:
|
||||
-
|
||||
@@ -27,6 +36,7 @@ process:
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
langcode: language
|
||||
field_name: '@comment_type'
|
||||
subject: subject
|
||||
uid: uid
|
||||
@@ -45,3 +55,5 @@ migration_dependencies:
|
||||
required:
|
||||
- d7_node
|
||||
- d7_comment_type
|
||||
optional:
|
||||
- d7_node_translation
|
||||
|
||||
@@ -50,7 +50,7 @@ class CommentFieldItemList extends FieldItemList {
|
||||
return $return_as_object ? $result : $result->isAllowed();
|
||||
}
|
||||
if ($operation === 'view') {
|
||||
// Only users with either post comments or access comments permisison can
|
||||
// Only users with "post comments" or "access comments" permission can
|
||||
// view the field value. The formatter,
|
||||
// Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter,
|
||||
// takes care of showing the thread and form based on individual
|
||||
|
||||
@@ -56,8 +56,9 @@ interface CommentInterface extends ContentEntityInterface, EntityChangedInterfac
|
||||
/**
|
||||
* Returns the entity to which the comment is attached.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\FieldableEntityInterface
|
||||
* The entity on which the comment is attached.
|
||||
* @return \Drupal\Core\Entity\FieldableEntityInterface|null
|
||||
* The entity on which the comment is attached or NULL if the comment is an
|
||||
* orphan.
|
||||
*/
|
||||
public function getCommentedEntity();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class Comment extends DrupalSqlBase {
|
||||
'mail', 'homepage', 'format',
|
||||
]);
|
||||
$query->innerJoin('node', 'n', 'c.nid = n.nid');
|
||||
$query->fields('n', ['type']);
|
||||
$query->fields('n', ['type', 'language']);
|
||||
$query->orderBy('c.timestamp');
|
||||
return $query;
|
||||
}
|
||||
@@ -61,6 +61,13 @@ class Comment extends DrupalSqlBase {
|
||||
// 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'));
|
||||
|
||||
// If node did not have a language, use site default language as a fallback.
|
||||
if (!$row->getSourceProperty('language')) {
|
||||
$language_default = $this->variableGet('language_default', NULL);
|
||||
$language = $language_default ? $language_default->language : 'en';
|
||||
$row->setSourceProperty('language', $language);
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
@@ -84,6 +91,7 @@ class Comment extends DrupalSqlBase {
|
||||
'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."),
|
||||
'language' => $this->t("The {node}.language to which this comment is a reply. Site default language is used as a fallback if node does not have a language."),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,20 @@ class Comment extends FieldableEntity {
|
||||
$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));
|
||||
// If this entity was translated using Entity Translation, we need to get
|
||||
// its source language to get the field values in the right language.
|
||||
// The translations will be migrated by the d7_comment_entity_translation
|
||||
// migration.
|
||||
$entity_translatable = $this->isEntityTranslatable('comment') && (int) $this->variableGet('language_content_type_' . $node_type, 0) === 4;
|
||||
$source_language = $this->getEntityTranslationSourceLanguage('comment', $cid);
|
||||
$language = $entity_translatable && $source_language ? $source_language : $row->getSourceProperty('language');
|
||||
|
||||
// Get Field API field values.
|
||||
foreach ($this->getFields('comment', $comment_type) as $field_name => $field) {
|
||||
// Ensure we're using the right language if the entity and the field are
|
||||
// translatable.
|
||||
$field_language = $entity_translatable && $field['translatable'] ? $language : NULL;
|
||||
$row->setSourceProperty($field_name, $this->getFieldValues('comment', $field_name, $cid, NULL, $field_language));
|
||||
}
|
||||
|
||||
// If the comment subject was replaced by a real field using the Drupal 7
|
||||
@@ -72,6 +84,7 @@ class Comment extends FieldableEntity {
|
||||
'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."),
|
||||
'language' => $this->t('The comment language.'),
|
||||
'type' => $this->t("The {node}.type to which this comment is a reply."),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\comment\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
||||
|
||||
/**
|
||||
* Provides Drupal 7 comment entity translation source plugin.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_comment_entity_translation",
|
||||
* source_module = "entity_translation"
|
||||
* )
|
||||
*/
|
||||
class CommentEntityTranslation extends FieldableEntity {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('entity_translation', 'et')
|
||||
->fields('et')
|
||||
->fields('c', [
|
||||
'subject',
|
||||
])
|
||||
->condition('et.entity_type', 'comment')
|
||||
->condition('et.source', '', '<>');
|
||||
|
||||
$query->innerJoin('comment', 'c', 'c.cid = et.entity_id');
|
||||
$query->innerJoin('node', 'n', 'n.nid = c.nid');
|
||||
|
||||
$query->addField('n', 'type', 'node_type');
|
||||
|
||||
$query->orderBy('et.created');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$cid = $row->getSourceProperty('entity_id');
|
||||
$language = $row->getSourceProperty('language');
|
||||
$node_type = $row->getSourceProperty('node_type');
|
||||
$comment_type = 'comment_node_' . $node_type;
|
||||
|
||||
// Get Field API field values.
|
||||
foreach ($this->getFields('comment', $comment_type) as $field_name => $field) {
|
||||
// Ensure we're using the right language if the entity is translatable.
|
||||
$field_language = $field['translatable'] ? $language : NULL;
|
||||
$row->setSourceProperty($field_name, $this->getFieldValues('comment', $field_name, $cid, NULL, $field_language));
|
||||
}
|
||||
|
||||
// If the comment subject was replaced by a real field using the Drupal 7
|
||||
// Title module, use the field value instead of the comment subject.
|
||||
if ($this->moduleExists('title')) {
|
||||
$subject_field = $row->getSourceProperty('subject_field');
|
||||
if (isset($subject_field[0]['value'])) {
|
||||
$row->setSourceProperty('subject', $subject_field[0]['value']);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'entity_type' => $this->t('The entity type this translation relates to'),
|
||||
'entity_id' => $this->t('The entity ID this translation relates to'),
|
||||
'revision_id' => $this->t('The entity revision ID this translation relates to'),
|
||||
'language' => $this->t('The target language for this translation.'),
|
||||
'source' => $this->t('The source language from which this translation was created.'),
|
||||
'uid' => $this->t('The author of this translation.'),
|
||||
'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
|
||||
'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'),
|
||||
'created' => $this->t('The Unix timestamp when the translation was created.'),
|
||||
'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'),
|
||||
'subject' => $this->t('The comment title.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return [
|
||||
'entity_id' => [
|
||||
'type' => 'integer',
|
||||
'alias' => 'et',
|
||||
],
|
||||
'language' => [
|
||||
'type' => 'string',
|
||||
'alias' => 'et',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,9 @@ use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field_ui\Tests\FieldUiTestTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@ class CommentHalJsonAnonTest extends CommentHalJsonTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Anononymous users cannot edit their own comments.
|
||||
* Anonymous users cannot edit their own comments.
|
||||
*
|
||||
* @see \Drupal\comment\CommentAccessControlHandler::checkAccess
|
||||
*
|
||||
|
||||
@@ -24,7 +24,7 @@ class CommentJsonAnonTest extends CommentResourceTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Anononymous users cannot edit their own comments.
|
||||
* Anonymous users cannot edit their own comments.
|
||||
*
|
||||
* @see \Drupal\comment\CommentAccessControlHandler::checkAccess
|
||||
*
|
||||
|
||||
@@ -60,7 +60,7 @@ abstract class CommentResourceTestBase extends EntityResourceTestBase {
|
||||
$this->grantPermissionsToTestedRole(['post comments']);
|
||||
break;
|
||||
case 'PATCH':
|
||||
// Anononymous users are not ever allowed to edit their own comments. To
|
||||
// Anonymous users are not ever allowed to edit their own comments. To
|
||||
// be able to test PATCHing comments as the anonymous user, the more
|
||||
// permissive 'administer comments' permission must be granted.
|
||||
// @see \Drupal\comment\CommentAccessControlHandler::checkAccess
|
||||
|
||||
@@ -26,7 +26,7 @@ class CommentXmlAnonTest extends CommentResourceTestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Anononymous users cannot edit their own comments.
|
||||
* Anonymous users cannot edit their own comments.
|
||||
*
|
||||
* @see \Drupal\comment\CommentAccessControlHandler::checkAccess
|
||||
*
|
||||
|
||||
@@ -20,7 +20,12 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment', 'menu_ui'];
|
||||
public static $modules = [
|
||||
'comment',
|
||||
'content_translation',
|
||||
'language',
|
||||
'menu_ui',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -31,6 +36,7 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installSchema('comment', ['comment_entity_statistics']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installConfig(['comment']);
|
||||
|
||||
// The entity.node.canonical route must exist when the RDF hook is called.
|
||||
@@ -38,7 +44,10 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
|
||||
|
||||
$this->migrateContent();
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_content_settings',
|
||||
'd6_node',
|
||||
'd6_node_translation',
|
||||
'd6_comment_type',
|
||||
'd6_comment_field',
|
||||
'd6_comment_field_instance',
|
||||
@@ -84,6 +93,31 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
|
||||
$node = $comment->getCommentedEntity();
|
||||
$this->assertInstanceOf(NodeInterface::class, $node);
|
||||
$this->assertSame('1', $node->id());
|
||||
|
||||
// Tests that the language of the comment is migrated from the node.
|
||||
$comment = Comment::load(7);
|
||||
$this->assertSame('Comment to John Smith - EN', $comment->subject->value);
|
||||
$this->assertSame('This is an English comment.', $comment->comment_body->value);
|
||||
$this->assertSame('21', $comment->getCommentedEntityId());
|
||||
$this->assertSame('node', $comment->getCommentedEntityTypeId());
|
||||
$this->assertSame('en', $comment->language()->getId());
|
||||
|
||||
$node = $comment->getCommentedEntity();
|
||||
$this->assertInstanceOf(NodeInterface::class, $node);
|
||||
$this->assertSame('21', $node->id());
|
||||
|
||||
// Tests that the comment language is correct and that the commented entity
|
||||
// is correctly migrated when the comment was posted to a node translation.
|
||||
$comment = Comment::load(8);
|
||||
$this->assertSame('Comment to John Smith - FR', $comment->subject->value);
|
||||
$this->assertSame('This is a French comment.', $comment->comment_body->value);
|
||||
$this->assertSame('21', $comment->getCommentedEntityId());
|
||||
$this->assertSame('node', $comment->getCommentedEntityTypeId());
|
||||
$this->assertSame('fr', $comment->language()->getId());
|
||||
|
||||
$node = $comment->getCommentedEntity();
|
||||
$this->assertInstanceOf(NodeInterface::class, $node);
|
||||
$this->assertSame('21', $node->id());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,11 +19,15 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
*/
|
||||
public static $modules = [
|
||||
'comment',
|
||||
'content_translation',
|
||||
'datetime',
|
||||
'filter',
|
||||
'image',
|
||||
'language',
|
||||
'link',
|
||||
'menu_ui',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
'node',
|
||||
'taxonomy',
|
||||
'telephone',
|
||||
@@ -38,14 +42,19 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['comment', 'node']);
|
||||
$this->installSchema('comment', ['comment_entity_statistics']);
|
||||
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_node_type',
|
||||
'd7_language_content_settings',
|
||||
'd7_user_role',
|
||||
'd7_user',
|
||||
'd7_node_type',
|
||||
'd7_node',
|
||||
'd7_node_translation',
|
||||
'd7_comment_type',
|
||||
'd7_comment_field',
|
||||
'd7_comment_field_instance',
|
||||
@@ -55,6 +64,8 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
'd7_field',
|
||||
'd7_field_instance',
|
||||
'd7_comment',
|
||||
'd7_entity_translation_settings',
|
||||
'd7_comment_entity_translation',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -64,7 +75,7 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
public function testMigration() {
|
||||
$comment = Comment::load(1);
|
||||
$this->assertInstanceOf(Comment::class, $comment);
|
||||
$this->assertSame('A comment', $comment->getSubject());
|
||||
$this->assertSame('Subject field in English', $comment->getSubject());
|
||||
$this->assertSame('1421727536', $comment->getCreatedTime());
|
||||
$this->assertSame('1421727536', $comment->getChangedTime());
|
||||
$this->assertTrue($comment->getStatus());
|
||||
@@ -73,6 +84,7 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
$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());
|
||||
$this->assertSame('en', $comment->language()->getId());
|
||||
$this->assertSame('1000000', $comment->field_integer->value);
|
||||
|
||||
$node = $comment->getCommentedEntity();
|
||||
@@ -85,6 +97,59 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
||||
$this->assertInstanceOf(Comment::class, $comment);
|
||||
$this->assertSame('TNG for the win!', $comment->getSubject());
|
||||
$this->assertSame('TNG is better than DS9.', $comment->comment_body->value);
|
||||
$this->assertSame('en', $comment->language()->getId());
|
||||
|
||||
// Tests that the commented entity is correctly migrated when the comment
|
||||
// was posted to a node translation.
|
||||
$comment = Comment::load(3);
|
||||
$this->assertInstanceOf(Comment::class, $comment);
|
||||
$this->assertSame('Comment to IS translation', $comment->getSubject());
|
||||
$this->assertSame('This is a comment to an Icelandic translation.', $comment->comment_body->value);
|
||||
$this->assertSame('2', $comment->getCommentedEntityId());
|
||||
$this->assertSame('node', $comment->getCommentedEntityTypeId());
|
||||
$this->assertSame('is', $comment->language()->getId());
|
||||
|
||||
$node = $comment->getCommentedEntity();
|
||||
$this->assertInstanceOf(NodeInterface::class, $node);
|
||||
$this->assertSame('2', $node->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration of comment entity translations.
|
||||
*/
|
||||
public function testCommentEntityTranslations() {
|
||||
$manager = $this->container->get('content_translation.manager');
|
||||
|
||||
// Get the comment and its translations.
|
||||
$comment = Comment::load(1);
|
||||
$comment_fr = $comment->getTranslation('fr');
|
||||
$comment_is = $comment->getTranslation('is');
|
||||
|
||||
// Test that fields translated with Entity Translation are migrated.
|
||||
$this->assertSame('Subject field in English', $comment->getSubject());
|
||||
$this->assertSame('Subject field in French', $comment_fr->getSubject());
|
||||
$this->assertSame('Subject field in Icelandic', $comment_is->getSubject());
|
||||
$this->assertSame('1000000', $comment->field_integer->value);
|
||||
$this->assertSame('2000000', $comment_fr->field_integer->value);
|
||||
$this->assertSame('3000000', $comment_is->field_integer->value);
|
||||
|
||||
// Test that the French translation metadata is correctly migrated.
|
||||
$metadata_fr = $manager->getTranslationMetadata($comment_fr);
|
||||
$this->assertFalse($metadata_fr->isPublished());
|
||||
$this->assertSame('en', $metadata_fr->getSource());
|
||||
$this->assertSame('1', $metadata_fr->getAuthor()->uid->value);
|
||||
$this->assertSame('1531837764', $metadata_fr->getCreatedTime());
|
||||
$this->assertSame('1531837764', $metadata_fr->getChangedTime());
|
||||
$this->assertFalse($metadata_fr->isOutdated());
|
||||
|
||||
// Test that the Icelandic translation metadata is correctly migrated.
|
||||
$metadata_is = $manager->getTranslationMetadata($comment_is);
|
||||
$this->assertTrue($metadata_is->isPublished());
|
||||
$this->assertSame('en', $metadata_is->getSource());
|
||||
$this->assertSame('2', $metadata_is->getAuthor()->uid->value);
|
||||
$this->assertSame('1531838064', $metadata_is->getCreatedTime());
|
||||
$this->assertSame('1531838064', $metadata_is->getChangedTime());
|
||||
$this->assertTrue($metadata_is->isOutdated());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -66,10 +66,12 @@ class CommentSourceWithHighWaterTest extends MigrateSqlSourceTestBase {
|
||||
[
|
||||
'nid' => 2,
|
||||
'type' => 'story',
|
||||
'language' => 'en',
|
||||
],
|
||||
[
|
||||
'nid' => 3,
|
||||
'type' => 'page',
|
||||
'language' => 'fr',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -91,6 +93,7 @@ class CommentSourceWithHighWaterTest extends MigrateSqlSourceTestBase {
|
||||
'homepage' => '',
|
||||
'format' => 'testformat2',
|
||||
'type' => 'page',
|
||||
'language' => 'fr',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -65,10 +65,12 @@ class CommentTest extends MigrateSqlSourceTestBase {
|
||||
[
|
||||
'nid' => 2,
|
||||
'type' => 'story',
|
||||
'language' => 'en',
|
||||
],
|
||||
[
|
||||
'nid' => 3,
|
||||
'type' => 'page',
|
||||
'language' => 'fr',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -90,6 +92,7 @@ class CommentTest extends MigrateSqlSourceTestBase {
|
||||
'homepage' => '',
|
||||
'format' => 'testformat1',
|
||||
'type' => 'story',
|
||||
'language' => 'en',
|
||||
],
|
||||
[
|
||||
'cid' => 2,
|
||||
@@ -107,6 +110,7 @@ class CommentTest extends MigrateSqlSourceTestBase {
|
||||
'homepage' => '',
|
||||
'format' => 'testformat2',
|
||||
'type' => 'page',
|
||||
'language' => 'fr',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests D7 comment entity translation source plugin.
|
||||
*
|
||||
* @covers \Drupal\comment\Plugin\migrate\source\d7\CommentEntityTranslation
|
||||
* @group comment
|
||||
*/
|
||||
class CommentEntityTranslationTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment', 'migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['comment'] = [
|
||||
[
|
||||
'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' => 'en',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['entity_translation'] = [
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'entity_id' => 1,
|
||||
'revision_id' => 1,
|
||||
'language' => 'en',
|
||||
'source' => '',
|
||||
'uid' => 1,
|
||||
'status' => 1,
|
||||
'translate' => 0,
|
||||
'created' => '1421727536',
|
||||
'changed' => '1421727536',
|
||||
],
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'entity_id' => 1,
|
||||
'revision_id' => 1,
|
||||
'language' => 'fr',
|
||||
'source' => 'en',
|
||||
'uid' => 1,
|
||||
'status' => 0,
|
||||
'translate' => 0,
|
||||
'created' => 1531343508,
|
||||
'changed' => 1531343508,
|
||||
],
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'entity_id' => 1,
|
||||
'revision_id' => 1,
|
||||
'language' => 'es',
|
||||
'source' => 'en',
|
||||
'uid' => 2,
|
||||
'status' => 1,
|
||||
'translate' => 1,
|
||||
'created' => 1531343528,
|
||||
'changed' => 1531343528,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_config'] = [
|
||||
[
|
||||
'id' => 1,
|
||||
'field_name' => 'field_test',
|
||||
'type' => 'text',
|
||||
'module' => 'text',
|
||||
'active' => 1,
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => 1,
|
||||
'locked' => 1,
|
||||
'data' => 'a:0:{}',
|
||||
'cardinality' => 1,
|
||||
'translatable' => 1,
|
||||
'deleted' => 0,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'field_name' => 'subject_field',
|
||||
'type' => 'text',
|
||||
'module' => 'text',
|
||||
'active' => 1,
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => 1,
|
||||
'locked' => 1,
|
||||
'data' => 'a:0:{}',
|
||||
'cardinality' => 1,
|
||||
'translatable' => 1,
|
||||
'deleted' => 0,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_config_instance'] = [
|
||||
[
|
||||
'id' => '1',
|
||||
'field_id' => '1',
|
||||
'field_name' => 'field_test',
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => '0',
|
||||
],
|
||||
[
|
||||
'id' => '2',
|
||||
'field_id' => '2',
|
||||
'field_name' => 'subject_field',
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => '0',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_data_field_test'] = [
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'en',
|
||||
'delta' => '0',
|
||||
'field_test_value' => 'This is an English comment',
|
||||
'field_test_format' => NULL,
|
||||
],
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'fr',
|
||||
'delta' => '0',
|
||||
'field_test_value' => 'This is a French comment',
|
||||
'field_test_format' => NULL,
|
||||
],
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'es',
|
||||
'delta' => '0',
|
||||
'field_test_value' => 'This is a Spanish comment',
|
||||
'field_test_format' => NULL,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_data_subject_field'] = [
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'en',
|
||||
'delta' => '0',
|
||||
'subject_field_value' => 'Comment subject in English',
|
||||
'subject_field_format' => NULL,
|
||||
],
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'fr',
|
||||
'delta' => '0',
|
||||
'subject_field_value' => 'Comment subject in French',
|
||||
'subject_field_format' => NULL,
|
||||
],
|
||||
[
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'es',
|
||||
'delta' => '0',
|
||||
'subject_field_value' => 'Comment subject in Spanish',
|
||||
'subject_field_format' => NULL,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['node'] = [
|
||||
[
|
||||
'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',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'subject' => 'A comment',
|
||||
'entity_type' => 'comment',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'fr',
|
||||
'source' => 'en',
|
||||
'uid' => '1',
|
||||
'status' => '0',
|
||||
'translate' => '0',
|
||||
'created' => '1531343508',
|
||||
'changed' => '1531343508',
|
||||
'field_test' => [
|
||||
[
|
||||
'value' => 'This is a French comment',
|
||||
'format' => NULL,
|
||||
],
|
||||
],
|
||||
'subject_field' => [
|
||||
[
|
||||
'value' => 'Comment subject in French',
|
||||
'format' => NULL,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'subject' => 'A comment',
|
||||
'entity_type' => 'comment',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'es',
|
||||
'source' => 'en',
|
||||
'uid' => '2',
|
||||
'status' => '1',
|
||||
'translate' => '1',
|
||||
'created' => '1531343528',
|
||||
'changed' => '1531343528',
|
||||
'field_test' => [
|
||||
[
|
||||
'value' => 'This is a Spanish comment',
|
||||
'format' => NULL,
|
||||
],
|
||||
],
|
||||
'subject_field' => [
|
||||
[
|
||||
'value' => 'Comment subject in Spanish',
|
||||
'format' => NULL,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user