function MigrateSqlIdMapTest::testLookupDestinationIdMapping

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testLookupDestinationIdMapping()
  2. 8.9.x core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testLookupDestinationIdMapping()
  3. 11.x core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testLookupDestinationIdMapping()

Performs destination ID test on source and destination fields.

@dataProvider lookupDestinationIdMappingDataProvider

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 409

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testLookupDestinationIdMapping($num_source_fields, $num_destination_fields) : void {
    // Adjust the migration configuration according to the number of source and
    // destination fields.
    $this->sourceIds = [];
    $this->destinationIds = [];
    $source_id_values = [];
    $nonexistent_id_values = [];
    $row = $this->idMapDefaults();
    for ($i = 1; $i <= $num_source_fields; $i++) {
        $row["sourceid{$i}"] = "source_id_value_{$i}";
        $source_id_values[] = "source_id_value_{$i}";
        $nonexistent_id_values[] = "nonexistent_source_id_value_{$i}";
        $this->sourceIds["source_id_property_{$i}"] = [];
    }
    $expected_result = [];
    for ($i = 1; $i <= $num_destination_fields; $i++) {
        $row["destid{$i}"] = "destination_id_value_{$i}";
        $expected_result[] = "destination_id_value_{$i}";
        $this->destinationIds["destination_id_property_{$i}"] = [];
    }
    $row['source_ids_hash'] = $this->getIdMap()
        ->getSourceIdsHash($source_id_values);
    $this->saveMap($row);
    $id_map = $this->getIdMap();
    // Test for a valid hit.
    $destination_ids = $id_map->lookupDestinationIds($source_id_values);
    $this->assertSame([
        $expected_result,
    ], $destination_ids);
    // Test for a miss.
    $destination_ids = $id_map->lookupDestinationIds($nonexistent_id_values);
    $this->assertCount(0, $destination_ids);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.