MigrateCommentFieldInstanceTest.php 2.88 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\comment\Kernel\Migrate\d7;
4 5

use Drupal\field\Entity\FieldConfig;
6
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
7 8

/**
9
 * Tests the migration of comment field instances from Drupal 7.
10 11
 *
 * @group comment
12
 * @group migrate_drupal_7
13 14 15
 */
class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {

16 17 18
  /**
   * {@inheritdoc}
   */
19
  protected static $modules = ['node', 'comment', 'text', 'menu_ui'];
20 21 22 23

  /**
   * {@inheritdoc}
   */
24
  protected function setUp(): void {
25
    parent::setUp();
26 27
    $this->migrateContentTypes();
    $this->migrateCommentTypes();
28 29 30 31
    $this->executeMigrations([
      'd7_comment_field',
      'd7_comment_field_instance',
    ]);
32 33 34
  }

  /**
35
   * Asserts a comment field instance entity.
36 37 38
   *
   * @param string $bundle
   *   The bundle ID.
39 40 41 42
   * @param string $field_name
   *   The field name.
   * @param int $default_value
   *   The field's default_value setting.
43 44 45 46 47 48 49 50 51 52 53
   * @param int $default_mode
   *   The field's default_mode setting.
   * @param int $per_page
   *   The field's per_page setting.
   * @param bool $anonymous
   *   The field's anonymous setting.
   * @param int $form_location
   *   The field's form_location setting.
   * @param bool $preview
   *   The field's preview setting.
   */
54 55 56 57 58
  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());
59
    $this->assertTrue($entity->isRequired());
60 61 62 63 64 65 66 67
    $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'));
68 69 70 71 72 73
  }

  /**
   * Tests the migrated fields.
   */
  public function testMigration() {
74 75 76 77 78 79
    $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);
80
    $this->assertEntity('et', 'comment_node_et', 2, 1, 50, 0, FALSE, 1);
81 82 83
  }

}