function MigrateSqlIdMapTest::testPrepareUpdate

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

Tests prepareUpdate().

File

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

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testPrepareUpdate() : void {
    $id_map = $this->getIdMap();
    $row_statuses = [
        MigrateIdMapInterface::STATUS_IMPORTED,
        MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
        MigrateIdMapInterface::STATUS_IGNORED,
        MigrateIdMapInterface::STATUS_FAILED,
    ];
    // Create a mapping row for each STATUS constant.
    foreach ($row_statuses as $status) {
        $source = [
            'source_id_property' => 'source_value_' . $status,
        ];
        $row = new Row($source, [
            'source_id_property' => [],
        ]);
        $destination = [
            'destination_id_property' => 'destination_value_' . $status,
        ];
        $id_map->saveIdMapping($row, $destination, $status);
        $expected_results[] = [
            'sourceid1' => 'source_value_' . $status,
            'destid1' => 'destination_value_' . $status,
            'source_row_status' => $status,
            'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
            'hash' => '',
        ];
    }
    // Assert that test values exist.
    $this->queryResultTest($this->getIdMapContents(), $expected_results);
    // Mark all rows as STATUS_NEEDS_UPDATE.
    $id_map->prepareUpdate();
    // Update expected results.
    foreach ($expected_results as $key => $value) {
        $expected_results[$key]['source_row_status'] = MigrateIdMapInterface::STATUS_NEEDS_UPDATE;
    }
    // Assert that updated expected values match.
    $this->queryResultTest($this->getIdMapContents(), $expected_results);
}

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