You are here

public function DrushCommandsTest::testDrush 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::testDrush()

Tests many of the migrate drush commands.

File

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

Class

DrushCommandsTest
Execute drush on fully functional website.

Namespace

Drupal\Tests\migrate_tools\Functional

Code

public function testDrush() {
  $this
    ->drush('ms', [], [], NULL, NULL, 1);
  $this
    ->assertContains('The "does_not_exist" plugin does not exist.', $this
    ->getErrorOutput());
  $this->container
    ->get('config.factory')
    ->getEditable('migrate_plus.migration.invalid_plugin')
    ->delete();

  // Flush cache so the recently removed invalid migration is cleared.
  drupal_flush_all_caches();
  $this
    ->drush('ms', [], [
    'format' => 'json',
  ]);
  $expected = [
    [
      'group' => 'Default (default)',
      'id' => 'fruit_terms',
      'imported' => 0,
      'status' => 'Idle',
      'total' => 3,
      'unprocessed' => 3,
      'last_imported' => '',
    ],
    [
      'group' => 'Default (default)',
      'id' => 'source_exception',
      'imported' => 0,
      'status' => 'Idle',
      'total' => 0,
      'unprocessed' => 0,
      'last_imported' => '',
    ],
  ];
  $this
    ->assertEquals($expected, $this
    ->getOutputFromJSON());
  $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
    ->drush('mim', [
    'fruit_terms',
  ]);
  $this
    ->assertEquals($expected, $this
    ->getErrorOutputAsList());
  $expected = [
    '1/3 [=========>------------------]  33%',
    ' 2/3 [==================>---------]  66%',
    ' 3/3 [============================] 100% [notice] Processed 3 items (0 created, 3 updated, 0 failed, 0 ignored) - done with \'fruit_terms\'',
  ];
  $this
    ->drush('mim', [
    'fruit_terms',
  ], [
    'update' => NULL,
    'force' => NULL,
    'execute-dependencies' => NULL,
  ]);
  $this
    ->assertEquals($expected, $this
    ->getErrorOutputAsList());
  $this
    ->drush('mrs', [
    'fruit_terms',
  ]);
  $this
    ->assertErrorOutputEquals('[warning] Migration fruit_terms is already Idle');
  $this
    ->drush('mfs', [
    'fruit_terms',
  ], [
    'format' => 'json',
  ]);
  $expected = [
    [
      'machine_name' => 'name',
      'description' => 'name',
    ],
  ];
  $this
    ->assertEquals($expected, $this
    ->getOutputFromJSON());
  $this
    ->drush('mr', [
    'fruit_terms',
  ]);
  $expected = [
    '1/3 [=========>------------------]  33%',
    ' 2/3 [==================>---------]  66%',
    ' 3/3 [============================] 100% [notice] Rolled back 3 items - done with \'fruit_terms\'',
  ];
  $this
    ->assertEquals($expected, $this
    ->getErrorOutputAsList());
  $this
    ->drush('migrate:stop', [
    'fruit_terms',
  ]);
  $this
    ->assertErrorOutputEquals('[warning] Migration fruit_terms is idle');
  $this
    ->drush('mim', [
    'fruit_terms',
  ], [
    'skip-progress-bar' => NULL,
  ]);
  $this
    ->assertErrorOutputEquals('[notice] Processed 3 items (3 created, 0 updated, 0 failed, 0 ignored) - done with \'fruit_terms\'');
  $this
    ->drush('mr', [
    'fruit_terms',
  ], [
    'skip-progress-bar' => NULL,
  ]);
  $this
    ->assertErrorOutputEquals('[notice] Rolled back 3 items - done with \'fruit_terms\'');
}