You are here

public function MigrateSqlIdMapTest::testClearMessages in Drupal 9

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

Tests the clear messages method.

File

core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php, line 203

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testClearMessages() {
  $message = 'Hello world.';
  $expected_results = [
    0,
    1,
    2,
    3,
  ];
  $id_map = $this
    ->getIdMap();

  // Insert 4 message for later delete.
  foreach ($expected_results as $key => $expected_result) {
    $id_map
      ->saveMessage([
      'source_id_property' => $key,
    ], $message);
  }

  // Truncate and check that 4 messages were deleted.
  $this
    ->assertSame($id_map
    ->messageCount(), 4);
  $id_map
    ->clearMessages();
  $count = $id_map
    ->messageCount();
  $this
    ->assertSame($count, 0);
}