function RenderElementTest::testPreRenderAjaxFormWithQueryOptions

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php \Drupal\Tests\Core\Render\Element\RenderElementTest::testPreRenderAjaxFormWithQueryOptions()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php \Drupal\Tests\Core\Render\Element\RenderElementTest::testPreRenderAjaxFormWithQueryOptions()
  3. 11.x core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php \Drupal\Tests\Core\Render\Element\RenderElementTest::testPreRenderAjaxFormWithQueryOptions()

@covers ::preRenderAjaxForm

File

core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php, line 81

Class

RenderElementTest
@coversDefaultClass \Drupal\Core\Render\Element\RenderElementBase @group Render

Namespace

Drupal\Tests\Core\Render\Element

Code

public function testPreRenderAjaxFormWithQueryOptions() : void {
    $request = Request::create('/test');
    $request->query
        ->set('foo', 'bar');
    $this->requestStack
        ->push($request);
    $prophecy = $this->prophesize('Drupal\\Core\\Routing\\UrlGeneratorInterface');
    $url = '/test?foo=bar&other=query&ajax_form=1';
    $prophecy->generateFromRoute('<current>', [], [
        'query' => [
            'foo' => 'bar',
            'other' => 'query',
            FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
        ],
    ], TRUE)
        ->willReturn((new GeneratedUrl())->setCacheContexts([
        'route',
    ])
        ->setGeneratedUrl($url));
    $url_generator = $prophecy->reveal();
    $this->container
        ->set('url_generator', $url_generator);
    $element = [
        '#type' => 'select',
        '#id' => 'test',
        '#ajax' => [
            'wrapper' => 'foo',
            'callback' => 'test-callback',
            'options' => [
                'query' => [
                    'other' => 'query',
                ],
            ],
        ],
    ];
    $element = RenderElementBase::preRenderAjaxForm($element);
    $this->assertTrue($element['#ajax_processed']);
    $this->assertEquals($url, $element['#attached']['drupalSettings']['ajax']['test']['url']);
}

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