You are here

protected function MigrateSqlIdMapTest::saveMap in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::saveMap()

Saves a single ID mapping row in the database.

Parameters

array $map: The row to save.

9 calls to MigrateSqlIdMapTest::saveMap()
MigrateSqlIdMapTest::setupRows in core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
Setup a database with the given rows.
MigrateSqlIdMapTest::testErrorCount in core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
Performs error count test with a given number of error rows.
MigrateSqlIdMapTest::testGetHighestId in core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
Tests getHighestId method.
MigrateSqlIdMapTest::testGetRowByDestination in core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
Tests the getRowByDestination method.
MigrateSqlIdMapTest::testGetRowBySource in core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php
Tests the getRowBySource method.

... See full list

File

core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php, line 69

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

protected function saveMap(array $map) {
  $table = 'migrate_map_sql_idmap_test';
  $schema = $this->database
    ->schema();

  // If the table already exists, add any columns which are in the map array,
  // but don't yet exist in the table. Yay, flexibility!
  if ($schema
    ->tableExists($table)) {
    foreach (array_keys($map) as $field) {
      if (!$schema
        ->fieldExists($table, $field)) {
        $schema
          ->addField($table, $field, [
          'type' => 'text',
        ]);
      }
    }
  }
  else {
    $schema
      ->createTable($table, $this
      ->createSchemaFromRow($map));
  }
  $this->database
    ->insert($table)
    ->fields($map)
    ->execute();
}