public function FormValidatorTest::testExecuteValidateHandlers in Drupal 8
Same name and namespace in other branches
- 9 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 268
Class
- FormValidatorTest
- @coversDefaultClass \Drupal\Core\Form\FormValidator @group Form
Namespace
Drupal\Tests\Core\FormCode
public function testExecuteValidateHandlers() {
$form_validator = $this
->getMockBuilder('Drupal\\Core\\Form\\FormValidator')
->setConstructorArgs([
new RequestStack(),
$this
->getStringTranslationStub(),
$this->csrfToken,
$this->logger,
$this->formErrorHandler,
])
->setMethods(NULL)
->getMock();
$mock = $this
->getMockBuilder('stdClass')
->setMethods([
'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);
}