public function SmartSqlTest::testSaveIdMapping 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::testSaveIdMapping()
Tests the ID mapping method.
Create two ID mappings and update the second to verify that:
- saving new to empty tables work.
- saving new to nonempty tables work.
- updating work.
Overrides MigrateSqlIdMapTest::testSaveIdMapping
File
- tests/
src/ Unit/ Plugin/ migrate/ id_map/ SmartSqlTest.php, line 127
Class
- SmartSqlTest
- Tests the Smart SQL ID map plugin.
Namespace
Drupal\Tests\smart_sql_idmap\Unit\Plugin\migrate\id_mapCode
public function testSaveIdMapping() {
$source = [
'source_id_property' => 'source_value',
];
$row = new Row($source, [
'source_id_property' => [],
]);
$id_map = $this
->getIdMap();
$id_map
->saveIdMapping($row, [
'destination_id_property' => 2,
]);
$expected_result = [
[
'sourceid1' => 'source_value',
'source_ids_hash' => $this
->getIdMap()
->getSourceIdsHash($source),
'destid1' => 2,
] + $this
->idMapDefaults(),
];
$this
->queryResultTest($this
->getIdMapContents(), $expected_result);
$source = [
'source_id_property' => 'source_value_1',
];
$row = new Row($source, [
'source_id_property' => [],
]);
$id_map
->saveIdMapping($row, [
'destination_id_property' => 3,
]);
$expected_result[] = [
'sourceid1' => 'source_value_1',
'source_ids_hash' => $this
->getIdMap()
->getSourceIdsHash($source),
'destid1' => 3,
] + $this
->idMapDefaults();
$this
->queryResultTest($this
->getIdMapContents(), $expected_result);
$id_map
->saveIdMapping($row, [
'destination_id_property' => 4,
]);
$expected_result[1]['destid1'] = 4;
$this
->queryResultTest($this
->getIdMapContents(), $expected_result);
}