You are here

public function SystemConfigFormTestBase::testConfigForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/System/SystemConfigFormTestBase.php \Drupal\system\Tests\System\SystemConfigFormTestBase::testConfigForm()

Submit the system_config_form ensure the configuration has expected values.

File

core/modules/system/src/Tests/System/SystemConfigFormTestBase.php, line 49
Contains \Drupal\system\Tests\System\SystemConfigFormTestBase.

Class

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

Namespace

Drupal\system\Tests\System

Code

public function testConfigForm() {

  // Programmatically submit the given values.
  $values = array();
  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 = array(
    '%values' => print_r($values, TRUE),
    '%errors' => $valid_form ? t('None') : implode(' ', $errors),
  );
  $this
    ->assertTrue($valid_form, format_string('Input values: %values<br/>Validation handler errors: %errors', $args));
  foreach ($this->values as $data) {
    $this
      ->assertEqual($data['#value'], $this
      ->config($data['#config_name'])
      ->get($data['#config_key']));
  }
}