function FormAjaxResponseBuilderTest::testBuildResponseRenderArray

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

@covers ::buildResponse

File

core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php, line 82

Class

FormAjaxResponseBuilderTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Form%21FormAjaxResponseBuilder.php/class/FormAjaxResponseBuilder/9" title="Builds an AJAX form response." class="local">\Drupal\Core\Form\FormAjaxResponseBuilder</a> @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testBuildResponseRenderArray() {
    $triggering_element = [
        '#ajax' => [
            'callback' => function (array $form, FormStateInterface $form_state) {
                return $form['test'];
            },
        ],
    ];
    $request = new Request();
    $form = [
        'test' => [
            '#type' => 'textfield',
        ],
    ];
    $form_state = new FormState();
    $form_state->setTriggeringElement($triggering_element);
    $commands = [];
    $this->renderer
        ->expects($this->once())
        ->method('renderResponse')
        ->with($form['test'], $request, $this->routeMatch)
        ->willReturn(new AjaxResponse([]));
    $result = $this->formAjaxResponseBuilder
        ->buildResponse($request, $form, $form_state, $commands);
    $this->assertInstanceOf('\\Drupal\\Core\\Ajax\\AjaxResponse', $result);
    $this->assertSame($commands, $result->getCommands());
}

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