3 namespace Drupal\system\Tests\System;
5 @trigger_error('\Drupal\system\Tests\System\SystemConfigFormTestBase is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal\KernelTests\ConfigFormTestBase instead.', E_USER_DEPRECATED);
7 use Drupal\Core\Form\FormState;
8 use Drupal\simpletest\WebTestBase;
11 * Full generic test suite for any form that data with the configuration system.
13 * @see UserAdminSettingsFormTest
14 * For a full working implementation.
16 * @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. Use
17 * \Drupal\KernelTests\ConfigFormTestBase instead.
19 * @see https://www.drupal.org/node/2941907
21 abstract class SystemConfigFormTestBase extends WebTestBase {
23 * Form ID to use for testing.
25 * @var \Drupal\Core\Form\FormInterface
30 * Values to use for testing.
32 * Contains details for form key, configuration object name, and config key.
36 * 'user_mail_cancel_confirm_body' => array(
37 * '#value' => $this->randomString(),
38 * '#config_name' => 'user.mail',
39 * '#config_key' => 'cancel_confirm.body',
49 * Submit the system_config_form ensure the configuration has expected values.
51 public function testConfigForm() {
52 // Programmatically submit the given values.
54 foreach ($this->values as $form_key => $data) {
55 $values[$form_key] = $data['#value'];
57 $form_state = (new FormState())->setValues($values);
58 \Drupal::formBuilder()->submitForm($this->form, $form_state);
60 // Check that the form returns an error when expected, and vice versa.
61 $errors = $form_state->getErrors();
62 $valid_form = empty($errors);
64 '%values' => print_r($values, TRUE),
65 '%errors' => $valid_form ? t('None') : implode(' ', $errors),
67 $this->assertTrue($valid_form, format_string('Input values: %values<br/>Validation handler errors: %errors', $args));
69 foreach ($this->values as $data) {
70 $this->assertEqual($data['#value'], $this->config($data['#config_name'])->get($data['#config_key']));