Commit 8dea1fb4 authored by catch's avatar catch
Browse files

Issue #3227549 by huzooka, Wim Leers: Sql id map plugin's getRowByDestination...

Issue #3227549 by huzooka, Wim Leers: Sql id map plugin's getRowByDestination shouldn't return FALSE
parent b85fb24c
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -539,10 +539,13 @@ public function getRowByDestination(array $destination_id_values) {
    $query = $this->getDatabase()->select($this->mapTableName(), 'map')
      ->fields('map');
    foreach ($this->destinationIdFields() as $field_name => $destination_id) {
      if (!isset($destination_id_values[$field_name])) {
        return [];
      }
      $query->condition("map.$destination_id", $destination_id_values[$field_name], '=');
    }
    $result = $query->execute();
    return $result->fetchAssoc();
    $result = $query->execute()->fetchAssoc();
    return $result ? $result : [];
  }

  /**
+13 −5
Original line number Diff line number Diff line
@@ -571,11 +571,19 @@ public function testGetRowByDestination() {
    $id_map = $this->getIdMap();
    $result_row = $id_map->getRowByDestination($dest_id_values);
    $this->assertSame($row, $result_row);
    // This value does not exist.
    $dest_id_values = ['destination_id_property' => 'invalid_destination_id_property'];
    $id_map = $this->getIdMap();
    $result_row = $id_map->getRowByDestination($dest_id_values);
    $this->assertFalse($result_row);
    // This value does not exist, getRowByDestination should return an (empty)
    // array.
    // @see \Drupal\migrate\Plugin\MigrateIdMapInterface::getRowByDestination()
    $missing_result_row = $id_map->getRowByDestination([
      'destination_id_property' => 'invalid_destination_id_property',
    ]);
    $this->assertEquals([], $missing_result_row);
    // The destination ID values array does not contain all the destination ID
    // keys, we expect an empty array.
    $invalid_result_row = $id_map->getRowByDestination([
      'invalid_destination_key' => 'invalid_destination_id_property',
    ]);
    $this->assertEquals([], $invalid_result_row);
  }

  /**