You are here

class MigrateExecutableTest in Drupal 10

Same name in this branch
  1. 10 core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest
  2. 10 core/modules/migrate/tests/src/Kernel/MigrateExecutableTest.php \Drupal\Tests\migrate\Kernel\MigrateExecutableTest
Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Kernel/MigrateExecutableTest.php \Drupal\Tests\migrate\Kernel\MigrateExecutableTest
  2. 9 core/modules/migrate/tests/src/Kernel/MigrateExecutableTest.php \Drupal\Tests\migrate\Kernel\MigrateExecutableTest

Tests the MigrateExecutable class.

@group migrate

Hierarchy

Expanded class hierarchy of MigrateExecutableTest

File

core/modules/migrate/tests/src/Kernel/MigrateExecutableTest.php, line 12

Namespace

Drupal\Tests\migrate\Kernel
View source
class MigrateExecutableTest extends MigrateTestBase {
  protected static $modules = [
    'entity_test',
    'user',
  ];
  protected function setUp() : void {
    parent::setUp();
    $this
      ->installEntitySchema('user');
    $this
      ->installEntitySchema('entity_test');
  }

  /**
   * Tests the MigrateExecutable class.
   */
  public function testMigrateExecutable() {
    $data_rows = [
      [
        'key' => '1',
        'field1' => 'f1value1',
        'field2' => 'f2value1',
      ],
      [
        'key' => '2',
        'field1' => 'f1value2',
        'field2' => 'f2value2',
      ],
    ];
    $ids = [
      'key' => [
        'type' => 'integer',
      ],
    ];
    $definition = [
      'migration_tags' => [
        'Embedded data test',
      ],
      'source' => [
        'plugin' => 'embedded_data',
        'data_rows' => $data_rows,
        'ids' => $ids,
      ],
      'process' => [],
      'destination' => [
        'plugin' => 'entity:entity_test',
      ],
    ];
    $migration = \Drupal::service('plugin.manager.migration')
      ->createStubMigration($definition);
    $executable = new TestMigrateExecutable($migration);
    $this
      ->assertEquals(MigrationInterface::RESULT_COMPLETED, $executable
      ->import());

    // Test the exception message when a process plugin throws a
    // MigrateSkipRowException. Change the definition to have one data row and a
    // process that will throw a MigrateSkipRowException on every row.
    $definition['source']['data_rows'] = [
      [
        'key' => '1',
        'field1' => 'f1value1',
      ],
    ];
    $definition['process'] = [
      'foo' => [
        'plugin' => 'skip_row_if_not_set',
        'index' => 'foo',
        'source' => 'field1',
        'message' => 'test message',
      ],
    ];
    $migration = \Drupal::service('plugin.manager.migration')
      ->createStubMigration($definition);
    $executable = new TestMigrateExecutable($migration);
    $executable
      ->import();
    $messages = iterator_to_array($migration
      ->getIdMap()
      ->getMessages());
    $this
      ->assertCount(1, $messages);
    $expected = $migration
      ->getPluginId() . ':foo: test message';
    $this
      ->assertEquals($expected, $messages[0]->message);
  }

}

Members