function FormSubmitterTest::testExecuteSubmitHandlers

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

Tests execute submit handlers.

File

core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php, line 250

Class

FormSubmitterTest
Tests Drupal\Core\Form\FormSubmitter.

Namespace

Drupal\Tests\Core\Form

Code

public function testExecuteSubmitHandlers() : void {
  $form_submitter = $this->getFormSubmitter();
  $mock = $this->prophesize(MockFormBase::class);
  $mock->hash_submit(Argument::type('array'), Argument::type(FormStateInterface::class))
    ->shouldBeCalledOnce();
  $mock->submit_handler(Argument::type('array'), Argument::type(FormStateInterface::class))
    ->shouldBeCalledOnce();
  $mock->simple_string_submit(Argument::type('array'), Argument::type(FormStateInterface::class))
    ->shouldBeCalledOnce();
  $form = [];
  $form_state = new FormState();
  $form_submitter->executeSubmitHandlers($form, $form_state);
  $this->callableResolver
    ->method('getCallableFromDefinition')
    ->willReturn([
    $mock->reveal(),
    'hash_submit',
  ], [
    $mock->reveal(),
    'submit_handler',
  ], [
    $mock->reveal(),
    'simple_string_submit',
  ]);
  $form['#submit'][] = [
    $mock->reveal(),
    'hash_submit',
  ];
  $form_submitter->executeSubmitHandlers($form, $form_state);
  // $form_state submit handlers will supersede $form handlers.
  $form_state->setSubmitHandlers([
    [
      $mock->reveal(),
      'submit_handler',
    ],
  ]);
  $form_submitter->executeSubmitHandlers($form, $form_state);
  // Methods directly on the form object can be specified as a string.
  $form_state = (new FormState())->setFormObject($mock->reveal())
    ->setSubmitHandlers([
    '::simple_string_submit',
  ]);
  $form_submitter->executeSubmitHandlers($form, $form_state);
}

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