You are here

public function MigrateSqlIdMapTest::testImportedCount in Drupal 8

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

Tests the imported count method.

Scenarios to test for:

  • No imports.
  • One import.
  • Multiple imports.

File

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

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testImportedCount() {
  $id_map = $this
    ->getIdMap();

  // Add a single failed row and assert zero imported rows.
  $source = [
    'source_id_property' => 'source_value_failed',
  ];
  $row = new Row($source, [
    'source_id_property' => [],
  ]);
  $destination = [
    'destination_id_property' => 'destination_value_failed',
  ];
  $id_map
    ->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_FAILED);
  $this
    ->assertSame(0, $id_map
    ->importedCount());

  // Add an imported row and assert single count.
  $source = [
    'source_id_property' => 'source_value_imported',
  ];
  $row = new Row($source, [
    'source_id_property' => [],
  ]);
  $destination = [
    'destination_id_property' => 'destination_value_imported',
  ];
  $id_map
    ->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_IMPORTED);
  $this
    ->assertSame(1, $id_map
    ->importedCount());

  // Add a row needing update and assert multiple imported rows.
  $source = [
    'source_id_property' => 'source_value_update',
  ];
  $row = new Row($source, [
    'source_id_property' => [],
  ]);
  $destination = [
    'destination_id_property' => 'destination_value_update',
  ];
  $id_map
    ->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
  $this
    ->assertSame(2, $id_map
    ->importedCount());
}