You are here

public function MigrationGroupTest::testConfigurationMerge in Migrate Plus 8.2

Same name and namespace in other branches
  1. 8.5 tests/src/Kernel/MigrationGroupTest.php \Drupal\Tests\migrate_plus\Kernel\MigrationGroupTest::testConfigurationMerge()
  2. 8.3 tests/src/Kernel/MigrationGroupTest.php \Drupal\Tests\migrate_plus\Kernel\MigrationGroupTest::testConfigurationMerge()
  3. 8.4 tests/src/Kernel/MigrationGroupTest.php \Drupal\Tests\migrate_plus\Kernel\MigrationGroupTest::testConfigurationMerge()

Test that group configuration is properly merged into specific migrations.

File

tests/src/Kernel/MigrationGroupTest.php, line 22

Class

MigrationGroupTest
Test migration groups.

Namespace

Drupal\Tests\migrate_plus\Kernel

Code

public function testConfigurationMerge() {
  $group_id = 'test_group';

  /** @var MigrationGroupInterface $migration_group */
  $group_configuration = [
    'id' => $group_id,
    'shared_configuration' => [
      'migration_tags' => [
        'Drupal 6',
      ],
      // In migration, so will be overridden.
      'source' => [
        'constants' => [
          'type' => 'image',
          // Not in migration, so will be added.
          'cardinality' => '1',
        ],
      ],
      'destination' => [
        'plugin' => 'field_storage_config',
      ],
    ],
  ];
  $this->container
    ->get('entity_type.manager')
    ->getStorage('migration_group')
    ->create($group_configuration)
    ->save();

  /** @var \Drupal\migrate_plus\Entity\MigrationInterface $migration */
  $migration = $this->container
    ->get('entity_type.manager')
    ->getStorage('migration')
    ->create([
    'id' => 'specific_migration',
    'load' => [],
    'migration_group' => $group_id,
    'label' => 'Unaffected by the group',
    'migration_tags' => [
      'Drupal 7',
    ],
    // Overrides group.
    'destination' => [],
    'source' => [],
    'process' => [],
    'migration_dependencies' => [],
  ]);
  $migration
    ->set('source', [
    'plugin' => 'empty',
    // Not in group, persists.
    'constants' => [
      'entity_type' => 'user',
      // Not in group, persists.
      'cardinality' => '3',
    ],
  ]);
  $migration
    ->save();
  $expected_config = [
    'migration_group' => $group_id,
    'label' => 'Unaffected by the group',
    'migration_tags' => [
      'Drupal 7',
    ],
    'source' => [
      'plugin' => 'empty',
      'constants' => [
        'entity_type' => 'user',
        'type' => 'image',
        'cardinality' => '3',
      ],
    ],
    'destination' => [
      'plugin' => 'field_storage_config',
    ],
  ];

  /** @var \Drupal\migrate\Plugin\MigrationInterface $loaded_migration */
  $loaded_migration = $this->container
    ->get('plugin.manager.config_entity_migration')
    ->createInstance('specific_migration');
  foreach ($expected_config as $key => $expected_value) {
    $actual_value = $loaded_migration
      ->get($key);
    $this
      ->assertEquals($expected_value, $actual_value);
  }
}