mirror of
https://github.com/friendica/friendica
synced 2025-04-25 01:10:12 +00:00
API: The legacy API finally moved
This commit is contained in:
parent
8abf1dccf0
commit
95f085b7ac
22 changed files with 1161 additions and 1391 deletions
|
@ -23,7 +23,6 @@
|
|||
namespace Friendica\Test\legacy;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\ACL;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
@ -129,37 +128,6 @@ class ApiTest extends FixtureTest
|
|||
BasicAuth::setCurrentUserID($this->selfUser['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that a list array contains expected keys.
|
||||
*
|
||||
* @param array $list List array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function assertList(array $list = [])
|
||||
{
|
||||
self::assertIsString($list['name']);
|
||||
self::assertIsInt($list['id']);
|
||||
self::assertIsString('string', $list['id_str']);
|
||||
self::assertContains($list['mode'], ['public', 'private']);
|
||||
// We could probably do more checks here.
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the string is XML and contain the root element.
|
||||
*
|
||||
* @param string $result XML string
|
||||
* @param string $root_element Root element name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function assertXml($result = '', $root_element = '')
|
||||
{
|
||||
self::assertStringStartsWith('<?xml version="1.0"?>', $result);
|
||||
self::assertStringContainsString('<' . $root_element, $result);
|
||||
// We could probably do more checks here.
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_user() function.
|
||||
*
|
||||
|
@ -214,26 +182,6 @@ class ApiTest extends FixtureTest
|
|||
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_register_func() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiRegisterFunc()
|
||||
{
|
||||
global $API;
|
||||
self::assertNull(
|
||||
api_register_func(
|
||||
'api_path',
|
||||
function () {
|
||||
},
|
||||
true,
|
||||
'method'
|
||||
)
|
||||
);
|
||||
self::assertTrue(is_callable($API['api_path']['func']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BasicAuth::getCurrentUserID() function without any login.
|
||||
*
|
||||
|
@ -312,166 +260,6 @@ class ApiTest extends FixtureTest
|
|||
BasicAuth::getCurrentUserID(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_call() function.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testApiCall()
|
||||
{
|
||||
global $API;
|
||||
$API['api_path'] = [
|
||||
'method' => 'method',
|
||||
'func' => function () {
|
||||
return ['data' => ['some_data']];
|
||||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'pagename=api_path';
|
||||
$_GET['callback'] = 'callback_name';
|
||||
|
||||
self::assertEquals(
|
||||
'callback_name(["some_data"])',
|
||||
api_call('api_path', 'json')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_call() function with the profiled enabled.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testApiCallWithProfiler()
|
||||
{
|
||||
global $API;
|
||||
$API['api_path'] = [
|
||||
'method' => 'method',
|
||||
'func' => function () {
|
||||
return ['data' => ['some_data']];
|
||||
}
|
||||
];
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'pagename=api_path';
|
||||
|
||||
$this->config->set('system', 'profiler', true);
|
||||
$this->config->set('rendertime', 'callstack', true);
|
||||
$this->app->callstack = [
|
||||
'database' => ['some_function' => 200],
|
||||
'database_write' => ['some_function' => 200],
|
||||
'cache' => ['some_function' => 200],
|
||||
'cache_write' => ['some_function' => 200],
|
||||
'network' => ['some_function' => 200]
|
||||
];
|
||||
|
||||
self::assertEquals(
|
||||
'["some_data"]',
|
||||
api_call('api_path', 'json')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_call() function with a JSON result.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testApiCallWithJson()
|
||||
{
|
||||
global $API;
|
||||
$API['api_path'] = [
|
||||
'method' => 'method',
|
||||
'func' => function () {
|
||||
return ['data' => ['some_data']];
|
||||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'pagename=api_path.json';
|
||||
|
||||
self::assertEquals(
|
||||
'["some_data"]',
|
||||
api_call('api_path.json', 'json')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_call() function with an XML result.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testApiCallWithXml()
|
||||
{
|
||||
global $API;
|
||||
$API['api_path'] = [
|
||||
'method' => 'method',
|
||||
'func' => function () {
|
||||
return 'some_data';
|
||||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'pagename=api_path.xml';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
self::assertEquals(
|
||||
'some_data',
|
||||
api_call('api_path.xml', 'xml')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_call() function with an RSS result.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testApiCallWithRss()
|
||||
{
|
||||
global $API;
|
||||
$API['api_path'] = [
|
||||
'method' => 'method',
|
||||
'func' => function () {
|
||||
return 'some_data';
|
||||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'pagename=api_path.rss';
|
||||
|
||||
self::assertEquals(
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
||||
'some_data',
|
||||
api_call('api_path.rss', 'rss')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_call() function with an Atom result.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testApiCallWithAtom()
|
||||
{
|
||||
global $API;
|
||||
$API['api_path'] = [
|
||||
'method' => 'method',
|
||||
'func' => function () {
|
||||
return 'some_data';
|
||||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'pagename=api_path.atom';
|
||||
|
||||
self::assertEquals(
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
||||
'some_data',
|
||||
api_call('api_path.atom', 'atom')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Arrays::walkRecursive() function.
|
||||
*
|
||||
|
@ -511,290 +299,4 @@ class ApiTest extends FixtureTest
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_lists_list() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiListsList()
|
||||
{
|
||||
$result = api_lists_list('json');
|
||||
self::assertEquals(['lists_list' => []], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_lists_ownerships() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiListsOwnerships()
|
||||
{
|
||||
$result = api_lists_ownerships('json');
|
||||
foreach ($result['lists']['lists'] as $list) {
|
||||
self::assertList($list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_lists_ownerships() function without an authenticated user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiListsOwnershipsWithoutAuthenticatedUser()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
||||
BasicAuth::setCurrentUserID();
|
||||
$_SESSION['authenticated'] = false;
|
||||
api_lists_ownerships('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photos_list() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotosList()
|
||||
{
|
||||
$result = api_fr_photos_list('json');
|
||||
self::assertArrayHasKey('photo', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photos_list() function without an authenticated user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotosListWithoutAuthenticatedUser()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
||||
BasicAuth::setCurrentUserID();
|
||||
$_SESSION['authenticated'] = false;
|
||||
api_fr_photos_list('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_create_update() function.
|
||||
*/
|
||||
public function testApiFrPhotoCreateUpdate()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
||||
api_fr_photo_create_update('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_create_update() function without an authenticated user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
||||
BasicAuth::setCurrentUserID();
|
||||
$_SESSION['authenticated'] = false;
|
||||
api_fr_photo_create_update('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_create_update() function with an album name.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotoCreateUpdateWithAlbum()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
||||
$_REQUEST['album'] = 'album_name';
|
||||
api_fr_photo_create_update('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_create_update() function with the update mode.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotoCreateUpdateWithUpdate()
|
||||
{
|
||||
$this->markTestIncomplete('We need to create a dataset for this');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_create_update() function with an uploaded file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotoCreateUpdateWithFile()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_detail() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotoDetail()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
||||
api_fr_photo_detail('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_detail() function without an authenticated user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotoDetailWithoutAuthenticatedUser()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
||||
BasicAuth::setCurrentUserID();
|
||||
$_SESSION['authenticated'] = false;
|
||||
api_fr_photo_detail('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_detail() function with a photo ID.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotoDetailWithPhotoId()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\NotFoundException::class);
|
||||
$_REQUEST['photo_id'] = 1;
|
||||
api_fr_photo_detail('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_fr_photo_detail() function with a correct photo ID.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFrPhotoDetailCorrectPhotoId()
|
||||
{
|
||||
$this->markTestIncomplete('We need to create a dataset for this.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_account_update_profile_image() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiAccountUpdateProfileImage()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
||||
api_account_update_profile_image('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_account_update_profile_image() function without an authenticated user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
||||
BasicAuth::setCurrentUserID();
|
||||
$_SESSION['authenticated'] = false;
|
||||
api_account_update_profile_image('json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_account_update_profile_image() function with an uploaded file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiAccountUpdateProfileImageWithUpload()
|
||||
{
|
||||
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the save_media_to_database() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveMediaToDatabase()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the post_photo_item() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPostPhotoItem()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the prepare_photo_data() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPreparePhotoData()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_friendica_group_show() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFriendicaGroupShow()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_lists_destroy() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiListsDestroy()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the group_create() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroupCreate()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_friendica_group_create() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiFriendicaGroupCreate()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_lists_create() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiListsCreate()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_lists_update() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiListsUpdate()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue