public function SmartSqlTest::testGetRowsNeedingUpdate in Smart SQL ID Map 1.1.x
Same name and namespace in other branches
- 1.0.x tests/src/Unit/Plugin/migrate/id_map/SmartSqlTest.php \Drupal\Tests\smart_sql_idmap\Unit\Plugin\migrate\id_map\SmartSqlTest::testGetRowsNeedingUpdate()
Tests the getRowsNeedingUpdate method for rows that need an update.
Overrides MigrateSqlIdMapTest::testGetRowsNeedingUpdate
File
- tests/
src/ Unit/ Plugin/ migrate/ id_map/ SmartSqlTest.php, line 161
Class
- SmartSqlTest
- Tests the Smart SQL ID map plugin.
Namespace
Drupal\Tests\smart_sql_idmap\Unit\Plugin\migrate\id_mapCode
public function testGetRowsNeedingUpdate() {
$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,
'source_ids_hash' => $this
->getIdMap()
->getSourceIdsHash($source),
'destid1' => 'destination_value_' . $status,
'source_row_status' => $status,
'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
'hash' => '',
];
// Assert zero rows need an update.
if ($status == MigrateIdMapInterface::STATUS_IMPORTED) {
$rows_needing_update = $id_map
->getRowsNeedingUpdate(1);
$this
->assertCount(0, $rows_needing_update);
}
}
// Assert that test values exist.
$this
->queryResultTest($this
->getIdMapContents(), $expected_results);
// Assert a single row needs an update.
$row_needing_update = $id_map
->getRowsNeedingUpdate(1);
$this
->assertCount(1, $row_needing_update);
// Assert the row matches its original source.
$source_id = $expected_results[MigrateIdMapInterface::STATUS_NEEDS_UPDATE]['sourceid1'];
$test_row = $id_map
->getRowBySource([
'source_id_property' => $source_id,
]);
// $row_needing_update is an array of objects returned from the database,
// but $test_row is an array, so the cast is necessary.
$this
->assertSame($test_row, (array) $row_needing_update[0]);
// Add additional row that needs an update.
$source = [
'source_id_property' => 'source_value_multiple',
];
$row = new Row($source, [
'source_id_property' => [],
]);
$destination = [
'destination_id_property' => 'destination_value_multiple',
];
$id_map
->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
// Assert multiple rows need an update.
$rows_needing_update = $id_map
->getRowsNeedingUpdate(2);
$this
->assertCount(2, $rows_needing_update);
}