function FormBuilderTest::testGetAjaxRequest

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testGetAjaxRequest()

Tests get ajax request.

@legacy-covers ::buildForm

File

core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php, line 673

Class

FormBuilderTest
Tests Drupal\Core\Form\FormBuilder.

Namespace

Drupal\Tests\Core\Form

Code

public function testGetAjaxRequest() : void {
  $request = new Request([
    FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
  ]);
  $request->query
    ->set('form_id', 'different_form_id');
  $request->setMethod('GET');
  $request->setSession(new Session(new MockArraySessionStorage()));
  $this->requestStack
    ->push($request);
  $form_state = (new FormState())->setUserInput([
    FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
  ])
    ->setMethod('get')
    ->setAlwaysProcess()
    ->disableRedirect()
    ->set('ajax', TRUE);
  $form_id = '\\Drupal\\Tests\\Core\\Form\\TestForm';
  $expected_form = (new TestForm())->buildForm([], $form_state);
  $form = $this->formBuilder
    ->buildForm($form_id, $form_state);
  $this->assertFormElement($expected_form, $form, 'test');
  $this->assertSame('test-form', $form['#id']);
}

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