function FormAjaxSubscriberTest::testOnExceptionNewBuildId

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php \Drupal\Tests\Core\Form\EventSubscriber\FormAjaxSubscriberTest::testOnExceptionNewBuildId()
  2. 8.9.x core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php \Drupal\Tests\Core\Form\EventSubscriber\FormAjaxSubscriberTest::testOnExceptionNewBuildId()
  3. 11.x core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php \Drupal\Tests\Core\Form\EventSubscriber\FormAjaxSubscriberTest::testOnExceptionNewBuildId()

@covers ::onException

File

core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php, line 104

Class

FormAjaxSubscriberTest
@coversDefaultClass \Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber @group EventSubscriber

Namespace

Drupal\Tests\Core\Form\EventSubscriber

Code

public function testOnExceptionNewBuildId() : void {
    $form = [
        '#type' => 'form',
        '#build_id' => 'the_build_id',
    ];
    $expected_form = $form + [
        '#build_id_old' => 'a_new_build_id',
    ];
    $form_state = new FormState();
    $exception = new FormAjaxException($form, $form_state);
    $request = new Request([], [
        'form_build_id' => 'a_new_build_id',
    ]);
    $commands = [];
    $response = new Response('');
    $this->formAjaxResponseBuilder
        ->expects($this->once())
        ->method('buildResponse')
        ->with($request, $expected_form, $form_state, $commands)
        ->willReturn($response);
    $this->assertResponseFromException($request, $exception, $response);
    $this->assertTrue($this->event
        ->isAllowingCustomResponseCode());
    $this->assertSame(200, $this->event
        ->getResponse()
        ->getStatusCode());
}

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