You are here

public function MigrateSqlIdMapTest::testGetHighestId 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::testGetHighestId()
  2. 10 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testGetHighestId()

Tests getHighestId method.

@dataProvider getHighestIdDataProvider

Parameters

array $destination_ids: Array of destination ids.

array $rows: Array of map table rows.

int $expected: Expected highest id value.

File

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

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testGetHighestId(array $destination_ids, array $rows, $expected) {
  $this->database = $this
    ->getDatabase([]);
  $this->sourceIds = $destination_ids;
  $this->destinationIds = $destination_ids;
  $db_keys = [];
  $dest_id_count = count($destination_ids);
  for ($i = 1; $i <= $dest_id_count; $i++) {
    $db_keys[$i] = "sourceid{$i}";
  }
  for ($i = 1; $i <= $dest_id_count; $i++) {
    $db_keys[] = "destid{$i}";
  }
  $id_map = $this
    ->getIdMap();
  foreach ($rows as $row) {
    $values = array_combine($db_keys, $row);
    $source_values = array_slice($row, 0, $dest_id_count);
    $values['source_ids_hash'] = $id_map
      ->getSourceIdsHash($source_values);
    $this
      ->saveMap($values);
  }
  $actual = $id_map
    ->getHighestId();
  $this
    ->assertSame($expected, $actual);
}