Skip to content

Commit

Permalink
OPENEUROPA-1271: Test that it is possible to specify the --skip-permi…
Browse files Browse the repository at this point in the history
…ssions-setup option in configuration.
  • Loading branch information
pfrenssen committed Oct 9, 2018
1 parent 849593c commit 32e9c54
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ abstract class AbstractTest extends TestCase
protected function setUp()
{
$filesystem = new Filesystem();
$filesystem->chmod($this->getSandboxRoot(), 0777, umask(), true);
$filesystem->remove(glob($this->getSandboxRoot()."/*"));
date_default_timezone_set('Europe/London');
}
Expand Down
32 changes: 26 additions & 6 deletions tests/Commands/DrupalCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ class DrupalCommandsTest extends AbstractTest
{
/**
* @param array $config
* The configuration array to pass to the command.
* @param string $command
* The command to execute.
* @param bool $expected_error
* Whether or not it is expected that the command will return an error
* code.
* @param string $expected_settings_dir_permission
* A string representing the octal permission number that is expected to
* be applied on the settings folder.
* @param string $expected_settings_file_permission
* A string representing the octal permission number that is expected to
* be applied on the settings file.
*
* @dataProvider drupalSettingsDataProvider
*/
public function testPermissions(array $config)
public function testPermissions(array $config, $command, $expected_error, $expected_settings_dir_permission, $expected_settings_file_permission)
{
$configFile = $this->getSandboxFilepath('runner.yml');
file_put_contents($configFile, Yaml::dump($config));
Expand All @@ -32,20 +44,28 @@ public function testPermissions(array $config)
// Prepare site settings file.
$siteSettings = $sitesSubdir . 'settings.php';
touch($siteSettings);
chmod($siteSettings, 0777);

// Make the settings folder and file unwritable so we can detect whether
// the exception is thrown in `DrupalCommands::validateSiteInstall()` as
// well as whether the permissions are correctly set.
chmod($siteSettings, 0444);
chmod($sitesSubdir, 0555);

// Run command.
$input = new StringInput("drupal:permissions-setup --working-dir=" . $this->getSandboxRoot());
$input = new StringInput("$command --working-dir=" . $this->getSandboxRoot());
$runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader());
$runner->run();
$exit_code = $runner->run();

// Check if an error is returned when this is expected.
$this->assertEquals($expected_error, $exit_code != 0);

// Check site directory.
$sitesSubdirPermissions = substr(sprintf('%o', fileperms($sitesSubdir)), -4);
$this->assertEquals('0775', $sitesSubdirPermissions);
$this->assertEquals($expected_settings_dir_permission, $sitesSubdirPermissions);

// Check site settings file.
$siteSettingsPermissions = substr(sprintf('%o', fileperms($siteSettings)), -4);
$this->assertEquals('0664', $siteSettingsPermissions);
$this->assertEquals($expected_settings_file_permission, $siteSettingsPermissions);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/commands/drupal-site-install.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# When the drupal:permissions-setup command is run it should make the settings
# folder and file writable, and there should not be any error.
- configuration:
drupal:
settings:
sites-subdir: "build/sites/default/"
settings_file: "settings.php"
command: "drupal:permissions-setup"
expected_error: false
expected_settings_dir_permission: "0775"
expected_settings_file_permission: "0664"

# When the drupal:site-install command is run with the 'skip-permission-setup'
# option set to 'true' then the settings folder and file should not be made
# writable, and an error should be returned.
- configuration:
drupal:
settings:
sites-subdir: "build/sites/default/"
settings_file: "settings.php"
skip-permissions-setup: true
command: "drupal:site-install"
expected_error: true
expected_settings_dir_permission: "0555"
expected_settings_file_permission: "0444"

0 comments on commit 32e9c54

Please sign in to comment.