diff --git a/core/lib/Drupal/Core/Command/DbDumpCommand.php b/core/lib/Drupal/Core/Command/DbDumpCommand.php index d991150..4002729 100644 --- a/core/lib/Drupal/Core/Command/DbDumpCommand.php +++ b/core/lib/Drupal/Core/Command/DbDumpCommand.php @@ -9,7 +9,7 @@ use Drupal\Component\Utility\Variable; use Drupal\Core\Database\Connection; -use Drupal\Core\Extension\ModuleHandler; +use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -27,7 +27,7 @@ class DbDumpCommand extends Command { protected $connection; /** - * @var \Drupal\Core\Extension\ModuleHandler + * @var \Drupal\Core\Extension\ModuleHandlerInterface */ protected $moduleHandler; @@ -49,9 +49,9 @@ class DbDumpCommand extends Command { /** * @param \Drupal\Core\Database\Connection $connection - * @param \Drupal\Core\Extension\ModuleHandler $module_handler + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */ - function __construct(Connection $connection, ModuleHandler $module_handler) { + function __construct(Connection $connection, ModuleHandlerInterface $module_handler) { $this->connection = $connection; $this->moduleHandler = $module_handler; parent::__construct(); @@ -127,7 +127,7 @@ protected function getTables() { */ protected function getTableSchema($table) { // @todo this implementation is hard-coded for MySQL. - $query = $this->connection->query("SHOW COLUMNS FROM {$table}"); + $query = $this->connection->query("SHOW COLUMNS FROM {" . $table . "}"); $definition = []; while (($row = $query->fetchAssoc()) !== FALSE) { $name = $row['Field']; @@ -192,7 +192,7 @@ protected function getTableData($table) { } } $order = $this->getFieldOrder($table); - $query = $this->connection->query("SELECT * FROM {$table} " . $order ); + $query = $this->connection->query("SELECT * FROM {" . $table . "} " . $order ); $results = []; while (($row = $query->fetchAssoc()) !== FALSE) { $results[] = $row; @@ -227,7 +227,7 @@ protected function getFieldOrder($table) { $order = ''; $query = "SELECT `COLUMN_NAME` FROM `information_schema`.`COLUMNS` WHERE (`TABLE_SCHEMA` = '" . $connection_info['database'] . "') - AND (`TABLE_NAME` = '{$table}') AND (`COLUMN_KEY` = 'PRI') + AND (`TABLE_NAME` = '{" . $table . "}') AND (`COLUMN_KEY` = 'PRI') ORDER BY COLUMN_NAME"; $results = $this->connection->query($query); while (($row = $results->fetchAssoc()) !== FALSE) { @@ -245,7 +245,7 @@ protected function getFieldOrder($table) { * @return string */ protected function getTemplate() { - $script = <<installSchema('system', ['sessions', 'url_alias']); + + // Place some sample config to test for in the export. + $this->data = ['foo' => $this->randomString(), 'bar' => $this->randomString()]; + $storage = new DatabaseStorage(Database::getConnection(), 'config'); + $storage->write('test_config', $this->data); } /** @@ -59,6 +73,10 @@ public function testDbDumpCommand() { // Table data is exported. $pattern = preg_quote("\$connection->insert('config')"); $this->assertTrue(preg_match('/' . $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->assertTrue(preg_match('/' . $pattern . '/', $command_tester->getDisplay()), 'Generated data is found in the exported script.'); } }