You are here

public function MigrationGroupTest::testConfigurationMerge in Migrate Plus 8

Test that group configuration is properly merged into specific migrations.

File

src/Tests/MigrationGroupTest.php, line 33
Contains \Drupal\migrate_plus\Tests\MigrationGroupTest.

Class

MigrationGroupTest
Test migration groups.

Namespace

Drupal\migrate_plus\Tests

Code

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

  /** @var MigrationGroupInterface $migration_group */
  $migration_group = entity_create('migration_group', array());
  $migration_group
    ->set('id', $group_id);
  $migration_group
    ->set('shared_configuration', array(
    'migration_tags' => array(
      'Drupal 6',
    ),
    // In migration, so will be overridden.
    'source' => array(
      'constants' => array(
        'type' => 'image',
        // Not in migration, so will be added.
        'cardinality' => '1',
      ),
    ),
    'destination' => array(
      'plugin' => 'field_storage_config',
    ),
  ));
  $migration_group
    ->save();

  /** @var MigrationInterface $migration */
  $migration = entity_create('migration', array(
    'id' => 'specific_migration',
    'load' => [],
    'third_party_settings' => [
      'migrate_plus' => [
        'migration_group' => $group_id,
      ],
    ],
    'label' => 'Unaffected by the group',
    'migration_tags' => array(
      'Drupal 7',
    ),
    // Overrides group.
    'destination' => array(),
    'source' => array(),
  ));
  $migration
    ->set('source', array(
    'plugin' => 'empty',
    // Not in group, persists.
    'constants' => array(
      'entity_type' => 'user',
      // Not in group, persists.
      'cardinality' => '3',
    ),
  ));
  $migration
    ->save();
  $expected_config = array(
    'third_party_settings' => [
      'migrate_plus' => [
        'migration_group' => $group_id,
      ],
    ],
    'label' => 'Unaffected by the group',
    'migration_tags' => array(
      'Drupal 7',
    ),
    'source' => array(
      'plugin' => 'empty',
      'constants' => array(
        'entity_type' => 'user',
        'type' => 'image',
        'cardinality' => '3',
      ),
    ),
    'destination' => array(
      'plugin' => 'field_storage_config',
    ),
  );

  /** @var MigrationInterface $loaded_migration */
  $loaded_migration = entity_load('migration', 'specific_migration', TRUE);
  foreach ($expected_config as $key => $expected_value) {
    $actual_value = $loaded_migration
      ->get($key);
    $this
      ->assertEqual($expected_value, $actual_value);
  }
}