You are here

public function TriggeringElementProgrammedTest::testLimitValidationErrors in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Form/TriggeringElementProgrammedTest.php \Drupal\KernelTests\Core\Form\TriggeringElementProgrammedTest::testLimitValidationErrors()

Tests that #limit_validation_errors of the only submit button takes effect.

File

core/tests/Drupal/KernelTests/Core/Form/TriggeringElementProgrammedTest.php, line 69

Class

TriggeringElementProgrammedTest
Tests detection of triggering_element for programmed form submissions.

Namespace

Drupal\KernelTests\Core\Form

Code

public function testLimitValidationErrors() {

  // Programmatically submit the form.
  $form_state = new FormState();
  $form_state
    ->setValue('section', 'one');
  $form_builder = $this->container
    ->get('form_builder');
  $form_builder
    ->submitForm($this, $form_state);

  // Verify that only the specified section was validated.
  $errors = $form_state
    ->getErrors();
  $this
    ->assertTrue(isset($errors['one']), "Section 'one' was validated.");
  $this
    ->assertFalse(isset($errors['two']), "Section 'two' was not validated.");

  // Verify that there are only values for the specified section.
  $this
    ->assertTrue($form_state
    ->hasValue('one'), "Values for section 'one' found.");
  $this
    ->assertFalse($form_state
    ->hasValue('two'), "Values for section 'two' not found.");
}