You are here

public function MobileNumberElementTest::submitFormElement in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/Tests/MobileNumberElementTest.php \Drupal\mobile_number\Tests\MobileNumberElementTest::submitFormElement()

Submit custom form.

1 call to MobileNumberElementTest::submitFormElement()
MobileNumberElementTest::testNumberValidity in src/Tests/MobileNumberElementTest.php
Test number validation.

File

src/Tests/MobileNumberElementTest.php, line 96

Class

MobileNumberElementTest
Mobile number form element functionality.

Namespace

Drupal\mobile_number\Tests

Code

public function submitFormElement($element, $input, $unset_verified_number = NULL) {
  if ($unset_verified_number) {
    $this->flood
      ->clear('mobile_number_verification', $unset_verified_number);
    unset($_SESSION['mobile_number_verification'][$unset_verified_number]['verified']);
  }
  $form_id = $this
    ->randomMachineName();
  $form_builder = \Drupal::formBuilder();
  $form = [];
  $form_state = new FormState();
  $form_state
    ->clearErrors();
  $form['op'] = [
    '#type' => 'submit',
    '#value' => t('Submit'),
  ];
  $form['mobile_number'] = $element;
  $form_state
    ->setUserInput([
    'mobile_number' => $input,
    'form_id' => $form_id,
  ]);
  $form_object = new PrepareCallbackTestForm();
  $form_state
    ->setFormObject($form_object);
  $form_state
    ->setCached(FALSE);
  $form_state
    ->setMethod('post');

  // The form token CSRF protection should not interfere with this test,
  // so we bypass it by marking this test form as programmed.
  $form_state
    ->setProgrammed(TRUE);
  $form_builder
    ->prepareForm($form_id, $form, $form_state);
  $form_builder
    ->processForm($form_id, $form, $form_state);
  return $form_state
    ->getErrors();
}