You are here

public function MigrateSqlIdMapTest::testLookupSourceIDMapping in Zircon Profile 8

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

Performs the source ID test on source and destination fields.

@dataProvider lookupSourceIDMappingDataProvider

Parameters

int $num_source_fields: Number of source fields to test.

int $num_destination_fields: Number of destination fields to test.

File

core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php, line 457
Contains \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest.

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testLookupSourceIDMapping($num_source_fields, $num_destination_fields) {

  // Adjust the migration configuration according to the number of source and
  // destination fields.
  $this->sourceIds = [];
  $this->destinationIds = [];
  $row = $this
    ->idMapDefaults();
  $expected_result = [];
  for ($i = 1; $i <= $num_source_fields; $i++) {
    $row["sourceid{$i}"] = "source_id_value_{$i}";
    $expected_result["source_id_property_{$i}"] = "source_id_value_{$i}";
    $this->sourceIds["source_id_property_{$i}"] = [];
  }
  $destination_id_values = [];
  $nonexistent_id_values = [];
  for ($i = 1; $i <= $num_destination_fields; $i++) {
    $row["destid{$i}"] = "destination_id_value_{$i}";
    $destination_id_values["destination_id_property_{$i}"] = "destination_id_value_{$i}";
    $nonexistent_id_values["destination_id_property_{$i}"] = "nonexistent_destination_id_value_{$i}";
    $this->destinationIds["destination_id_property_{$i}"] = [];
  }
  $this
    ->saveMap($row);
  $id_map = $this
    ->getIdMap();

  // Test for a valid hit.
  $source_id = $id_map
    ->lookupSourceID($destination_id_values);
  $this
    ->assertSame($expected_result, $source_id);

  // Test for a miss.
  $source_id = $id_map
    ->lookupSourceID($nonexistent_id_values);
  $this
    ->assertSame(0, count($source_id));
}