MigrateCommentFieldInstanceTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Drupal\Tests\comment\Kernel\Migrate\d7;
  3. use Drupal\field\Entity\FieldConfig;
  4. use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
  5. /**
  6. * Tests the migration of comment field instances from Drupal 7.
  7. *
  8. * @group comment
  9. * @group migrate_drupal_7
  10. */
  11. class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public static $modules = ['node', 'comment', 'text', 'menu_ui'];
  16. /**
  17. * {@inheritdoc}
  18. */
  19. protected function setUp() {
  20. parent::setUp();
  21. $this->migrateContentTypes();
  22. $this->migrateCommentTypes();
  23. $this->executeMigrations([
  24. 'd7_comment_field',
  25. 'd7_comment_field_instance',
  26. ]);
  27. }
  28. /**
  29. * Asserts a comment field instance entity.
  30. *
  31. * @param string $bundle
  32. * The bundle ID.
  33. * @param string $field_name
  34. * The field name.
  35. * @param int $default_value
  36. * The field's default_value setting.
  37. * @param int $default_mode
  38. * The field's default_mode setting.
  39. * @param int $per_page
  40. * The field's per_page setting.
  41. * @param bool $anonymous
  42. * The field's anonymous setting.
  43. * @param int $form_location
  44. * The field's form_location setting.
  45. * @param bool $preview
  46. * The field's preview setting.
  47. */
  48. protected function assertEntity($bundle, $field_name, $default_value, $default_mode, $per_page, $anonymous, $form_location, $preview) {
  49. $entity = FieldConfig::load("node.$bundle.$field_name");
  50. $this->assertInstanceOf(FieldConfig::class, $entity);
  51. $this->assertSame('node', $entity->getTargetEntityTypeId());
  52. $this->assertSame('Comments', $entity->label());
  53. $this->assertTrue($entity->isRequired());
  54. $this->assertSame($bundle, $entity->getTargetBundle());
  55. $this->assertSame($field_name, $entity->getFieldStorageDefinition()->getName());
  56. $this->assertSame($default_value, $entity->get('default_value')[0]['status']);
  57. $this->assertSame($default_mode, $entity->getSetting('default_mode'));
  58. $this->assertSame($per_page, $entity->getSetting('per_page'));
  59. $this->assertSame($anonymous, $entity->getSetting('anonymous'));
  60. $this->assertSame($form_location, $entity->getSetting('form_location'));
  61. $this->assertSame($preview, $entity->getSetting('preview'));
  62. }
  63. /**
  64. * Tests the migrated fields.
  65. */
  66. public function testMigration() {
  67. $this->assertEntity('page', 'comment_node_page', 0, 1, 50, 0, TRUE, 1);
  68. $this->assertEntity('article', 'comment_node_article', 2, 1, 50, 0, TRUE, 1);
  69. $this->assertEntity('blog', 'comment_node_blog', 2, 1, 50, 0, TRUE, 1);
  70. $this->assertEntity('book', 'comment_node_book', 2, 1, 50, 0, TRUE, 1);
  71. $this->assertEntity('forum', 'comment_forum', 2, 1, 50, 0, TRUE, 1);
  72. $this->assertEntity('test_content_type', 'comment_node_test_content_type', 2, 1, 30, 0, TRUE, 1);
  73. $this->assertEntity('et', 'comment_node_et', 2, 1, 50, 0, FALSE, 1);
  74. }
  75. }