function FormSubmitterTest::testExecuteSubmitHandlers

Same name in other branches
  1. 8.9.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. 11.x core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testExecuteSubmitHandlers()

@covers ::executeSubmitHandlers

File

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

Class

FormSubmitterTest
@coversDefaultClass \Drupal\Core\Form\FormSubmitter @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testExecuteSubmitHandlers() {
    $form_submitter = $this->getFormSubmitter();
    $mock = $this->getMockForAbstractClass('Drupal\\Core\\Form\\FormBase', [], '', TRUE, TRUE, TRUE, [
        'submit_handler',
        'hash_submit',
        'simple_string_submit',
    ]);
    $mock->expects($this->once())
        ->method('submit_handler')
        ->with($this->isType('array'), $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'));
    $mock->expects($this->once())
        ->method('hash_submit')
        ->with($this->isType('array'), $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'));
    $mock->expects($this->once())
        ->method('simple_string_submit')
        ->with($this->isType('array'), $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'));
    $form = [];
    $form_state = new FormState();
    $form_submitter->executeSubmitHandlers($form, $form_state);
    $form['#submit'][] = [
        $mock,
        'hash_submit',
    ];
    $form_submitter->executeSubmitHandlers($form, $form_state);
    // $form_state submit handlers will supersede $form handlers.
    $form_state->setSubmitHandlers([
        [
            $mock,
            '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)
        ->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.