You are here

public function MigrateTableTest::testTableMigration in Migrate Plus 8.5

Tests table migration.

1 call to MigrateTableTest::testTableMigration()
MigrateTableTest::testTableUpdate in tests/src/Kernel/MigrateTableTest.php
Tests table update.

File

tests/src/Kernel/MigrateTableTest.php, line 160

Class

MigrateTableTest
Tests migration destination table.

Namespace

Drupal\Tests\migrate_plus\Kernel

Code

public function testTableMigration() : void {
  $definition = [
    'id' => 'migration_table_test',
    'migration_tags' => [
      'Testing',
    ],
    'source' => [
      'plugin' => 'table',
      'table_name' => static::SOURCE_TABLE_NAME,
      'id_fields' => [
        'data' => [
          'type' => 'string',
        ],
      ],
      'ignore_map' => TRUE,
    ],
    'destination' => [
      'plugin' => 'table',
      'table_name' => static::DEST_TABLE_NAME,
      'id_fields' => [
        'data' => [
          'type' => 'string',
        ],
      ],
      'batch_size' => $this->batchSize,
    ],
    'process' => [
      'data' => 'data',
      'data2' => 'data2',
      'data3' => 'data3',
    ],
  ];
  $migration = \Drupal::service('plugin.manager.migration')
    ->createStubMigration($definition);
  $executable = new MigrateExecutable($migration, $this);
  $executable
    ->import();
  $values = $this->connection
    ->select(static::DEST_TABLE_NAME)
    ->fields(static::DEST_TABLE_NAME)
    ->execute()
    ->fetchAllAssoc('data');
  $this
    ->assertEquals('dummy value', $values['dummy value']->data);
  $this
    ->assertEquals('dummy2 value', $values['dummy value']->data2);
  $this
    ->assertEquals('dummy2 value2', $values['dummy value2']->data2);
  $this
    ->assertEquals('dummy3 value3', $values['dummy value3']->data3);
  $this
    ->assertEquals(3, count($values));

  // Now rollback.
  $executable
    ->rollback();
  $values = $this->connection
    ->select(static::DEST_TABLE_NAME)
    ->fields(static::DEST_TABLE_NAME)
    ->execute()
    ->fetchAllAssoc('data');
  $this
    ->assertEquals(0, count($values));
}