/**
  * Tests the 'must_validate' $form_state flag.
  *
  * @covers ::validateForm
  */
 public function testMustValidate()
 {
     $form_validator = $this->getMockBuilder('Drupal\\Core\\Form\\FormValidator')->setConstructorArgs([new RequestStack(), $this->getStringTranslationStub(), $this->csrfToken, $this->logger, $this->formErrorHandler])->setMethods(array('doValidateForm'))->getMock();
     $form_validator->expects($this->once())->method('doValidateForm');
     $this->formErrorHandler->expects($this->once())->method('handleFormErrors');
     $form = array();
     $form_state = (new FormState())->setValidationComplete()->setValidationEnforced();
     $form_validator->validateForm('test_form_id', $form, $form_state);
 }
Example #2
0
 /**
  * Finalizes validation.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param string $form_id
  *   The unique string identifying the form.
  */
 protected function finalizeValidation(&$form, FormStateInterface &$form_state, $form_id)
 {
     // Delegate handling of form errors to a service.
     $this->formErrorHandler->handleFormErrors($form, $form_state);
     // Mark this form as validated.
     $form_state->setValidationComplete();
 }