View source
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\comment\Entity\CommentType;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
class MigrateCommentTypeTest extends MigrateDrupal6TestBase {
protected static $modules = [
'comment',
];
protected function assertEntity($id, $label) {
$entity = CommentType::load($id);
$this
->assertInstanceOf(CommentType::class, $entity);
$this
->assertSame($label, $entity
->label());
$this
->assertSame('node', $entity
->getTargetEntityTypeId());
}
public function testMigration() {
$this
->installConfig([
'comment',
]);
$this
->executeMigration('d6_comment_type');
$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');
$this
->assertEntity('comment_node_a_thirty_two_char', 'Test long name comment');
}
public function testNoCommentTypeMigration(array $disabled_source_modules, array $expected_messages) {
if (!empty($disabled_source_modules)) {
$this->sourceDatabase
->update('system')
->condition('name', $disabled_source_modules, 'IN')
->fields([
'status' => 0,
])
->execute();
}
$this
->startCollectingMessages();
$this
->executeMigration('d6_comment_type');
$expected_messages += [
'status' => [],
'warning' => [],
'error' => [],
];
$actual_messages = $this->migrateMessages + [
'status' => [],
'warning' => [],
'error' => [],
];
foreach ($expected_messages as $type => $expected_messages_by_type) {
$this
->assertSameSize($expected_messages_by_type, $actual_messages[$type]);
$actual_messages_by_type = array_reduce($actual_messages[$type], function (array $carry, $actual_message) {
$carry[] = (string) $actual_message;
return $carry;
}, []);
$missing_expected_messages_by_type = array_diff($expected_messages_by_type, $actual_messages_by_type);
$unexpected_messages_by_type = array_diff($actual_messages_by_type, $expected_messages_by_type);
$this
->assertEmpty($unexpected_messages_by_type, sprintf('No additional messages are present with type "%s". This expectation is wrong, because there are additional messages present: "%s"', $type, implode('", "', $unexpected_messages_by_type)));
$this
->assertEmpty($missing_expected_messages_by_type, sprintf('Every expected messages are present with type "%s". This expectation is wrong, because the following messages aren\'t present: "%s"', $type, implode('", "', $missing_expected_messages_by_type)));
}
$this
->assertEmpty(CommentType::loadMultiple());
}
public function providerTestNoCommentTypeMigration() {
return [
'Node module is disabled in source' => [
'Disabled source modules' => [
'node',
],
'Expected messages' => [
'error' => [
'Migration d6_comment_type did not meet the requirements. The node module is not enabled in the source site. source_module_additional: node.',
],
],
],
'Comment module is disabled in source' => [
'Disabled source modules' => [
'comment',
],
'Expected messages' => [
'error' => [
'Migration d6_comment_type did not meet the requirements. The module comment is not enabled in the source site. source_module: comment.',
],
],
],
'Node and comment modules are disabled in source' => [
'Disabled source modules' => [
'comment',
'node',
],
'Expected messages' => [
'error' => [
'Migration d6_comment_type did not meet the requirements. The module comment is not enabled in the source site. source_module: comment.',
],
],
],
];
}
}