From a1b9fdf2cd4d915414e087001e256e24919e9b67 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 3 Apr 2020 16:10:18 +0700 Subject: [PATCH] test for API\ResponseTrait::format() with format is not json or xml --- tests/system/API/ResponseTraitTest.php | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/system/API/ResponseTraitTest.php b/tests/system/API/ResponseTraitTest.php index c081caf17481..6a72a795e565 100644 --- a/tests/system/API/ResponseTraitTest.php +++ b/tests/system/API/ResponseTraitTest.php @@ -452,4 +452,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('application/json; charset=UTF-8', $response->getHeaderLine('Content-Type')); + } + }