ConfigFormTestBase.php in Drupal 9
File
core/tests/Drupal/KernelTests/ConfigFormTestBase.php
View source
<?php
namespace Drupal\KernelTests;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Form\FormState;
abstract class ConfigFormTestBase extends KernelTestBase {
protected $form;
protected $values;
public function testConfigForm() {
$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);
$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']);
}
}
}
Classes
Name |
Description |
ConfigFormTestBase |
Full generic test suite for any form that data with the configuration system. |