function MigrateSqlIdMapTest::testImportedCount

Same name in other branches
  1. 8.9.x core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testImportedCount()
  2. 10 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testImportedCount()
  3. 11.x 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 693

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());
}

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