You are here

public function MigrateSqlIdMapTest::testDestroy in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testDestroy()

Tests the destroy method.

Scenarios to test for:

  • No errors.
  • One error.
  • Multiple errors.

File

core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php, line 732
Contains \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest.

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testDestroy() {
  $id_map = $this
    ->getIdMap();

  // Initialize the id map.
  $id_map
    ->getDatabase();
  $map_table_name = $id_map
    ->mapTableName();
  $message_table_name = $id_map
    ->messageTableName();
  $row = new Row([
    'source_id_property' => 'source_value',
  ], [
    'source_id_property' => [],
  ]);
  $id_map
    ->saveIdMapping($row, [
    'destination_id_property' => 2,
  ]);
  $id_map
    ->saveMessage([
    'source_id_property' => 'source_value',
  ], 'A message');
  $this
    ->assertTrue($this->database
    ->schema()
    ->tableExists($map_table_name), "{$map_table_name} exists");
  $this
    ->assertTrue($this->database
    ->schema()
    ->tableExists($message_table_name), "{$message_table_name} exists");
  $id_map
    ->destroy();
  $this
    ->assertFalse($this->database
    ->schema()
    ->tableExists($map_table_name), "{$map_table_name} does not exist");
  $this
    ->assertFalse($this->database
    ->schema()
    ->tableExists($message_table_name), "{$message_table_name} does not exist");
}