function TriggeringElementProgrammedTest::testLimitValidationErrors

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Form/TriggeringElementProgrammedTest.php \Drupal\KernelTests\Core\Form\TriggeringElementProgrammedTest::testLimitValidationErrors()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Form/TriggeringElementProgrammedTest.php \Drupal\KernelTests\Core\Form\TriggeringElementProgrammedTest::testLimitValidationErrors()
  3. 10 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 71

Class

TriggeringElementProgrammedTest
Tests detection of triggering_element for programmed form submissions.

Namespace

Drupal\KernelTests\Core\Form

Code

public function testLimitValidationErrors() : void {
    // 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.");
}

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