X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FKernel%2FMigrate%2Fd7%2FMigrateCommentFieldInstanceTest.php;h=4b928f7a3d41f01124644b56d4adb7856ee396dc;hp=cc82c827667348f82a299e7d01504a8509a99828;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php b/web/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php index cc82c8276..4b928f7a3 100644 --- a/web/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php +++ b/web/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php @@ -2,19 +2,20 @@ 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 + * @group migrate_drupal_7 */ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase { + /** + * {@inheritdoc} + */ public static $modules = ['node', 'comment', 'text', 'menu_ui']; /** @@ -22,7 +23,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 +33,14 @@ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase { } /** - * 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 +52,32 @@ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase { * @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_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); + $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); } }