function ConfigFormTestBase::testConfigForm

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/ConfigFormTestBase.php \Drupal\KernelTests\ConfigFormTestBase::testConfigForm()
  2. 10 core/tests/Drupal/KernelTests/ConfigFormTestBase.php \Drupal\KernelTests\ConfigFormTestBase::testConfigForm()
  3. 11.x core/tests/Drupal/KernelTests/ConfigFormTestBase.php \Drupal\KernelTests\ConfigFormTestBase::testConfigForm()

Submit the system_config_form ensure the configuration has expected values.

File

core/tests/Drupal/KernelTests/ConfigFormTestBase.php, line 44

Class

ConfigFormTestBase
Full generic test suite for any form that data with the configuration system.

Namespace

Drupal\KernelTests

Code

public function testConfigForm() {
    // Programmatically submit the given values.
    $values = [];
    foreach ($this->values as $form_key => $data) {
        $values[$form_key] = $data['#value'];
    }
    $form_state = (new FormState())->setValues($values);
    \Drupal::formBuilder()->submitForm($this->form, $form_state);
    // Check that the form returns an error when expected, and vice versa.
    $errors = $form_state->getErrors();
    $valid_form = empty($errors);
    $args = [
        '%values' => print_r($values, TRUE),
        '%errors' => $valid_form ? t('None') : implode(' ', $errors),
    ];
    $this->assertTrue($valid_form, new FormattableMarkup('Input values: %values<br/>Validation handler errors: %errors', $args));
    foreach ($this->values as $data) {
        $this->assertEquals($this->config($data['#config_name'])
            ->get($data['#config_key']), $data['#value']);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.