public function DrushCommandsTest::testSyncImport in Migrate Tools 8.5
Same name and namespace in other branches
- 8.4 tests/src/Functional/DrushCommandsTest.php \Drupal\Tests\migrate_tools\Functional\DrushCommandsTest::testSyncImport()
Tests synced import.
File
- tests/
src/ Functional/ DrushCommandsTest.php, line 186
Class
- DrushCommandsTest
- Execute drush on fully functional website.
Namespace
Drupal\Tests\migrate_tools\FunctionalCode
public function testSyncImport() : void {
$this
->drush('mim', [
'fruit_terms',
]);
$this
->assertStringContainsString('1/3', $this
->getErrorOutput());
$this
->assertStringContainsString('3/3', $this
->getErrorOutput());
$this
->assertStringContainsString('[notice] Processed 3 items (3 created, 0 updated, 0 failed, 0 ignored) - done with \'fruit_terms\'', $this
->getErrorOutput());
$this
->assertStringNotContainsString('4', $this
->getErrorOutput());
$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,
]);
$this
->assertStringContainsString('1/3', $this
->getErrorOutput());
$this
->assertStringContainsString('4/4', $this
->getErrorOutput());
$this
->assertStringContainsString('[notice] Processed 3 items (1 created, 2 updated, 0 failed, 0 ignored) - done with \'fruit_terms\'', $this
->getErrorOutput());
$this
->assertStringNotContainsString('5', $this
->getErrorOutput());
$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);
}