You are here

public function SmartSqlTest::testSetUpdate in Smart SQL ID Map 1.0.x

Same name and namespace in other branches
  1. 1.1.x tests/src/Unit/Plugin/migrate/id_map/SmartSqlTest.php \Drupal\Tests\smart_sql_idmap\Unit\Plugin\migrate\id_map\SmartSqlTest::testSetUpdate()

Tests setting a row source_row_status to STATUS_NEEDS_UPDATE.

Overrides MigrateSqlIdMapTest::testSetUpdate

File

tests/src/Unit/Plugin/migrate/id_map/SmartSqlTest.php, line 343

Class

SmartSqlTest
Tests the Smart SQL ID map plugin.

Namespace

Drupal\Tests\smart_sql_idmap\Unit\Plugin\migrate\id_map

Code

public function testSetUpdate() {
  $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 that test values exist.
  $this
    ->queryResultTest($this
    ->getIdMapContents(), $expected_results);

  // Mark each row as STATUS_NEEDS_UPDATE.
  foreach ($row_statuses as $status) {
    $id_map
      ->setUpdate([
      'source_id_property' => 'source_value_' . $status,
    ]);
  }

  // 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);

  // Assert an exception is thrown when source identifiers are not provided.
  try {
    $id_map
      ->setUpdate([]);
    $this
      ->assertFalse(FALSE, 'MigrateException not thrown, when source identifiers were provided to update.');
  } catch (MigrateException $e) {
    $this
      ->assertTrue(TRUE, "MigrateException thrown, when source identifiers were not provided to update.");
  }
}