You are here

public function FormAjaxSubscriberTest::testOnExceptionNestedException in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php \Drupal\Tests\Core\Form\EventSubscriber\FormAjaxSubscriberTest::testOnExceptionNestedException()
  2. 9 core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php \Drupal\Tests\Core\Form\EventSubscriber\FormAjaxSubscriberTest::testOnExceptionNestedException()

@covers ::onException @covers ::getFormAjaxException

File

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

Class

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

Namespace

Drupal\Tests\Core\Form\EventSubscriber

Code

public function testOnExceptionNestedException() {
  $form = [
    '#type' => 'form',
    '#build_id' => 'the_build_id',
  ];
  $expected_form = $form + [
    '#build_id_old' => 'the_build_id',
  ];
  $form_state = new FormState();
  $form_exception = new FormAjaxException($form, $form_state);
  $exception = new \Exception('', 0, $form_exception);
  $request = new Request([], [
    'form_build_id' => 'the_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);
}