diff --git a/tests/system/API/ResponseTraitTest.php b/tests/system/API/ResponseTraitTest.php index beb905960091..b42c1d8ef70e 100644 --- a/tests/system/API/ResponseTraitTest.php +++ b/tests/system/API/ResponseTraitTest.php @@ -462,4 +462,44 @@ public function testXMLFormatter() $this->assertEquals($expected, $this->response->getBody()); } + public function testFormatByRequestNegotiateIfFormatIsNotJsonOrXML() + { + $config = [ + 'baseURL' => 'http://example.com', + 'uriProtocol' => 'REQUEST_URI', + 'defaultLocale' => 'en', + 'negotiateLocale' => false, + 'supportedLocales' => ['en'], + 'CSPEnabled' => false, + 'cookiePrefix' => '', + 'cookieDomain' => '', + 'cookiePath' => '/', + 'cookieSecure' => false, + 'cookieHTTPOnly' => false, + 'proxyIPs' => [], + ]; + + $request = new MockIncomingRequest((object) $config, new URI($config['baseURL']), null, new UserAgent()); + $response = new MockResponse((object) $config); + + $controller = new class($request, $response) + { + use ResponseTrait; + + protected $request; + protected $response; + + public function __construct(&$request, &$response) + { + $this->request = $request; + $this->response = $response; + + $this->format = 'txt'; + } + }; + + $controller->respondCreated(['id' => 3], 'A Custom Reason'); + $this->assertStringStartsWith(config('Format')->supportedResponseFormats[0], $response->getHeaderLine('Content-Type')); + } + }