You are here

public function DrushCommandsTest::testSyncImport in Migrate Tools 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/DrushCommandsTest.php \Drupal\Tests\migrate_tools\Functional\DrushCommandsTest::testSyncImport()

Tests synced import.

File

tests/src/Functional/DrushCommandsTest.php, line 191

Class

DrushCommandsTest
Execute drush on fully functional website.

Namespace

Drupal\Tests\migrate_tools\Functional

Code

public function testSyncImport() {
  $this
    ->drush('mim', [
    'fruit_terms',
  ]);
  $expected = [
    '1/3 [=========>------------------]  33%',
    ' 2/3 [==================>---------]  66%',
    ' 3/3 [============================] 100% [notice] Processed 3 items (3 created, 0 updated, 0 failed, 0 ignored) - done with \'fruit_terms\'',
  ];
  $this
    ->assertEquals($expected, $this
    ->getErrorOutputAsList());
  $term = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->load(2);
  $this
    ->assertEquals('Banana', $term
    ->label());
  $this
    ->assertEquals(3, \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->getQuery()
    ->count()
    ->execute());
  $source = $this->container
    ->get('config.factory')
    ->getEditable('migrate_plus.migration.fruit_terms')
    ->get('source');
  unset($source['data_rows'][1]);
  $source['data_rows'][] = [
    'name' => 'Grape',
  ];
  $this->container
    ->get('config.factory')
    ->getEditable('migrate_plus.migration.fruit_terms')
    ->set('source', $source)
    ->save();

  // Flush cache so the recently changed migration can be refreshed.
  drupal_flush_all_caches();
  $this
    ->drush('mim', [
    'fruit_terms',
  ], [
    'sync' => NULL,
  ]);
  $expected = [
    '1/3 [=========>------------------]  33% [notice] Rolled back 1 item - done with \'fruit_terms\'',
    '',
    ' 2/3 [==================>---------]  66%',
    ' 3/3 [============================] 100%',
    ' 4/4 [============================] 100% [notice] Processed 3 items (1 created, 2 updated, 0 failed, 0 ignored) - done with \'fruit_terms\'',
  ];
  $this
    ->assertEquals($expected, $this
    ->getErrorOutputAsList());
  $this
    ->assertEquals(3, \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->getQuery()
    ->count()
    ->execute());
  $this
    ->assertEmpty(\Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->load(2));

  /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map */
  $id_map = $this->container
    ->get('plugin.manager.migration')
    ->createInstance('fruit_terms')
    ->getIdMap();
  $this
    ->assertCount(3, $id_map);
}