summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-03-17 06:02:41 (GMT)
committerwebchick2013-03-17 06:02:41 (GMT)
commiteb313a6feae5e5f1572e43502208ef5d86dc577a (patch)
tree55a872148395868f2f03172f66e5a02793c648d5
parentda805e2bc1d17d185fb38fe2294820dd95c4c5e0 (diff)
Issue #1937944 by ACF: Convert simpletest's system_config_form() to SystemConfigFormBase.
-rw-r--r--core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestSettingsForm.php120
-rw-r--r--core/modules/simpletest/simpletest.module4
-rw-r--r--core/modules/simpletest/simpletest.pages.inc97
-rw-r--r--core/modules/simpletest/simpletest.routing.yml6
4 files changed, 127 insertions, 100 deletions
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestSettingsForm.php b/core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestSettingsForm.php
new file mode 100644
index 0000000..cce1a8a
--- /dev/null
+++ b/core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestSettingsForm.php
@@ -0,0 +1,120 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\simpletest\Form\SimpletestSettingsForm.
+ */
+
+namespace Drupal\simpletest\Form;
+
+use Drupal\system\SystemConfigFormBase;
+
+/**
+ * Configure simpletest settings for this site.
+ */
+class SimpletestSettingsForm extends SystemConfigFormBase {
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::getFormID().
+ */
+ public function getFormID() {
+ return 'simpletest_settings_form';
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::buildForm().
+ */
+ public function buildForm(array $form, array &$form_state) {
+ $config = $this->configFactory->get('simpletest.settings');
+ $form['general'] = array(
+ '#type' => 'details',
+ '#title' => t('General'),
+ );
+ $form['general']['simpletest_clear_results'] = array(
+ '#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/results/[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' => $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' => $config->get('verbose'),
+ );
+
+ $form['httpauth'] = array(
+ '#type' => 'details',
+ '#title' => t('HTTP authentication'),
+ '#description' => t('HTTP auth settings to be used by the SimpleTest browser during testing. Useful when the site requires basic HTTP authentication.'),
+ '#collapsed' => TRUE,
+ );
+ $form['httpauth']['simpletest_httpauth_method'] = array(
+ '#type' => 'select',
+ '#title' => t('Method'),
+ '#options' => array(
+ CURLAUTH_BASIC => t('Basic'),
+ CURLAUTH_DIGEST => t('Digest'),
+ CURLAUTH_GSSNEGOTIATE => t('GSS negotiate'),
+ CURLAUTH_NTLM => t('NTLM'),
+ CURLAUTH_ANY => t('Any'),
+ CURLAUTH_ANYSAFE => t('Any safe'),
+ ),
+ '#default_value' => $config->get('httpauth.method'),
+ );
+ $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 (!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(
+ '#type' => 'password',
+ '#title' => t('Password'),
+ );
+ if ($password) {
+ $form['httpauth']['simpletest_httpauth_password']['#description'] = t('To change the password, enter the new password here.');
+ }
+
+ return parent::buildForm($form, $form_state);
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::validateForm().
+ */
+ public function validateForm(array &$form, array &$form_state) {
+ $config = $this->configFactory->get('simpletest.settings');
+ // 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'] = $config->get('httpauth.password');
+ }
+
+ // If a password was provided but a username wasn't, the credentials are
+ // incorrect, so throw an error.
+ if (empty($form_state['values']['simpletest_httpauth_username']) && !empty($form_state['values']['simpletest_httpauth_password'])) {
+ form_set_error('simpletest_httpauth_username', t('HTTP authentication credentials must include a username in addition to a password.'));
+ }
+
+ parent::validateForm($form, $form_state);
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::submitForm().
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ $this->configFactory->get('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();
+
+ parent::submitForm($form, $form_state);
+ }
+
+}
diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module
index c2d96d4..c0d8d42 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -47,12 +47,10 @@ function simpletest_menu() {
);
$items['admin/config/development/testing/settings'] = array(
'title' => 'Settings',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('simpletest_settings_form'),
+ 'route_name' => 'simpletest_settings',
'access arguments' => array('administer unit tests'),
'type' => MENU_LOCAL_TASK,
'weight' => 100,
- 'file' => 'simpletest.pages.inc',
);
$items['admin/config/development/testing/results/%'] = array(
'title' => 'Test result',
diff --git a/core/modules/simpletest/simpletest.pages.inc b/core/modules/simpletest/simpletest.pages.inc
index 61a4f82..4fb908d 100644
--- a/core/modules/simpletest/simpletest.pages.inc
+++ b/core/modules/simpletest/simpletest.pages.inc
@@ -430,100 +430,3 @@ function simpletest_result_status_image($status) {
}
return FALSE;
}
-
-/**
- * Provides settings form for SimpleTest variables.
- *
- * @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' => 'details',
- '#title' => t('General'),
- );
- $form['general']['simpletest_clear_results'] = array(
- '#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/results/[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' => $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' => $config->get('verbose'),
- );
-
- $form['httpauth'] = array(
- '#type' => 'details',
- '#title' => t('HTTP authentication'),
- '#description' => t('HTTP auth settings to be used by the SimpleTest browser during testing. Useful when the site requires basic HTTP authentication.'),
- '#collapsed' => TRUE,
- );
- $form['httpauth']['simpletest_httpauth_method'] = array(
- '#type' => 'select',
- '#title' => t('Method'),
- '#options' => array(
- CURLAUTH_BASIC => t('Basic'),
- CURLAUTH_DIGEST => t('Digest'),
- CURLAUTH_GSSNEGOTIATE => t('GSS negotiate'),
- CURLAUTH_NTLM => t('NTLM'),
- CURLAUTH_ANY => t('Any'),
- CURLAUTH_ANYSAFE => t('Any safe'),
- ),
- '#default_value' => $config->get('httpauth.method'),
- );
- $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 (!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(
- '#type' => 'password',
- '#title' => t('Password'),
- );
- if ($password) {
- $form['httpauth']['simpletest_httpauth_password']['#description'] = t('To change the password, enter the new password here.');
- }
-
- 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();
-}
-
-/**
- * Validation handler for simpletest_settings_form().
- */
-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'] = config('simpletest.settings')->get('httpauth.password');
- }
-
- // If a password was provided but a username wasn't, the credentials are
- // incorrect, so throw an error.
- if (empty($form_state['values']['simpletest_httpauth_username']) && !empty($form_state['values']['simpletest_httpauth_password'])) {
- form_set_error('simpletest_httpauth_username', t('HTTP authentication credentials must include a username in addition to a password.'));
- }
-}
-
diff --git a/core/modules/simpletest/simpletest.routing.yml b/core/modules/simpletest/simpletest.routing.yml
new file mode 100644
index 0000000..7a17bfd
--- /dev/null
+++ b/core/modules/simpletest/simpletest.routing.yml
@@ -0,0 +1,6 @@
+simpletest_settings:
+ pattern: '/admin/config/development/testing/settings'
+ defaults:
+ _form: 'Drupal\simpletest\Form\SimpletestSettingsForm'
+ requirements:
+ _permission: 'administer unit tests'