function NegotiationMiddlewareTest::testSetFormat

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

@covers ::registerFormat

File

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

Class

NegotiationMiddlewareTest
@coversDefaultClass \Drupal\Core\StackMiddleware\NegotiationMiddleware[[api-linebreak]] @group NegotiationMiddleware

Namespace

Drupal\Tests\Core\StackMiddleware

Code

public function testSetFormat() : void {
  $app = $this->createMock(HttpKernelInterface::class);
  $app->expects($this->once())
    ->method('handle')
    ->willReturn($this->createMock(Response::class));
  $content_negotiation = new StubNegotiationMiddleware($app);
  $request = $this->prophesize(Request::class);
  // Default empty format list should not set any formats.
  $request->setFormat('david', 'geeky/david')
    ->shouldBeCalled();
  // Some calls we don't care about.
  $request->setRequestFormat()
    ->shouldNotBeCalled();
  $request_mock = $request->reveal();
  $request_mock->query = new InputBag();
  $request_mock->request = new InputBag();
  // Trigger handle.
  $content_negotiation->registerFormat('david', 'geeky/david');
  $content_negotiation->handle($request_mock);
}

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