You are here

public function MigrateLookupTest::testMultipleSourceIds in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Kernel/MigrateLookupTest.php \Drupal\Tests\migrate\Kernel\MigrateLookupTest::testMultipleSourceIds()

Tests lookups with multiple source ids.

File

core/modules/migrate/tests/src/Kernel/MigrateLookupTest.php, line 83

Class

MigrateLookupTest
Tests the Migrate Lookup service.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testMultipleSourceIds() {
  $this
    ->executeMigration('sample_lookup_migration_multiple_source_ids');

  // Test with full set of numerically indexed source ids.
  $result = $this->migrateLookup
    ->lookup('sample_lookup_migration_multiple_source_ids', [
    25,
    26,
  ]);
  $this
    ->assertCount(1, $result);
  $this
    ->assertSame('3', $result[0]['nid']);

  // Test with full set of associatively indexed source ids.
  $result = $this->migrateLookup
    ->lookup('sample_lookup_migration_multiple_source_ids', [
    'id' => 17,
    'version_id' => 17,
  ]);
  $this
    ->assertCount(1, $result);
  $this
    ->assertSame('1', $result[0]['nid']);

  // Test with full set of associatively indexed source ids in the wrong
  // order.
  $result = $this->migrateLookup
    ->lookup('sample_lookup_migration_multiple_source_ids', [
    'version_id' => 26,
    'id' => 25,
  ]);
  $this
    ->assertCount(1, $result);
  $this
    ->assertSame('3', $result[0]['nid']);

  // Test with a partial set of numerically indexed ids.
  $result = $this->migrateLookup
    ->lookup('sample_lookup_migration_multiple_source_ids', [
    25,
  ]);
  $this
    ->assertCount(2, $result);
  $this
    ->assertSame('2', $result[0]['nid']);
  $this
    ->assertSame('3', $result[1]['nid']);

  // Test with a partial set of associatively indexed ids.
  $result = $this->migrateLookup
    ->lookup('sample_lookup_migration_multiple_source_ids', [
    'version_id' => 25,
  ]);
  $this
    ->assertCount(1, $result);
  $this
    ->assertSame('2', $result[0]['nid']);
}