3 namespace Drupal\KernelTests;
5 use Drupal\Core\Form\FormState;
8 * Full generic test suite for any form that data with the configuration system.
10 * @see UserAdminSettingsFormTest
11 * For a full working implementation.
13 abstract class ConfigFormTestBase extends KernelTestBase {
15 * Form ID to use for testing.
17 * @var \Drupal\Core\Form\FormInterface
22 * Values to use for testing.
24 * Contains details for form key, configuration object name, and config key.
28 * 'user_mail_cancel_confirm_body' => array(
29 * '#value' => $this->randomString(),
30 * '#config_name' => 'user.mail',
31 * '#config_key' => 'cancel_confirm.body',
41 * Submit the system_config_form ensure the configuration has expected values.
43 public function testConfigForm() {
44 // Programmatically submit the given values.
46 foreach ($this->values as $form_key => $data) {
47 $values[$form_key] = $data['#value'];
49 $form_state = (new FormState())->setValues($values);
50 \Drupal::formBuilder()->submitForm($this->form, $form_state);
52 // Check that the form returns an error when expected, and vice versa.
53 $errors = $form_state->getErrors();
54 $valid_form = empty($errors);
56 '%values' => print_r($values, TRUE),
57 '%errors' => $valid_form ? t('None') : implode(' ', $errors),
59 $this->assertTrue($valid_form, format_string('Input values: %values<br/>Validation handler errors: %errors', $args));
61 foreach ($this->values as $data) {
62 $this->assertEqual($data['#value'], $this->config($data['#config_name'])->get($data['#config_key']));