Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for API\ResponseTrait::format() with format is not json or xml
Browse files Browse the repository at this point in the history
samsonasik committed Apr 3, 2020

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent ca3ed2f commit a1b9fdf
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
@@ -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 a1b9fdf

Please sign in to comment.