Skip to content

Commit

Permalink
OPENEUROPA-1149: Update the tests to make sure that the settings over…
Browse files Browse the repository at this point in the history
…ride file is properly included.
  • Loading branch information
drupol committed Oct 1, 2018
1 parent 5630d84 commit fc56405
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
13 changes: 13 additions & 0 deletions tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,17 @@ protected function getSandboxRoot()
{
return __DIR__."/sandbox";
}

/**
* Generate a random string.
*
* @param int $length
* The desired length.
*
* @return string
* The random string.
*/
protected function generateRandomString($length = 10) {
return substr(str_shuffle(str_repeat($x = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)))), 1, $length);
}
}
50 changes: 48 additions & 2 deletions tests/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function testSettingsSetup(array $config, array $expected)

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

$sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default';
$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', '');

Expand All @@ -158,6 +158,29 @@ public function testSettingsSetup(array $config, array $expected)
$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 = $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));
}

/**
Expand All @@ -171,7 +194,7 @@ public function testSettingsSetupForce(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';
$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', '');
file_put_contents($this->getSandboxRoot() . '/build/sites/' . $sites_subdir . '/settings.php', '# Already existing file.');
Expand All @@ -184,6 +207,29 @@ public function testSettingsSetupForce(array $config, array $expected)
$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 = $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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/commands/drupal-settings-setup-force.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
force: true
expected:
- file: "build/sites/default/settings.php"
contains: "include $app_root . '/' . $site_path . '/settings.override.php';"
contains: "include $app_root . '/' . $site_path . '/' . settings.override.php;"
not_contains: "# Already existing file."
6 changes: 3 additions & 3 deletions tests/fixtures/commands/drupal-settings-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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 $app_root . '/' . $site_path . '/settings.override.php';"
contains: "include $app_root . '/' . $site_path . '/' . settings.override.php;"
not_contains: ~

- configuration:
Expand Down Expand Up @@ -47,7 +47,7 @@
contains: "$settings[\"file_scan_ignore_directories\"] = array(0 => 'build');"
not_contains: ~
- file: "build/sites/default/settings.php"
contains: "include $app_root . '/' . $site_path . '/settings.overridemeplease.php';"
contains: "include $app_root . '/' . $site_path . '/' . settings.overridemeplease.php;"
not_contains: ~

- configuration:
Expand All @@ -64,5 +64,5 @@
contains: "$settings[\"file_scan_ignore_directories\"] = array(0 => 'build');"
not_contains: ~
- file: "build/sites/inea/settings.php"
contains: "include $app_root . '/' . $site_path . '/settings.overridemeplease.php';"
contains: "include $app_root . '/' . $site_path . '/' . settings.overridemeplease.php;"
not_contains: ~

0 comments on commit fc56405

Please sign in to comment.