function RouterTest::testControllerResolutionAjax

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testControllerResolutionAjax()
  2. 8.9.x core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testControllerResolutionAjax()
  3. 11.x core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testControllerResolutionAjax()

Checks that an ajax request gets rendered as an Ajax response, by mime.

File

core/modules/system/tests/src/Functional/Routing/RouterTest.php, line 295

Class

RouterTest
Functional class for the full integrated routing system.

Namespace

Drupal\Tests\system\Functional\Routing

Code

public function testControllerResolutionAjax() : void {
    // This will fail with a JSON parse error if the request is not routed to
    // The correct controller.
    $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax';
    $headers = [
        'X-Requested-With' => 'XMLHttpRequest',
    ];
    $this->drupalGet('/router_test/test10', $options, $headers);
    $this->assertSession()
        ->responseHeaderEquals('Content-Type', 'application/json');
    $this->assertSession()
        ->pageTextContains('abcde');
}

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