You are here

private function ElementsTableSelectTest::formSubmitHelper in Zircon Profile 8

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

Helper function for the option check test to submit a form while collecting errors.

Parameters

$form_element: A form element to test.

$edit: An array containing post data.

Return value

An array containing the processed form, the form_state and any errors.

2 calls to ElementsTableSelectTest::formSubmitHelper()
ElementsTableSelectTest::testMultipleFalseOptionchecker in core/modules/system/src/Tests/Form/ElementsTableSelectTest.php
Test the whether the option checker gives an error on invalid tableselect values for radios.
ElementsTableSelectTest::testMultipleTrueOptionchecker in core/modules/system/src/Tests/Form/ElementsTableSelectTest.php
Test the whether the option checker gives an error on invalid tableselect values for checkboxes.

File

core/modules/system/src/Tests/Form/ElementsTableSelectTest.php, line 209
Contains \Drupal\system\Tests\Form\ElementsTableSelectTest.

Class

ElementsTableSelectTest
Tests the tableselect form element for expected behavior.

Namespace

Drupal\system\Tests\Form

Code

private function formSubmitHelper($form, $edit) {
  $form_id = $this
    ->randomMachineName();
  $form_state = new FormState();
  $form['op'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  // The form token CSRF protection should not interfere with this test, so we
  // bypass it by setting the token to FALSE.
  $form['#token'] = FALSE;
  $edit['form_id'] = $form_id;

  // Disable page redirect for forms submitted programmatically. This is a
  // solution to skip the redirect step (there are no pages, then the redirect
  // isn't possible).
  $form_state
    ->disableRedirect();
  $form_state
    ->setUserInput($edit);
  $form_state
    ->setFormObject(new StubForm($form_id, $form));
  \Drupal::formBuilder()
    ->prepareForm($form_id, $form, $form_state);
  \Drupal::formBuilder()
    ->processForm($form_id, $form, $form_state);
  $errors = $form_state
    ->getErrors();

  // Clear errors and messages.
  drupal_get_messages();
  $form_state
    ->clearErrors();

  // Return the processed form together with form_state and errors
  // to allow the caller lowlevel access to the form.
  return array(
    $form,
    $form_state,
    $errors,
  );
}