public function HttpPurgerConfigFormTestBase::testFormValidation in Generic HTTP Purger 8
Test validating the data.
File
- tests/
src/ Functional/ HttpPurgerConfigFormTestBase.php, line 80
Class
- HttpPurgerConfigFormTestBase
- Testbase for testing \Drupal\purge_purger_http\Form\HttpPurgerFormBase.
Namespace
Drupal\Tests\purge_purger_http\FunctionalCode
public function testFormValidation() : void {
// Assert that valid timeout values don't cause validation errors.
$form_state = $this
->getFormStateInstance();
$form_state
->addBuildInfo('args', $this->formArgs);
$form_state
->setValues([
'connect_timeout' => 0.3,
'timeout' => 0.1,
'name' => 'foobar',
]);
$form = $this
->getFormInstance();
$this
->formBuilder()
->submitForm($form, $form_state);
$this
->assertEquals(0, count($form_state
->getErrors()));
$form_state = $this
->getFormStateInstance();
$form_state
->addBuildInfo('args', $this->formArgs);
$form_state
->setValues([
'connect_timeout' => 2.3,
'timeout' => 7.7,
'name' => 'foobar',
]);
$form = $this
->getFormInstance();
$this
->formBuilder()
->submitForm($form, $form_state);
$this
->assertEquals(0, count($form_state
->getErrors()));
// Submit timeout values that are too low and confirm the validation error.
$form_state = $this
->getFormStateInstance();
$form_state
->addBuildInfo('args', $this->formArgs);
$form_state
->setValues([
'connect_timeout' => 0.0,
'timeout' => 0.0,
'name' => 'foobar',
]);
$form = $this
->getFormInstance();
$this
->formBuilder()
->submitForm($form, $form_state);
$errors = $form_state
->getErrors();
$this
->assertEquals(2, count($errors));
$this
->assertTrue(isset($errors['timeout']));
$this
->assertTrue(isset($errors['connect_timeout']));
// Submit timeout values that are too high and confirm the validation error.
$form_state = $this
->getFormStateInstance();
$form_state
->addBuildInfo('args', $this->formArgs);
$form_state
->setValues([
'connect_timeout' => 2.4,
'timeout' => 7.7,
'name' => 'foobar',
]);
$form = $this
->getFormInstance();
$this
->formBuilder()
->submitForm($form, $form_state);
$errors = $form_state
->getErrors();
$this
->assertEquals(2, count($errors));
$this
->assertTrue(isset($errors['timeout']));
$this
->assertTrue(isset($errors['connect_timeout']));
}