You are here

public function DbDumpTest::testDbDumpCommand in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php \Drupal\KernelTests\Core\Command\DbDumpTest::testDbDumpCommand()
  2. 10 core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php \Drupal\KernelTests\Core\Command\DbDumpTest::testDbDumpCommand()

Test the command directly.

File

core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php, line 155

Class

DbDumpTest
Tests for the database dump commands.

Namespace

Drupal\KernelTests\Core\Command

Code

public function testDbDumpCommand() {
  $application = new DbDumpApplication();
  $command = $application
    ->find('dump-database-d8-mysql');
  $command_tester = new CommandTester($command);
  $command_tester
    ->execute([]);

  // Tables that are schema-only should not have data exported.
  $pattern = preg_quote("\$connection->insert('sessions')");
  $this
    ->assertNotRegExp('/' . $pattern . '/', $command_tester
    ->getDisplay(), 'Tables defined as schema-only do not have data exported to the script.');

  // Table data is exported.
  $pattern = preg_quote("\$connection->insert('config')");
  $this
    ->assertRegExp('/' . $pattern . '/', $command_tester
    ->getDisplay(), 'Table data is properly exported to the script.');

  // The test data are in the dump (serialized).
  $pattern = preg_quote(serialize($this->data));
  $this
    ->assertRegExp('/' . $pattern . '/', $command_tester
    ->getDisplay(), 'Generated data is found in the exported script.');

  // Check that the user account name and email address was properly escaped.
  $pattern = preg_quote('"q\'uote\\$dollar@example.com"');
  $this
    ->assertRegExp('/' . $pattern . '/', $command_tester
    ->getDisplay(), 'The user account email address was properly escaped in the exported script.');
  $pattern = preg_quote('\'$dollar\'');
  $this
    ->assertRegExp('/' . $pattern . '/', $command_tester
    ->getDisplay(), 'The user account name was properly escaped in the exported script.');
}