Commit 5efb185f authored by webchick's avatar webchick

Issue #1705748 by n3or, tim.plunkett, sun, xjm, boombatower: Convert...

Issue #1705748 by n3or, tim.plunkett, sun, xjm, boombatower: Convert simpletest settings to configuration system.
parent f1cde31f
......@@ -5145,7 +5145,7 @@ function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1)
// distribution we need to include the profile of the parent site (in which
// test runs are triggered).
if (drupal_valid_test_ua()) {
$testing_profile = variable_get('simpletest_parent_profile', FALSE);
$testing_profile = config('simpletest.settings')->get('parent_profile');
if ($testing_profile && $testing_profile != $profile) {
$searchdir[] = drupal_get_path('profile', $testing_profile) . '/' . $directory;
}
......
......@@ -530,8 +530,10 @@ protected function verbose($message) {
* methods during debugging.
*/
public function run(array $methods = array()) {
$simpletest_config = config('simpletest.settings');
$class = get_class($this);
if (variable_get('simpletest_verbose', TRUE)) {
if ($simpletest_config->get('verbose')) {
// Initialize verbose debugging.
$this->verbose = TRUE;
$this->verboseDirectory = variable_get('file_public_path', conf_path() . '/files') . '/simpletest/verbose';
......@@ -542,10 +544,10 @@ public function run(array $methods = array()) {
}
// HTTP auth settings (<username>:<password>) for the simpletest browser
// when sending requests to the test site.
$this->httpauth_method = variable_get('simpletest_httpauth_method', CURLAUTH_BASIC);
$username = variable_get('simpletest_httpauth_username', NULL);
$password = variable_get('simpletest_httpauth_password', NULL);
if ($username && $password) {
$this->httpauth_method = (int) $simpletest_config->get('httpauth.method');
$username = $simpletest_config->get('httpauth.username');
$password = $simpletest_config->get('httpauth.password');
if (!empty($username) && !empty($password)) {
$this->httpauth_credentials = $username . ':' . $password;
}
......
......@@ -84,7 +84,7 @@ function testInternalBrowser() {
'name' => $user->name,
'pass' => $user->pass_raw
);
variable_set('simpletest_maximum_redirects', 1);
$this->maximumRedirects = 1;
$this->drupalPost('user', $edit, t('Log in'), array(
'query' => array('destination' => 'user/logout'),
));
......
......@@ -139,6 +139,11 @@ abstract class WebTestBase extends TestBase {
*/
protected $generatedTestFiles = FALSE;
/**
* The maximum number of redirects to follow when handling responses.
*/
protected $maximumRedirects = 5;
/**
* The number of redirects followed during the handling of a request.
*/
......@@ -628,11 +633,11 @@ protected function setUp() {
variable_set('file_private_path', $this->private_files_directory);
variable_set('file_temporary_path', $this->temp_files_directory);
// Set the 'simpletest_parent_profile' variable to add the parent profile's
// Set 'parent_profile' of simpletest to add the parent profile's
// search path to the child site's search paths.
// @see drupal_system_listing()
// @todo This may need to be primed like 'install_profile' above.
variable_set('simpletest_parent_profile', $this->originalProfile);
config('simpletest.settings')->set('parent_profile', $this->originalProfile)->save();
// Include the testing profile.
variable_set('install_profile', $this->profile);
......@@ -902,7 +907,7 @@ protected function curlExec($curl_options, $redirect = FALSE) {
// to prevent fragments being sent to the web server as part
// of the request.
// TODO: Remove this for Drupal 8, since fixed in curl 7.20.0.
if (in_array($status, array(300, 301, 302, 303, 305, 307)) && $this->redirect_count < variable_get('simpletest_maximum_redirects', 5)) {
if (in_array($status, array(300, 301, 302, 303, 305, 307)) && $this->redirect_count < $this->maximumRedirects) {
if ($this->drupalGetHeader('location')) {
$this->redirect_count++;
$curl_options = array();
......
......@@ -170,13 +170,19 @@ function simpletest_uninstall() {
drupal_load('module', 'simpletest');
simpletest_clean_database();
// Remove settings variables.
variable_del('simpletest_httpauth_method');
variable_del('simpletest_httpauth_username');
variable_del('simpletest_httpauth_password');
variable_del('simpletest_clear_results');
variable_del('simpletest_verbose');
// Remove generated files.
file_unmanaged_delete_recursive('public://simpletest');
}
/**
* Move simpletest settings from variables to config.
*/
function simpletest_update_8000() {
update_variables_to_config('simpletest.settings', array(
'simpletest_clear_results' => 'clear_results',
'simpletest_httpauth_method' => 'httpauth.method',
'simpletest_httpauth_password' => 'httpauth.password',
'simpletest_httpauth_username' => 'httpauth.username',
'simpletest_verbose' => 'verbose',
));
}
......@@ -429,7 +429,7 @@ function simpletest_generate_file($filename, $width, $lines, $type = 'binary-tex
function simpletest_clean_environment() {
simpletest_clean_database();
simpletest_clean_temporary_directories();
if (variable_get('simpletest_clear_results', TRUE)) {
if (config('simpletest.settings')->get('clear_results')) {
$count = simpletest_clean_results_table();
drupal_set_message(format_plural($count, 'Removed 1 test result.', 'Removed @count test results.'));
}
......@@ -498,7 +498,7 @@ function simpletest_clean_temporary_directories() {
* The number of results removed.
*/
function simpletest_clean_results_table($test_id = NULL) {
if (variable_get('simpletest_clear_results', TRUE)) {
if (config('simpletest.settings')->get('clear_results')) {
if ($test_id) {
$count = db_query('SELECT COUNT(test_id) FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id))->fetchField();
......
......@@ -432,8 +432,10 @@ function simpletest_result_status_image($status) {
*
* @ingroup forms
* @see simpletest_settings_form_validate()
* @see simpletest_settings_form_submit()
*/
function simpletest_settings_form($form, &$form_state) {
$config = config('simpletest.settings');
$form['general'] = array(
'#type' => 'fieldset',
'#title' => t('General'),
......@@ -442,13 +444,13 @@ function simpletest_settings_form($form, &$form_state) {
'#type' => 'checkbox',
'#title' => t('Clear results after each complete test suite run'),
'#description' => t('By default SimpleTest will clear the results after they have been viewed on the results page, but in some cases it may be useful to leave the results in the database. The results can then be viewed at <em>admin/config/development/testing/[test_id]</em>. The test ID can be found in the database, simpletest table, or kept track of when viewing the results the first time. Additionally, some modules may provide more analysis or features that require this setting to be disabled.'),
'#default_value' => variable_get('simpletest_clear_results', TRUE),
'#default_value' => $config->get('clear_results'),
);
$form['general']['simpletest_verbose'] = array(
'#type' => 'checkbox',
'#title' => t('Provide verbose information when running tests'),
'#description' => t('The verbose data will be printed along with the standard assertions and is useful for debugging. The verbose data will be erased between each test suite run. The verbose data output is very detailed and should only be used when debugging.'),
'#default_value' => variable_get('simpletest_verbose', TRUE),
'#default_value' => $config->get('verbose'),
);
$form['httpauth'] = array(
......@@ -469,16 +471,16 @@ function simpletest_settings_form($form, &$form_state) {
CURLAUTH_ANY => t('Any'),
CURLAUTH_ANYSAFE => t('Any safe'),
),
'#default_value' => variable_get('simpletest_httpauth_method', CURLAUTH_BASIC),
'#default_value' => $config->get('httpauth.method'),
);
$username = variable_get('simpletest_httpauth_username');
$password = variable_get('simpletest_httpauth_password');
$username = $config->get('httpauth.username');
$password = $config->get('httpauth.password');
$form['httpauth']['simpletest_httpauth_username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => $username,
);
if ($username && $password) {
if (!empty($username) && !empty($password)) {
$form['httpauth']['simpletest_httpauth_username']['#description'] = t('Leave this blank to delete both the existing username and password.');
}
$form['httpauth']['simpletest_httpauth_password'] = array(
......@@ -489,7 +491,20 @@ function simpletest_settings_form($form, &$form_state) {
$form['httpauth']['simpletest_httpauth_password']['#description'] = t('To change the password, enter the new password here.');
}
return system_settings_form($form);
return system_config_form($form, $form_state);
}
/**
* Form submission handler for simpletest_settings_form().
*/
function simpletest_settings_form_submit($form, &$form_state) {
config('simpletest.settings')
->set('clear_results', $form_state['values']['simpletest_clear_results'])
->set('verbose', $form_state['values']['simpletest_verbose'])
->set('httpauth.method', $form_state['values']['simpletest_httpauth_method'])
->set('httpauth.username', $form_state['values']['simpletest_httpauth_username'])
->set('httpauth.password', $form_state['values']['simpletest_httpauth_password'])
->save();
}
/**
......@@ -499,7 +514,7 @@ function simpletest_settings_form_validate($form, &$form_state) {
// If a username was provided but a password wasn't, preserve the existing
// password.
if (!empty($form_state['values']['simpletest_httpauth_username']) && empty($form_state['values']['simpletest_httpauth_password'])) {
$form_state['values']['simpletest_httpauth_password'] = variable_get('simpletest_httpauth_password', '');
$form_state['values']['simpletest_httpauth_password'] = config('simpletest.settings')->get('httpauth.password');
}
// If a password was provided but a username wasn't, the credentials are
......
......@@ -376,9 +376,6 @@ function simpletest_script_run_one_test($test_id, $test_class) {
// Override configuration according to command line parameters.
$conf['simpletest.settings']['verbose'] = $args['verbose'];
$conf['simpletest.settings']['clear_results'] = !$args['keep-results'];
// @todo D8: Remove after converting Simpletest settings to config.
$conf['simpletest_verbose'] = $args['verbose'];
$conf['simpletest_clear_results'] = !$args['keep-results'];
$test = new $test_class($test_id);
$test->run();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment