Skip to content

Commit

Permalink
Merge pull request #2793 from samsonasik/test-response-trait-negotiate
Browse files Browse the repository at this point in the history
test for API\ResponseTrait::format() with format is not json or xml
  • Loading branch information
MGatner authored Apr 15, 2020
2 parents 5f7906e + bd2282c commit 611d3bb
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 @@ -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'));
}

}

0 comments on commit 611d3bb

Please sign in to comment.