function NegotiationMiddlewareTest::testHandle

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php \Drupal\Tests\Core\StackMiddleware\NegotiationMiddlewareTest::testHandle()
  2. 10 core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php \Drupal\Tests\Core\StackMiddleware\NegotiationMiddlewareTest::testHandle()
  3. 11.x core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php \Drupal\Tests\Core\StackMiddleware\NegotiationMiddlewareTest::testHandle()

Tests that handle() correctly hands off to sub application.

@covers ::handle

File

core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php, line 95

Class

NegotiationMiddlewareTest
@coversDefaultClass \Drupal\Core\StackMiddleware\NegotiationMiddleware @group NegotiationMiddleware

Namespace

Drupal\Tests\Core\StackMiddleware

Code

public function testHandle() {
    $request = $this->prophesize(Request::class);
    // Default empty format list should not set any formats.
    $request->setFormat()
        ->shouldNotBeCalled();
    // Request format will be set with default format.
    $request->setRequestFormat()
        ->shouldNotBeCalled();
    // Some getContentType calls we don't really care about but have to mock.
    $request_data = $this->prophesize(ParameterBag::class);
    $request_data->get('ajax_iframe_upload', FALSE)
        ->shouldBeCalled();
    $request_mock = $request->reveal();
    $request_mock->query = new ParameterBag([]);
    $request_mock->request = $request_data->reveal();
    // Calling kernel app with default arguments.
    $this->app
        ->handle($request_mock, HttpKernelInterface::MASTER_REQUEST, TRUE)
        ->shouldBeCalled();
    $this->contentNegotiation
        ->handle($request_mock);
    // Calling kernel app with specified arguments.
    $this->app
        ->handle($request_mock, HttpKernelInterface::SUB_REQUEST, FALSE)
        ->shouldBeCalled();
    $this->contentNegotiation
        ->handle($request_mock, HttpKernelInterface::SUB_REQUEST, FALSE);
}

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