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 197ac6d commit e81cf3d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,18 @@ 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: 50 additions & 0 deletions tests/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,31 @@ 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 = 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));
}

/**
Expand All @@ -184,6 +209,31 @@ 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 = 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));
}

/**
Expand Down

0 comments on commit e81cf3d

Please sign in to comment.