You are here

public function NegotiationMiddlewareTest::testSetFormat in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php \Drupal\Tests\Core\StackMiddleware\NegotiationMiddlewareTest::testSetFormat()
  2. 9 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 130
Contains \Drupal\Tests\Core\StackMiddleware\NegotiationMiddlewareTest.

Class

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

Namespace

Drupal\Tests\Core\StackMiddleware

Code

public function testSetFormat() {
  $app = $this
    ->createMock(HttpKernelInterface::class);
  $app
    ->expects($this
    ->once())
    ->method('handle')
    ->will($this
    ->returnValue($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_data = $this
    ->prophesize(ParameterBag::class);
  $request_data
    ->get('ajax_iframe_upload', FALSE)
    ->willReturn(FALSE)
    ->shouldBeCalled();
  $request_mock = $request
    ->reveal();
  $request_mock->query = new ParameterBag([]);
  $request_mock->request = $request_data
    ->reveal();

  // Trigger handle.
  $content_negotiation
    ->registerFormat('david', 'geeky/david');
  $content_negotiation
    ->handle($request_mock);
}