You are here

function TriggeringElementProgrammedUnitTest::testLimitValidationErrors in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Form/TriggeringElementProgrammedUnitTest.php \Drupal\system\Tests\Form\TriggeringElementProgrammedUnitTest::testLimitValidationErrors()

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

File

core/modules/system/src/Tests/Form/TriggeringElementProgrammedUnitTest.php, line 76
Contains \Drupal\system\Tests\Form\TriggeringElementProgrammedUnitTest.

Class

TriggeringElementProgrammedUnitTest
Tests detection of triggering_element for programmed form submissions.

Namespace

Drupal\system\Tests\Form

Code

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.");
}