diff -u b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php --- b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php @@ -496,57 +496,24 @@ * Tests the getRowByDestination method. */ public function testGetRowByDestination() { - $this->getDatabase([]); - $this->sourceIds = [ - 'source_id_property1' => [ - 'type' => 'string', - ], - 'source_id_property2' => [ - 'type' => 'string', - ], - ]; $row = [ 'sourceid1' => 'source_id_value_1', 'sourceid2' => 'source_id_value_2', - 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash( - [ - 'source_id_property1' => 'source_id_value_1', - 'source_id_property2' => 'source_id_value_2' - ]), + 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_1']), 'destid1' => 'destination_id_value_1', ] + $this->idMapDefaults(); $this->saveMap($row); $row = [ 'sourceid1' => 'source_id_value_3', 'sourceid2' => 'source_id_value_4', - 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash( - [ - 'source_id_property1' => 'source_id_value_3', - 'source_id_property2' => 'source_id_value_4' - ]), + 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_3']), 'destid1' => 'destination_id_value_2', - ] + $this->idMapDefaults(); - $this->saveMap($row); - $expected = [ - 'source_id_property1' . Sql::ID_SUFFIX => 'source_id_value_3', - 'source_id_property2' . Sql::ID_SUFFIX => 'source_id_value_4', - 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash( - [ - 'source_id_property1' => 'source_id_value_3', - 'source_id_property2' => 'source_id_value_4' - ]), - 'destination_id_property' . Sql::ID_SUFFIX => 'destination_id_value_2', ] + $this->idMapDefaults(); + $this->saveMap($row); $dest_id_values = ['destination_id_property' => $row['destid1']]; $id_map = $this->getIdMap(); $result_row = $id_map->getRowByDestination($dest_id_values); - // Sort expected_results to the same order as $result_row. - foreach ($result_row as $key => $value) { - if (isset($expected[$key]) || array_key_exists($key, $expected)) { - $expected_results[$key] = $expected[$key]; - } - } - $this->assertSame($expected_results, $result_row); + $this->assertSame($row, $result_row); // This value does not exist. $dest_id_values = ['destination_id_property' => 'invalid_destination_id_property']; $id_map = $this->getIdMap(); @@ -646,24 +613,57 @@ * Tests the getRowByDestination method. */ public function testGetRowByDestination() { + $this->getDatabase([]); + $this->sourceIds = [ + 'source_id_property1' => [ + 'type' => 'string', + ], + 'source_id_property2' => [ + 'type' => 'string', + ], + ]; $row = [ 'sourceid1' => 'source_id_value_1', 'sourceid2' => 'source_id_value_2', - 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_1']), + 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash( + [ + 'source_id_property1' => 'source_id_value_1', + 'source_id_property2' => 'source_id_value_2' + ]), 'destid1' => 'destination_id_value_1', ] + $this->idMapDefaults(); $this->saveMap($row); $row = [ 'sourceid1' => 'source_id_value_3', 'sourceid2' => 'source_id_value_4', - 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_3']), + 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash( + [ + 'source_id_property1' => 'source_id_value_3', + 'source_id_property2' => 'source_id_value_4' + ]), 'destid1' => 'destination_id_value_2', - ] + $this->idMapDefaults(); + ] + $this->idMapDefaults(); $this->saveMap($row); + $expected = [ + 'source_id_property1' . Sql::ID_SUFFIX => 'source_id_value_3', + 'source_id_property2' . Sql::ID_SUFFIX => 'source_id_value_4', + 'source_ids_hash' => $this->getIdMap()->getSourceIDsHash( + [ + 'source_id_property1' => 'source_id_value_3', + 'source_id_property2' => 'source_id_value_4' + ]), + 'destination_id_property' . Sql::ID_SUFFIX => 'destination_id_value_2', + ] + $this->idMapDefaults(); $dest_id_values = ['destination_id_property' => $row['destid1']]; $id_map = $this->getIdMap(); $result_row = $id_map->getRowByDestination($dest_id_values); - $this->assertSame($row, $result_row); + // Sort expected_results to the same order as $result_row. + foreach ($result_row as $key => $value) { + if (isset($expected[$key]) || array_key_exists($key, $expected)) { + $expected_results[$key] = $expected[$key]; + } + } + $this->assertSame($expected_results, $result_row); // This value does not exist. $dest_id_values = ['destination_id_property' => 'invalid_destination_id_property']; $id_map = $this->getIdMap();