mirror of
https://github.com/friendica/friendica
synced 2025-04-25 14:30:10 +00:00
Move ApiResponse & Twitter Status tests
This commit is contained in:
parent
2c15fb03ff
commit
2e221943d4
3 changed files with 194 additions and 133 deletions
|
@ -113,4 +113,150 @@ class ApiResponseTest extends MockedTest
|
|||
|
||||
self::assertEquals('{"error":"API endpoint %s %s is not implemented","error_description":"The API endpoint is currently not implemented but might be in the future."}', $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BaseApi::reformatXML() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiReformatXml()
|
||||
{
|
||||
$item = true;
|
||||
$key = '';
|
||||
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
||||
self::assertEquals('true', $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BaseApi::reformatXML() function with a statusnet_api key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiReformatXmlWithStatusnetKey()
|
||||
{
|
||||
$item = '';
|
||||
$key = 'statusnet_api';
|
||||
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
||||
self::assertEquals('statusnet:api', $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BaseApi::reformatXML() function with a friendica_api key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiReformatXmlWithFriendicaKey()
|
||||
{
|
||||
$item = '';
|
||||
$key = 'friendica_api';
|
||||
self::assertTrue(ApiResponse::reformatXML($item, $key));
|
||||
self::assertEquals('friendica:api', $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BaseApi::createXML() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiCreateXml()
|
||||
{
|
||||
$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);
|
||||
|
||||
self::assertEquals(
|
||||
'<?xml version="1.0"?>' . "\n" .
|
||||
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
|
||||
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
|
||||
'xmlns:georss="http://www.georss.org/georss">' . "\n" .
|
||||
' <data>some_data</data>' . "\n" .
|
||||
'</root_element>' . "\n",
|
||||
$response->createXML(['data' => ['some_data']], 'root_element')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BaseApi::createXML() function without any XML namespace.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiCreateXmlWithoutNamespaces()
|
||||
{
|
||||
$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);
|
||||
|
||||
self::assertEquals(
|
||||
'<?xml version="1.0"?>' . "\n" .
|
||||
'<ok>' . "\n" .
|
||||
' <data>some_data</data>' . "\n" .
|
||||
'</ok>' . "\n",
|
||||
$response->createXML(['data' => ['some_data']], 'ok')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BaseApi::formatData() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFormatData()
|
||||
{
|
||||
$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);
|
||||
|
||||
$data = ['some_data'];
|
||||
self::assertEquals($data, $response->formatData('root_element', 'json', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BaseApi::formatData() function with an XML result.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFormatDataWithXml()
|
||||
{
|
||||
$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);
|
||||
|
||||
self::assertEquals(
|
||||
'<?xml version="1.0"?>' . "\n" .
|
||||
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
|
||||
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
|
||||
'xmlns:georss="http://www.georss.org/georss">' . "\n" .
|
||||
' <data>some_data</data>' . "\n" .
|
||||
'</root_element>' . "\n",
|
||||
$response->formatData('root_element', 'xml', ['data' => ['some_data']])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue