function FormValidatorTest::testExecuteValidateHandlers

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php \Drupal\Tests\Core\Form\FormValidatorTest::testExecuteValidateHandlers()
  2. 10 core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php \Drupal\Tests\Core\Form\FormValidatorTest::testExecuteValidateHandlers()
  3. 11.x core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php \Drupal\Tests\Core\Form\FormValidatorTest::testExecuteValidateHandlers()

@covers ::executeValidateHandlers

File

core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php, line 263

Class

FormValidatorTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Form%21FormValidator.php/class/FormValidator/9" title="Provides validation of form submissions." class="local">\Drupal\Core\Form\FormValidator</a> @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testExecuteValidateHandlers() {
    $form_validator = new FormValidator(new RequestStack(), $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $this->formErrorHandler);
    $mock = $this->getMockBuilder('stdClass')
        ->addMethods([
        'validate_handler',
        'hash_validate',
    ])
        ->getMock();
    $mock->expects($this->once())
        ->method('validate_handler')
        ->with($this->isType('array'), $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'));
    $mock->expects($this->once())
        ->method('hash_validate')
        ->with($this->isType('array'), $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'));
    $form = [];
    $form_state = new FormState();
    $form_validator->executeValidateHandlers($form, $form_state);
    $form['#validate'][] = [
        $mock,
        'hash_validate',
    ];
    $form_validator->executeValidateHandlers($form, $form_state);
    // $form_state validate handlers will supersede $form handlers.
    $validate_handlers[] = [
        $mock,
        'validate_handler',
    ];
    $form_state->setValidateHandlers($validate_handlers);
    $form_validator->executeValidateHandlers($form, $form_state);
}

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