View source
<?php
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;
class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
public static $modules = [
'node',
'comment',
'text',
];
protected function setUp() {
parent::setUp();
$this
->installConfig(static::$modules);
$this
->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
]);
}
protected function assertEntity($id, $field_name, $bundle, $default_mode, $per_page, $anonymous, $form_location, $preview) {
$entity = FieldConfig::load($id);
$this
->assertTrue($entity instanceof FieldConfigInterface);
$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
->assertEqual($preview, $entity
->getSetting('preview'));
}
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);
}
}