Commit d6693eb3 authored by webchick's avatar webchick
Browse files

Issue #2072323 by tim.plunkett: Modernize simpletest.module forms.

parent e6b87efa
...@@ -7,16 +7,15 @@ ...@@ -7,16 +7,15 @@
namespace Drupal\simpletest\Form; namespace Drupal\simpletest\Form;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormBase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
/** /**
* Test results form for $test_id. * Test results form for $test_id.
*/ */
class SimpletestResultsForm implements FormInterface, ControllerInterface { class SimpletestResultsForm extends FormBase {
/** /**
* Associative array of themed result images keyed by status. * Associative array of themed result images keyed by status.
...@@ -53,28 +52,28 @@ public function __construct(Connection $database) { ...@@ -53,28 +52,28 @@ public function __construct(Connection $database) {
'#uri' => 'core/misc/watchdog-ok.png', '#uri' => 'core/misc/watchdog-ok.png',
'#width' => 18, '#width' => 18,
'#height' => 18, '#height' => 18,
'#alt' => t('Pass'), '#alt' => $this->t('Pass'),
); );
$image_fail = array( $image_fail = array(
'#theme' => 'image', '#theme' => 'image',
'#uri' => 'core/misc/watchdog-error.png', '#uri' => 'core/misc/watchdog-error.png',
'#width' => 18, '#width' => 18,
'#height' => 18, '#height' => 18,
'#alt' => t('Fail'), '#alt' => $this->t('Fail'),
); );
$image_exception = array( $image_exception = array(
'#theme' => 'image', '#theme' => 'image',
'#uri' => 'core/misc/watchdog-warning.png', '#uri' => 'core/misc/watchdog-warning.png',
'#width' => 18, '#width' => 18,
'#height' => 18, '#height' => 18,
'#alt' => t('Exception'), '#alt' => $this->t('Exception'),
); );
$image_debug = array( $image_debug = array(
'#theme' => 'image', '#theme' => 'image',
'#uri' => 'core/misc/watchdog-warning.png', '#uri' => 'core/misc/watchdog-warning.png',
'#width' => 18, '#width' => 18,
'#height' => 18, '#height' => 18,
'#alt' => t('Debug'), '#alt' => $this->t('Debug'),
); );
$this->statusImageMap = array( $this->statusImageMap = array(
'pass' => drupal_render($image_pass), 'pass' => drupal_render($image_pass),
...@@ -100,7 +99,7 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) { ...@@ -100,7 +99,7 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) {
$results = array(); $results = array();
if (is_numeric($test_id) && !$results = $this->getResults($test_id)) { if (is_numeric($test_id) && !$results = $this->getResults($test_id)) {
drupal_set_message(t('No test results to display.'), 'error'); drupal_set_message($this->t('No test results to display.'), 'error');
return new RedirectResponse(url('admin/config/development/testing', array('absolute' => TRUE))); return new RedirectResponse(url('admin/config/development/testing', array('absolute' => TRUE)));
} }
...@@ -116,7 +115,7 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) { ...@@ -116,7 +115,7 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) {
// Summary result widget. // Summary result widget.
$form['result'] = array( $form['result'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Results'), '#title' => $this->t('Results'),
); );
$form['result']['summary'] = $summary = array( $form['result']['summary'] = $summary = array(
'#theme' => 'simpletest_result_summary', '#theme' => 'simpletest_result_summary',
...@@ -130,12 +129,12 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) { ...@@ -130,12 +129,12 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) {
// Cycle through each test group. // Cycle through each test group.
$header = array( $header = array(
t('Message'), $this->t('Message'),
t('Group'), $this->t('Group'),
t('Filename'), $this->t('Filename'),
t('Line'), $this->t('Line'),
t('Function'), $this->t('Function'),
array('colspan' => 2, 'data' => t('Status')) array('colspan' => 2, 'data' => $this->t('Status'))
); );
$form['result']['results'] = array(); $form['result']['results'] = array();
foreach ($results as $group => $assertions) { foreach ($results as $group => $assertions) {
...@@ -183,14 +182,14 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) { ...@@ -183,14 +182,14 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) {
$filter[$group_summary['#ok'] ? 'pass' : 'fail'][] = $group; $filter[$group_summary['#ok'] ? 'pass' : 'fail'][] = $group;
} }
// Overal summary status. // Overall summary status.
$form['result']['summary']['#ok'] = $form['result']['summary']['#fail'] + $form['result']['summary']['#exception'] == 0; $form['result']['summary']['#ok'] = $form['result']['summary']['#fail'] + $form['result']['summary']['#exception'] == 0;
// Actions. // Actions.
$form['#action'] = url('admin/config/development/testing/results/re-run'); $form['#action'] = url('admin/config/development/testing/results/re-run');
$form['action'] = array( $form['action'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Actions'), '#title' => $this->t('Actions'),
'#attributes' => array('class' => array('container-inline')), '#attributes' => array('class' => array('container-inline')),
'#weight' => -11, '#weight' => -11,
); );
...@@ -199,9 +198,9 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) { ...@@ -199,9 +198,9 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) {
'#type' => 'select', '#type' => 'select',
'#title' => 'Filter', '#title' => 'Filter',
'#options' => array( '#options' => array(
'all' => t('All (@count)', array('@count' => count($filter['pass']) + count($filter['fail']))), 'all' => $this->t('All (@count)', array('@count' => count($filter['pass']) + count($filter['fail']))),
'pass' => t('Pass (@count)', array('@count' => count($filter['pass']))), 'pass' => $this->t('Pass (@count)', array('@count' => count($filter['pass']))),
'fail' => t('Fail (@count)', array('@count' => count($filter['fail']))), 'fail' => $this->t('Fail (@count)', array('@count' => count($filter['fail']))),
), ),
); );
$form['action']['filter']['#default_value'] = ($filter['fail'] ? 'fail' : 'all'); $form['action']['filter']['#default_value'] = ($filter['fail'] ? 'fail' : 'all');
...@@ -218,12 +217,12 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) { ...@@ -218,12 +217,12 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) {
$form['action']['op'] = array( $form['action']['op'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Run tests'), '#value' => $this->t('Run tests'),
); );
$form['action']['return'] = array( $form['action']['return'] = array(
'#type' => 'link', '#type' => 'link',
'#title' => t('Return to list'), '#title' => $this->t('Return to list'),
'#href' => 'admin/config/development/testing', '#href' => 'admin/config/development/testing',
); );
...@@ -234,12 +233,6 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) { ...@@ -234,12 +233,6 @@ public function buildForm(array $form, array &$form_state, $test_id = NULL) {
return $form; return $form;
} }
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\simpletest\Form\SimpletestSettingsForm. * Contains \Drupal\simpletest\Form\SimpletestSettingsForm.
...@@ -14,50 +15,50 @@ ...@@ -14,50 +15,50 @@
class SimpletestSettingsForm extends SystemConfigFormBase { class SimpletestSettingsForm extends SystemConfigFormBase {
/** /**
* Implements \Drupal\Core\Form\FormInterface::getFormID(). * {@inheritdoc}
*/ */
public function getFormID() { public function getFormID() {
return 'simpletest_settings_form'; return 'simpletest_settings_form';
} }
/** /**
* Implements \Drupal\Core\Form\FormInterface::buildForm(). * {@inheritdoc}
*/ */
public function buildForm(array $form, array &$form_state) { public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('simpletest.settings'); $config = $this->configFactory->get('simpletest.settings');
$form['general'] = array( $form['general'] = array(
'#type' => 'details', '#type' => 'details',
'#title' => t('General'), '#title' => $this->t('General'),
); );
$form['general']['simpletest_clear_results'] = array( $form['general']['simpletest_clear_results'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Clear results after each complete test suite run'), '#title' => $this->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.'), '#description' => $this->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'), '#default_value' => $config->get('clear_results'),
); );
$form['general']['simpletest_verbose'] = array( $form['general']['simpletest_verbose'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Provide verbose information when running tests'), '#title' => $this->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.'), '#description' => $this->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'), '#default_value' => $config->get('verbose'),
); );
$form['httpauth'] = array( $form['httpauth'] = array(
'#type' => 'details', '#type' => 'details',
'#title' => t('HTTP authentication'), '#title' => $this->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.'), '#description' => $this->t('HTTP auth settings to be used by the SimpleTest browser during testing. Useful when the site requires basic HTTP authentication.'),
'#collapsed' => TRUE, '#collapsed' => TRUE,
); );
$form['httpauth']['simpletest_httpauth_method'] = array( $form['httpauth']['simpletest_httpauth_method'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Method'), '#title' => $this->t('Method'),
'#options' => array( '#options' => array(
CURLAUTH_BASIC => t('Basic'), CURLAUTH_BASIC => $this->t('Basic'),
CURLAUTH_DIGEST => t('Digest'), CURLAUTH_DIGEST => $this->t('Digest'),
CURLAUTH_GSSNEGOTIATE => t('GSS negotiate'), CURLAUTH_GSSNEGOTIATE => $this->t('GSS negotiate'),
CURLAUTH_NTLM => t('NTLM'), CURLAUTH_NTLM => $this->t('NTLM'),
CURLAUTH_ANY => t('Any'), CURLAUTH_ANY => $this->t('Any'),
CURLAUTH_ANYSAFE => t('Any safe'), CURLAUTH_ANYSAFE => $this->t('Any safe'),
), ),
'#default_value' => $config->get('httpauth.method'), '#default_value' => $config->get('httpauth.method'),
); );
...@@ -65,25 +66,25 @@ public function buildForm(array $form, array &$form_state) { ...@@ -65,25 +66,25 @@ public function buildForm(array $form, array &$form_state) {
$password = $config->get('httpauth.password'); $password = $config->get('httpauth.password');
$form['httpauth']['simpletest_httpauth_username'] = array( $form['httpauth']['simpletest_httpauth_username'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Username'), '#title' => $this->t('Username'),
'#default_value' => $username, '#default_value' => $username,
); );
if (!empty($username) && !empty($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_username']['#description'] = $this->t('Leave this blank to delete both the existing username and password.');
} }
$form['httpauth']['simpletest_httpauth_password'] = array( $form['httpauth']['simpletest_httpauth_password'] = array(
'#type' => 'password', '#type' => 'password',
'#title' => t('Password'), '#title' => $this->t('Password'),
); );
if ($password) { if ($password) {
$form['httpauth']['simpletest_httpauth_password']['#description'] = t('To change the password, enter the new password here.'); $form['httpauth']['simpletest_httpauth_password']['#description'] = $this->t('To change the password, enter the new password here.');
} }
return parent::buildForm($form, $form_state); return parent::buildForm($form, $form_state);
} }
/** /**
* Implements \Drupal\Core\Form\FormInterface::validateForm(). * {@inheritdoc}
*/ */
public function validateForm(array &$form, array &$form_state) { public function validateForm(array &$form, array &$form_state) {
$config = $this->configFactory->get('simpletest.settings'); $config = $this->configFactory->get('simpletest.settings');
...@@ -96,14 +97,14 @@ public function validateForm(array &$form, array &$form_state) { ...@@ -96,14 +97,14 @@ public function validateForm(array &$form, array &$form_state) {
// If a password was provided but a username wasn't, the credentials are // If a password was provided but a username wasn't, the credentials are
// incorrect, so throw an error. // incorrect, so throw an error.
if (empty($form_state['values']['simpletest_httpauth_username']) && !empty($form_state['values']['simpletest_httpauth_password'])) { 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.')); form_set_error('simpletest_httpauth_username', $this->t('HTTP authentication credentials must include a username in addition to a password.'));
} }
parent::validateForm($form, $form_state); parent::validateForm($form, $form_state);
} }
/** /**
* Implements \Drupal\Core\Form\FormInterface::submitForm(). * {@inheritdoc}
*/ */
public function submitForm(array &$form, array &$form_state) { public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('simpletest.settings') $this->configFactory->get('simpletest.settings')
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
namespace Drupal\simpletest\Form; namespace Drupal\simpletest\Form;
use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormBase;
/** /**
* List tests arranged in groups that can be selected and run. * List tests arranged in groups that can be selected and run.
*/ */
class SimpletestTestForm implements FormInterface { class SimpletestTestForm extends FormBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -34,21 +34,21 @@ public function buildForm(array $form, array &$form_state) { ...@@ -34,21 +34,21 @@ public function buildForm(array $form, array &$form_state) {
); );
$form['filters']['text'] = array( $form['filters']['text'] = array(
'#type' => 'search', '#type' => 'search',
'#title' => t('Search'), '#title' => $this->t('Search'),
'#size' => 30, '#size' => 30,
'#placeholder' => t('Enter test name…'), '#placeholder' => $this->t('Enter test name…'),
'#attributes' => array( '#attributes' => array(
'class' => array('table-filter-text'), 'class' => array('table-filter-text'),
'data-table' => '#simpletest-test-form', 'data-table' => '#simpletest-test-form',
'autocomplete' => 'off', 'autocomplete' => 'off',
'title' => t('Enter at least 3 characters of the test name or description to filter by.'), 'title' => $this->t('Enter at least 3 characters of the test name or description to filter by.'),
), ),
); );
$form['tests'] = array( $form['tests'] = array(
'#type' => 'details', '#type' => 'details',
'#title' => t('Tests'), '#title' => $this->t('Tests'),
'#description' => t('Select the test(s) or test group(s) you would like to run, and click <em>Run tests</em>.'), '#description' => $this->t('Select the test(s) or test group(s) you would like to run, and click <em>Run tests</em>.'),
); );
$form['tests']['table'] = array( $form['tests']['table'] = array(
...@@ -77,16 +77,16 @@ public function buildForm(array $form, array &$form_state) { ...@@ -77,16 +77,16 @@ public function buildForm(array $form, array &$form_state) {
// Action buttons. // Action buttons.
$form['tests']['op'] = array( $form['tests']['op'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Run tests'), '#value' => $this->t('Run tests'),
); );
$form['clean'] = array( $form['clean'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Clean test environment'), '#title' => $this->t('Clean test environment'),
'#description' => t('Remove tables with the prefix "simpletest" and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'), '#description' => $this->t('Remove tables with the prefix "simpletest" and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),
); );
$form['clean']['op'] = array( $form['clean']['op'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Clean environment'), '#value' => $this->t('Clean environment'),
'#submit' => array('simpletest_clean_environment'), '#submit' => array('simpletest_clean_environment'),
); );
...@@ -122,7 +122,7 @@ public function submitForm(array &$form, array &$form_state) { ...@@ -122,7 +122,7 @@ public function submitForm(array &$form, array &$form_state) {
$form_state['redirect'] = 'admin/config/development/testing/results/' . $test_id; $form_state['redirect'] = 'admin/config/development/testing/results/' . $test_id;
} }
else { else {
drupal_set_message(t('No test(s) selected.'), 'error'); drupal_set_message($this->t('No test(s) selected.'), 'error');
} }
} }
......
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