Skip to content

Commit

Permalink
test for API\ResponseTrait::format() with format is not json or xml
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 7, 2020
1 parent c3e545d commit f7dd47f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

}

0 comments on commit f7dd47f

Please sign in to comment.