Skip to content

Commit

Permalink
Issue #89: Add specific tests for Drupal 7 and 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Nov 23, 2018
1 parent 90e52fe commit 8171b30
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp()
{
$filesystem = new Filesystem();
$filesystem->chmod($this->getSandboxRoot(), 0777, umask(), true);
$filesystem->remove(glob($this->getSandboxRoot()."/*"));
$filesystem->remove(glob($this->getSandboxRoot() . '/*'));
date_default_timezone_set('Europe/London');
}

Expand Down
69 changes: 64 additions & 5 deletions tests/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public function testDrushSetup(array $config, array $expected)
* @param array $config
* @param array $expected
*
* @dataProvider settingsSetupDataProvider
* @dataProvider drupal7SettingsSetupDataProvider
*/
public function testSettingsSetup(array $config, array $expected)
public function testDrupal7SettingsSetup(array $config, array $expected)
{
$configFile = $this->getSandboxFilepath('runner.yml');

Expand All @@ -176,7 +176,58 @@ public function testSettingsSetup(array $config, array $expected)
mkdir($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/', 0777, true);
file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/default.settings.php', '');

$input = new StringInput("drupal:settings-setup --working-dir=".$this->getSandboxRoot());
$input = new StringInput('drupal:settings-setup --working-dir=' . $this->getSandboxRoot());
$runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader());
$runner->run();

foreach ($expected as $row) {
$content = file_get_contents($this->getSandboxFilepath($row['file']));
$this->assertContainsNotContains($content, $row);
}

// Generate a random function name.
$fct = $this->generateRandomString(20);

// Generate a dummy PHP code.
$config_override_dummy_script = <<< EOF
<?php
function $fct() {}
EOF;

$config_override_filename = isset($config['drupal']['site']['settings_override_file']) ?
$config['drupal']['site']['settings_override_file'] :
'settings.override.php';

// Add the dummy PHP code to the config override file.
file_put_contents(
$this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/' . $config_override_filename,
$config_override_dummy_script
);

// Include the config override file.
include_once $this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/' . $config_override_filename;

// Test if the dummy PHP code has been properly included.
$this->assertTrue(\function_exists($fct));
}

/**
* @param array $config
* @param array $expected
*
* @dataProvider drupal8SettingsSetupDataProvider
*/
public function testDrupal8SettingsSetup(array $config, array $expected)
{
$configFile = $this->getSandboxFilepath('runner.yml');

file_put_contents($configFile, Yaml::dump($config));

$sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default';
mkdir($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/', 0777, true);
file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/default.settings.php', '');

$input = new StringInput('drupal:settings-setup --working-dir=' . $this->getSandboxRoot());
$runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader());
$runner->run();

Expand Down Expand Up @@ -304,9 +355,17 @@ public function drushSetupDataProvider()
/**
* @return array
*/
public function settingsSetupDataProvider()
public function drupal7SettingsSetupDataProvider()
{
return $this->getFixtureContent('commands/drupal7-settings-setup.yml');
}

/**
* @return array
*/
public function drupal8SettingsSetupDataProvider()
{
return $this->getFixtureContent('commands/drupal-settings-setup.yml');
return $this->getFixtureContent('commands/drupal8-settings-setup.yml');
}

/**
Expand Down
72 changes: 72 additions & 0 deletions tests/fixtures/commands/drupal7-settings-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
- configuration:
drupal:
core: 7
settings:
conf:
file_scan_ignore_directories:
- "node_modules"
- "bower_components"
- "vendor"
- "${drupal.root}"
expected:
- file: "build/sites/default/settings.override.php"
contains: "$conf[\"file_scan_ignore_directories\"] = array(0 => 'node_modules',1 => 'bower_components',2 => 'vendor',3 => 'build');"
not_contains: ~
- file: "build/sites/default/settings.php"
contains: "include DRUPAL_ROOT . '/' . $conf_path . '/settings.override.php';"
not_contains: ~

- configuration:
drupal:
core: 7
settings:
settings:
file_scan_ignore_directories:
- "${drupal.root}"
expected:
- file: "build/sites/default/settings.override.php"
contains: "$settings[\"file_scan_ignore_directories\"] = array(0 => 'build');"
not_contains: ~

- configuration:
drupal:
settings: []
expected:
- file: "build/sites/default/settings.override.php"
contains: "// Start settings processor block."
not_contains: "file_scan_ignore_directories"

- configuration:
drupal:
core: 7
settings:
settings:
file_scan_ignore_directories:
- "${drupal.root}"
site:
settings_override_file: "settings.overridemeplease.php"
expected:
- file: "build/sites/default/settings.overridemeplease.php"
contains: "$settings[\"file_scan_ignore_directories\"] = array(0 => 'build');"
not_contains: ~
- file: "build/sites/default/settings.php"
contains: "include DRUPAL_ROOT . '/' . $conf_path . '/settings.overridemeplease.php';"
not_contains: ~

- configuration:
drupal:
core: 7
settings:
settings:
file_scan_ignore_directories:
- "${drupal.root}"
site:
sites_subdir: "inea"
settings_override_file: "settings.overridemeplease.php"
expected:
- file: "build/sites/inea/settings.overridemeplease.php"
contains: "$settings[\"file_scan_ignore_directories\"] = array(0 => 'build');"
not_contains: ~
- file: "build/sites/inea/settings.php"
contains: "include DRUPAL_ROOT . '/' . $conf_path . '/settings.overridemeplease.php';"
not_contains: ~

0 comments on commit 8171b30

Please sign in to comment.