mirror of
https://github.com/friendica/friendica
synced 2025-05-10 17:04:09 +02:00
Remove dependency on super-globals in Module\Api\ApiResponse
- Updated DI dependencies to reflect the new parameters - Updated tests to reflect the new parameters
This commit is contained in:
parent
d165a96220
commit
960171c4e0
3 changed files with 85 additions and 8 deletions
|
@ -127,7 +127,30 @@ class ApiResponseTest extends MockedTest
|
|||
$baseUrl = \Mockery::mock(BaseURL::class);
|
||||
$twitterUser = \Mockery::mock(User::class);
|
||||
|
||||
$response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
|
||||
$logger = \Mockery::mock(NullLogger::class);
|
||||
$logger->shouldReceive('info')->withArgs(['Unimplemented API call', ['method' => 'all', 'path' => '', 'agent' => '', 'request' => []]]);
|
||||
|
||||
$response = new ApiResponse($l10n, $args, $logger, $baseUrl, $twitterUser);
|
||||
$response->unsupported();
|
||||
|
||||
self::assertEquals('{"error":"API endpoint %s %s is not implemented but might be in the future.","code":"501 Not Implemented","request":""}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testUnsupportedUserAgent()
|
||||
{
|
||||
$l10n = \Mockery::mock(L10n::class);
|
||||
$l10n->shouldReceive('t')->andReturnUsing(function ($args) {
|
||||
return $args;
|
||||
});
|
||||
$args = \Mockery::mock(Arguments::class);
|
||||
$args->shouldReceive('getQueryString')->andReturn('');
|
||||
$baseUrl = \Mockery::mock(BaseURL::class);
|
||||
$twitterUser = \Mockery::mock(User::class);
|
||||
|
||||
$logger = \Mockery::mock(NullLogger::class);
|
||||
$logger->shouldReceive('info')->withArgs(['Unimplemented API call', ['method' => 'all', 'path' => '', 'agent' => 'PHPUnit', 'request' => []]]);
|
||||
|
||||
$response = new ApiResponse($l10n, $args, $logger, $baseUrl, $twitterUser, ['HTTP_USER_AGENT' => 'PHPUnit']);
|
||||
$response->unsupported();
|
||||
|
||||
self::assertEquals('{"error":"API endpoint %s %s is not implemented but might be in the future.","code":"501 Not Implemented","request":""}', $response->getContent());
|
||||
|
@ -250,6 +273,40 @@ class ApiResponseTest extends MockedTest
|
|||
self::assertEquals($data, $response->formatData('root_element', 'json', $data));
|
||||
}
|
||||
|
||||
public function testApiExitWithJson()
|
||||
{
|
||||
$l10n = \Mockery::mock(L10n::class);
|
||||
$l10n->shouldReceive('t')->andReturnUsing(function ($args) {
|
||||
return $args;
|
||||
});
|
||||
$args = \Mockery::mock(Arguments::class);
|
||||
$args->shouldReceive('getQueryString')->andReturn('');
|
||||
$baseUrl = \Mockery::mock(BaseURL::class);
|
||||
$twitterUser = \Mockery::mock(User::class);
|
||||
|
||||
$response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser);
|
||||
$response->exitWithJson(['some_data']);
|
||||
|
||||
self::assertEquals('["some_data"]', $response->getContent());
|
||||
}
|
||||
|
||||
public function testApiExitWithJsonP()
|
||||
{
|
||||
$l10n = \Mockery::mock(L10n::class);
|
||||
$l10n->shouldReceive('t')->andReturnUsing(function ($args) {
|
||||
return $args;
|
||||
});
|
||||
$args = \Mockery::mock(Arguments::class);
|
||||
$args->shouldReceive('getQueryString')->andReturn('');
|
||||
$baseUrl = \Mockery::mock(BaseURL::class);
|
||||
$twitterUser = \Mockery::mock(User::class);
|
||||
|
||||
$response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser, [], 'JsonPCallback');
|
||||
$response->exitWithJson(['some_data']);
|
||||
|
||||
self::assertEquals('JsonPCallback(["some_data"])', $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BaseApi::formatData() function with an XML result.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue