You are here

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

Fully test migrate messages.

File

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

Class

DrushCommandsTest
Execute drush on fully functional website.

Namespace

Drupal\Tests\migrate_tools\Functional

Code

public function testMessages() {
  $this
    ->drush('mim', [
    'fruit_terms',
  ]);
  $this
    ->drush('mmsg', [
    'fruit_terms',
  ]);
  $this
    ->assertErrorOutputEquals('[notice] No messages for this migration');

  /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map */
  $id_map = $this->container
    ->get('plugin.manager.migration')
    ->createInstance('fruit_terms')
    ->getIdMap();
  $id_map
    ->saveMessage([
    'name' => 'Apple',
  ], 'You picked a bad one.');
  $this
    ->drush('mmsg', [
    'fruit_terms',
  ], [
    'format' => 'json',
  ]);
  $expected = [
    [
      'level' => '1',
      'message' => 'You picked a bad one.',
      'source_ids' => 'Apple',
      'destination_ids' => '1',
    ],
  ];
  $this
    ->assertEquals($expected, $this
    ->getOutputFromJSON());
  $this
    ->drush('mmsg', [
    'fruit_terms',
  ], [
    'format' => 'csv',
  ]);
  $expected = <<<EOT
"Source ID(s)","Destination ID(s)",Level,Message
Apple,1,1,"You picked a bad one."
EOT;
  $this
    ->assertEquals($expected, $this
    ->getOutput());
}