public function DatabaseSanitizeCase::testDatabaseSanitizeCommands in Database Sanitize 8
Same name and namespace in other branches
- 7 drush/tests/DatabaseSanitizeTest.php \Unish\DatabaseSanitizeCase::testDatabaseSanitizeCommands()
Tests Database Sanitize drush commands.
File
- drush/
tests/ DatabaseSanitizeTest.php, line 102
Class
- DatabaseSanitizeCase
- PHPUnit Tests for Database Sanitize.
Namespace
UnishCode
public function testDatabaseSanitizeCommands() {
// @see assets/database.sanitize.merge.yml
$this
->assertContains('users', $this->dbTables);
$this
->drush('sqlq', [
'show tables like "node_revision%";',
], $this->siteOptions);
$wildcard_tables = $this
->getOutputAsList();
// Test db-sanitize-analyze command.
$analyze_options = $this->siteOptions + [
'file' => $this->mergeYmlFile,
];
$dumped_tables_expected = count($this->dbTables) - (2 + count($wildcard_tables));
$this
->drush('db-sanitize-analyze', [], $analyze_options);
$eds_analyze_output = $this
->getErrorOutput();
$this
->assertContains(sprintf('There are %s tables not defined on sanitize YML files', $dumped_tables_expected), $eds_analyze_output);
$this
->assertFileExists($this->fullySpecifiedYmlFile);
$analyze_options['file'] = $this->fullySpecifiedYmlFile;
$this
->drush('db-sanitize-analyze', [], $analyze_options);
$this
->assertContains('All database tables are already specified', $this
->getErrorOutput());
// Test db-sanitize-generate command.
$generate_options = $this->siteOptions + [
'machine-name' => 'database_sanitize_test',
'file' => $this->mergeYmlFile,
];
$this
->drush('db-sanitize-generate', [], $generate_options);
$yaml = $this
->getOutput();
try {
$parsed_yaml = Yaml::parse($yaml);
} catch (ParseException $exception) {
$this
->fail(sprintf("Unable to parse the output as YAML: %s", $exception
->getMessage()));
}
$this
->assertArrayHasKey('sanitize', $parsed_yaml);
$this
->assertArrayHasKey('database_sanitize_test', $parsed_yaml['sanitize']);
// @see assets/database.sanitize.merge.yml
$this
->assertArrayNotHasKey('users', $parsed_yaml['sanitize']['database_sanitize_test']);
$generate_options['file'] = $this->fullySpecifiedYmlFile;
$this
->drush('db-sanitize-generate', [], $generate_options);
$this
->assertContains('All database tables are already specified', $this
->getErrorOutput());
}