function NegotiationMiddlewareTest::testHandle

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php \Drupal\Tests\Core\StackMiddleware\NegotiationMiddlewareTest::testHandle()
  2. 8.9.x 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 92

Class

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

Namespace

Drupal\Tests\Core\StackMiddleware

Code

public function testHandle() : void {
    $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_mock = $request->reveal();
    $request_mock->query = new InputBag();
    $request_mock->request = new InputBag();
    // Calling kernel app with default arguments.
    $this->app
        ->handle($request_mock, HttpKernelInterface::MAIN_REQUEST, TRUE)
        ->shouldBeCalled()
        ->willReturn($this->createMock(Response::class));
    $this->contentNegotiation
        ->handle($request_mock);
    // Calling kernel app with specified arguments.
    $this->app
        ->handle($request_mock, HttpKernelInterface::SUB_REQUEST, FALSE)
        ->shouldBeCalled()
        ->willReturn($this->createMock(Response::class));
    $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.