Merge remote-tracking branch 'upstream/2021.12-rc' into remove-obsolete

This commit is contained in:
Michael 2021-12-07 07:30:28 +00:00
commit b2042253c4
45 changed files with 495 additions and 343 deletions

View file

@ -221,6 +221,16 @@ class ApiResponse extends Response
$this->addContent($return);
}
/**
* Wrapper around exit() for JSON only responses
*
* @param array $data
*/
public function exitWithJson(array $data)
{
$this->exit('content', ['content' => $data], static::TYPE_JSON);
}
/**
* Quit execution with the message that the endpoint isn't implemented
*

View file

@ -81,7 +81,7 @@ class Followers extends BaseApi
DBA::close($followers);
if (!empty($request['min_id'])) {
array_reverse($accounts);
$accounts = array_reverse($accounts);
}
self::setLinkHeader();

View file

@ -81,7 +81,7 @@ class Following extends BaseApi
DBA::close($followers);
if (!empty($request['min_id'])) {
array_reverse($accounts);
$accounts = array_reverse($accounts);
}
self::setLinkHeader();

View file

@ -113,7 +113,7 @@ class Statuses extends BaseApi
DBA::close($items);
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -52,6 +52,6 @@ class VerifyCredentials extends BaseApi
// @todo Support the source property,
$account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid);
System::jsonExit($account);
$this->response->exitWithJson($account->toArray());
}
}

View file

@ -81,7 +81,7 @@ class Blocks extends BaseApi
DBA::close($followers);
if (!empty($request['min_id'])) {
array_reverse($accounts);
$accounts = array_reverse($accounts);
}
self::setLinkHeader();

View file

@ -77,7 +77,7 @@ class Bookmarks extends BaseApi
DBA::close($items);
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -91,7 +91,7 @@ class Conversations extends BaseApi
DBA::close($convs);
if (!empty($request['min_id'])) {
array_reverse($conversations);
$conversations = array_reverse($conversations);
}
self::setLinkHeader();

View file

@ -73,7 +73,7 @@ class Favourited extends BaseApi
DBA::close($items);
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -100,7 +100,7 @@ class Accounts extends BaseApi
DBA::close($members);
if (!empty($request['min_id'])) {
array_reverse($accounts);
$accounts = array_reverse($accounts);
}
self::setLinkHeader();

View file

@ -81,7 +81,7 @@ class Mutes extends BaseApi
DBA::close($followers);
if (!empty($request['min_id'])) {
array_reverse($accounts);
$accounts = array_reverse($accounts);
}
self::setLinkHeader();

View file

@ -105,7 +105,7 @@ class ScheduledStatuses extends BaseApi
DBA::close($posts);
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -167,7 +167,7 @@ class Search extends BaseApi
DBA::close($items);
if (!empty($min_id)) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -75,7 +75,7 @@ class Direct extends BaseApi
}
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -98,7 +98,7 @@ class Home extends BaseApi
DBA::close($items);
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -103,7 +103,7 @@ class ListTimeline extends BaseApi
DBA::close($items);
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -109,7 +109,7 @@ class PublicTimeline extends BaseApi
DBA::close($items);
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -112,7 +112,7 @@ class Tag extends BaseApi
DBA::close($items);
if (!empty($request['min_id'])) {
array_reverse($statuses);
$statuses = array_reverse($statuses);
}
self::setLinkHeader();

View file

@ -39,22 +39,22 @@ class UpdateProfile extends BaseApi
$api_user = DI::twitterUser()->createFromUserId($uid, true)->toArray();
if (!empty($_POST['name'])) {
DBA::update('profile', ['name' => $_POST['name']], ['uid' => $uid]);
DBA::update('user', ['username' => $_POST['name']], ['uid' => $uid]);
Contact::update(['name' => $_POST['name']], ['uid' => $uid, 'self' => 1]);
Contact::update(['name' => $_POST['name']], ['id' => $api_user['id']]);
if (!empty($request['name'])) {
DBA::update('profile', ['name' => $request['name']], ['uid' => $uid]);
DBA::update('user', ['username' => $request['name']], ['uid' => $uid]);
Contact::update(['name' => $request['name']], ['uid' => $uid, 'self' => 1]);
Contact::update(['name' => $request['name']], ['id' => $api_user['id']]);
}
if (isset($_POST['description'])) {
DBA::update('profile', ['about' => $_POST['description']], ['uid' => $uid]);
Contact::update(['about' => $_POST['description']], ['uid' => $uid, 'self' => 1]);
Contact::update(['about' => $_POST['description']], ['id' => $api_user['id']]);
if (isset($request['description'])) {
DBA::update('profile', ['about' => $request['description']], ['uid' => $uid]);
Contact::update(['about' => $request['description']], ['uid' => $uid, 'self' => 1]);
Contact::update(['about' => $request['description']], ['id' => $api_user['id']]);
}
Profile::publishUpdate($uid);
$skip_status = $_REQUEST['skip_status'] ?? false;
$skip_status = $request['skip_status'] ?? false;
$user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray();

View file

@ -79,7 +79,7 @@ class Ids extends ContactEndpoint
DBA::close($contacts);
if (!empty($min_id)) {
array_reverse($ids);
$ids = array_reverse($ids);
}
$return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);

View file

@ -80,13 +80,13 @@ class Lists extends ContactEndpoint
DBA::close($contacts);
if (!empty($min_id)) {
array_reverse($ids);
$ids = array_reverse($ids);
}
$return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities);
self::setLinkHeader();
System::jsonExit($return);
$this->response->exit('lists', ['lists' => $return]);
}
}

View file

@ -84,7 +84,7 @@ class Ids extends ContactEndpoint
DBA::close($followers);
if (!empty($min_id)) {
array_reverse($ids);
$ids = array_reverse($ids);
}
$return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);

View file

@ -85,13 +85,13 @@ class Lists extends ContactEndpoint
DBA::close($followers);
if (!empty($min_id)) {
array_reverse($ids);
$ids = array_reverse($ids);
}
$return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities);
self::setLinkHeader();
System::jsonExit($return);
$this->response->exit('lists', ['lists' => $return]);
}
}

View file

@ -84,7 +84,7 @@ class Ids extends ContactEndpoint
DBA::close($followers);
if (!empty($min_id)) {
array_reverse($ids);
$ids = array_reverse($ids);
}
$return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);

View file

@ -85,13 +85,13 @@ class Lists extends ContactEndpoint
DBA::close($followers);
if (!empty($min_id)) {
array_reverse($ids);
$ids = array_reverse($ids);
}
$return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities);
self::setLinkHeader();
System::jsonExit($return);
$this->response->exit('lists', ['lists' => $return]);
}
}

View file

@ -79,13 +79,13 @@ class Incoming extends ContactEndpoint
DBA::close($contacts);
if (!empty($min_id)) {
array_reverse($ids);
$ids = array_reverse($ids);
}
$return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);
self::setLinkHeader();
System::jsonExit($return);
$this->response->exit('incoming', ['incoming' => $return]);
}
}

View file

@ -40,23 +40,23 @@ class Statuses extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
if (empty($_REQUEST['list_id'])) {
if (empty($request['list_id'])) {
throw new BadRequestException('list_id not specified');
}
// params
$count = $_REQUEST['count'] ?? 20;
$page = $_REQUEST['page'] ?? 1;
$since_id = $_REQUEST['since_id'] ?? 0;
$max_id = $_REQUEST['max_id'] ?? 0;
$exclude_replies = (!empty($_REQUEST['exclude_replies']) ? 1 : 0);
$conversation_id = $_REQUEST['conversation_id'] ?? 0;
$count = $request['count'] ?? 20;
$page = $request['page'] ?? 1;
$since_id = $request['since_id'] ?? 0;
$max_id = $request['max_id'] ?? 0;
$exclude_replies = (!empty($request['exclude_replies']) ? 1 : 0);
$conversation_id = $request['conversation_id'] ?? 0;
$start = max(0, ($page - 1) * $count);
$groups = DBA::selectToArray('group_member', ['contact-id'], ['gid' => 1]);
$groups = DBA::selectToArray('group_member', ['contact-id'], ['gid' => $request['list_id']]);
$gids = array_column($groups, 'contact-id');
$condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'group-id' => $gids];
$condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'contact-id' => $gids];
$condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]);
if ($max_id > 0) {
@ -75,7 +75,7 @@ class Statuses extends BaseApi
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
$items = [];
while ($status = DBA::fetch($statuses)) {

View file

@ -437,6 +437,13 @@ class Transmitter
return [];
}
$permissions = [
'to' => [],
'cc' => [],
'bto' => [],
'bcc' => [],
];
$activity = json_decode($conversation['source'], true);
$actor = JsonLD::fetchElement($activity, 'actor', 'id');

View file

@ -220,6 +220,55 @@ return [
'network' => Protocol::DFRN,
'location' => 'DFRN',
],
[
'id' => 48,
'uid' => 0,
'uri-id' => 42,
'name' => 'Self contact',
'nick' => 'selfcontact',
'self' => 0,
'nurl' => 'http://localhost/profile/selfcontact',
'url' => 'http://localhost/profile/selfcontact',
'about' => 'User used in tests',
'pending' => 0,
'blocked' => 0,
'rel' => Contact::FOLLOWER,
'network' => Protocol::DFRN,
'location' => 'DFRN',
],
],
'apcontact' => [
[
"url" => "http://localhost/profile/selfcontact",
"uri-id" => 1,
"uuid" => "42",
"type" => "Person",
"following" => "http://localhost/following/selfcontact",
"followers" => "http://localhost/followers/selfcontact",
"inbox" => "http://localhost/inbox/selfcontact",
"outbox" => "http://localhost/outbox/selfcontact",
"sharedinbox" => "http://localhost/inbox",
"manually-approve" => 1,
"discoverable" => 0,
"nick" => "selfcontact",
"name" => "Self contact",
"about" => "User used in tests",
"xmpp" => null,
"matrix" => null,
"photo" => "http://localhost/photo/profile/admin.jpeg",
"header" => null,
"addr" => "selfcontact@localhost",
"alias" => null,
"pubkey" => "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzLquDFnFxNYZZFQNbA9f\nkgtUJpC+MPrhxhEsjxme1ivvE4itdPnCueBHifknUkwfmqormyeqr4TdoVbNuKRg\nj2QRBdtaGbUJLQVdbiTKFOmJIYMtV05WIIHEhUW84fwIXmF+6u3kbOw+sIjWY3OW\nwC/2+54HiYS2n8cddfwoZBim6Na8yyQI8pQSKqJ+I4gDfkGuoVex0svNPEv9liLE\nykpQ3PuoeLJV2Wex0Cy6FYPgcfH6xvvUVxh6e8w0w22jC3DJInfDrmbw5H7aUbf+\nMMwV3TVI6/CqTO0cLEOZUjsUwdm6lIV0O0fTsrkjU9G0bc0sLJl7n9i9ICDOKOMf\nCLaK2Pj2sVbpkzXJoufLUDf0oSftdVvN9jR9WYxRdnwsyF8N/xVTw8AsyHhkXawR\n3YDgi6i2uZj5kvG7GPBf7EPZ/MpbGhEZB+/GQuZuyhLdgFDSi/uX8STBmn1jI/zY\nTLZ8JCwMzFKAXAtYaBPklZBbcRyz9O1893MsAXO8d6ODTOkD324gAjRUtuOMscYc\nWV98NZIUSbqQrznmMoJn1fiMNVgx+UXOPkiZuDxnrr1T3vynKnl5LXmadx2YeoAf\nxPeCoDb0eJtCDLcsTZ9qlztaEaohPV+H3HBSpdItea7LgAbccILHPssk9tUgmHVl\na5yV8uFenhKKQ9g93Pt63LsCAwEAAQ==\n-----END PUBLIC KEY-----",
"subscribe" => "/follow?url={uri}",
"baseurl" => null,
"gsid" => null,
"generator" => "Friendica 'Siberian Iris' 2021.12-dev-1443",
"following_count" => 0,
"followers_count" => 0,
"statuses_count" => 0,
"updated" => "2021-11-19 19:17:59",
],
],
'verb' => [
[
@ -778,6 +827,13 @@ return [
'name' => 'Private list',
],
],
'group_member' => [
[
'id' => 1,
'gid' => 1,
'contact-id' => 42,
],
],
'search' => [
[
'id' => 1,

View file

@ -6,21 +6,14 @@
namespace Friendica\Test\legacy;
use Friendica\App;
use Friendica\App\Router;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Protocol;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Module\Api\ApiResponse;
use Friendica\Module\Api\Twitter\Media\Upload;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
use Friendica\Security\BasicAuth;
use Friendica\Test\FixtureTest;
use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
use Monolog\Handler\TestHandler;
require_once __DIR__ . '/../../include/api.php';

View file

@ -2,29 +2,39 @@
namespace Friendica\Test\src\Module\Api\GnuSocial\GnuSocial;
use Friendica\App\BaseURL;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\GNUSocial\GNUSocial\Config;
use Friendica\Test\src\Module\Api\ApiTest;
class ConfigTest extends ApiTest
{
/**
* Test the api_statusnet_config() function.
*
* @return void
*/
public function testApiStatusnetConfig()
{
/*
$result = api_statusnet_config('json');
self::assertEquals('localhost', $result['config']['site']['server']);
self::assertEquals('default', $result['config']['site']['theme']);
self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
self::assertTrue($result['config']['site']['fancy']);
self::assertEquals('en', $result['config']['site']['language']);
self::assertEquals('UTC', $result['config']['site']['timezone']);
self::assertEquals(200000, $result['config']['site']['textlimit']);
self::assertEquals('false', $result['config']['site']['private']);
self::assertEquals('false', $result['config']['site']['ssl']);
self::assertEquals(30, $result['config']['site']['shorturllength']);
*/
DI::config()->set('system', 'ssl_policy', BaseURL::SSL_POLICY_FULL);
$config = new Config(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $config->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
self::assertEquals(1, 1);
self::assertEquals('localhost', $json->site->server);
self::assertEquals('frio', $json->site->theme);
self::assertEquals(DI::baseUrl() . '/images/friendica-64.png', $json->site->logo);
self::assertTrue($json->site->fancy);
self::assertEquals('en', $json->site->language);
self::assertEquals('UTC', $json->site->timezone);
self::assertEquals(200000, $json->site->textlimit);
self::assertFalse($json->site->private);
self::assertEquals('always', $json->site->ssl);
}
}

View file

@ -2,6 +2,9 @@
namespace Friendica\Test\src\Module\Api\Mastodon\Accounts;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Mastodon\Accounts\Statuses;
use Friendica\Test\src\Module\Api\ApiTest;
class StatusesTest extends ApiTest
@ -11,6 +14,8 @@ class StatusesTest extends ApiTest
*/
public function testApiStatusShowWithJson()
{
self::markTestIncomplete('Needs Statuses to not set header during call (like at BaseApi::setLinkHeader');
// $result = api_status_show('json', 1);
// self::assertStatus($result['status']);
}
@ -20,6 +25,8 @@ class StatusesTest extends ApiTest
*/
public function testApiStatusShowWithXml()
{
self::markTestIncomplete('Needs Statuses to not set header during call (like at BaseApi::setLinkHeader');
// $result = api_status_show('xml', 1);
// self::assertXml($result, 'statuses');
}

View file

@ -2,6 +2,9 @@
namespace Friendica\Test\src\Module\Api\Mastodon\Accounts;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Mastodon\Accounts\VerifyCredentials;
use Friendica\Test\src\Module\Api\ApiTest;
class VerifyCredentialsTest extends ApiTest
@ -13,7 +16,18 @@ class VerifyCredentialsTest extends ApiTest
*/
public function testApiAccountVerifyCredentials()
{
// self::assertArrayHasKey('user', api_account_verify_credentials('json'));
$verifyCredentials = new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $verifyCredentials->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
self::assertEquals(48, $json->id);
self::assertIsArray($json->emojis);
self::assertIsArray($json->fields);
}
/**
@ -23,6 +37,8 @@ class VerifyCredentialsTest extends ApiTest
*/
public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
{
self::markTestIncomplete('Needs dynamic BasicAuth first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// $_SESSION['authenticated'] = false;

View file

@ -13,6 +13,8 @@ class ConversationsTest extends ApiTest
*/
public function testApiConversationShow()
{
self::markTestIncomplete('Needs Conversations to not set header during call (like at BaseApi::setLinkHeader');
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// api_conversation_show('json');
}
@ -24,6 +26,8 @@ class ConversationsTest extends ApiTest
*/
public function testApiConversationShowWithId()
{
self::markTestIncomplete('Needs Conversations to not set header during call (like at BaseApi::setLinkHeader');
/*
DI::args()->setArgv(['', '', '', 1]);
$_REQUEST['max_id'] = 10;
@ -43,6 +47,8 @@ class ConversationsTest extends ApiTest
*/
public function testApiConversationShowWithUnallowedUser()
{
self::markTestIncomplete('Needs Conversations to not set header during call (like at BaseApi::setLinkHeader');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// api_conversation_show('json');

View file

@ -13,6 +13,8 @@ class SearchTest extends ApiTest
*/
public function testApiSearch()
{
self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['q'] = 'reply';
$_REQUEST['max_id'] = 10;
@ -31,6 +33,8 @@ class SearchTest extends ApiTest
*/
public function testApiSearchWithCount()
{
self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['q'] = 'reply';
$_REQUEST['count'] = 20;
@ -49,6 +53,8 @@ class SearchTest extends ApiTest
*/
public function testApiSearchWithRpp()
{
self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['q'] = 'reply';
$_REQUEST['rpp'] = 20;
@ -66,6 +72,8 @@ class SearchTest extends ApiTest
*/
public function testApiSearchWithHashtag()
{
self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['q'] = '%23friendica';
$result = api_search('json');
@ -82,6 +90,8 @@ class SearchTest extends ApiTest
*/
public function testApiSearchWithExcludeReplies()
{
self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true;
@ -100,6 +110,8 @@ class SearchTest extends ApiTest
*/
public function testApiSearchWithUnallowedUser()
{
self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// api_search('json');
@ -112,6 +124,8 @@ class SearchTest extends ApiTest
*/
public function testApiSearchWithoutQuery()
{
self::markTestIncomplete('Needs Search to not set header during call (like at BaseApi::setLinkHeader');
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// api_search('json');
}

View file

@ -13,6 +13,8 @@ class HomeTest extends ApiTest
*/
public function testApiStatusesHomeTimeline()
{
self::markTestIncomplete('Needs Home to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true;
@ -32,6 +34,8 @@ class HomeTest extends ApiTest
*/
public function testApiStatusesHomeTimelineWithNegativePage()
{
self::markTestIncomplete('Needs Home to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['page'] = -2;
$result = api_statuses_home_timeline('json');
@ -49,6 +53,8 @@ class HomeTest extends ApiTest
*/
public function testApiStatusesHomeTimelineWithUnallowedUser()
{
self::markTestIncomplete('Needs Home to not set header during call (like at BaseApi::setLinkHeader');
/*
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
@ -63,6 +69,8 @@ class HomeTest extends ApiTest
*/
public function testApiStatusesHomeTimelineWithRss()
{
self::markTestIncomplete('Needs Home to not set header during call (like at BaseApi::setLinkHeader');
// $result = api_statuses_home_timeline('rss');
// self::assertXml($result, 'statuses');
}

View file

@ -13,6 +13,8 @@ class PublicTimelineTest extends ApiTest
*/
public function testApiStatusesPublicTimeline()
{
self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['max_id'] = 10;
$_REQUEST['conversation_id'] = 1;
@ -31,6 +33,8 @@ class PublicTimelineTest extends ApiTest
*/
public function testApiStatusesPublicTimelineWithExcludeReplies()
{
self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['max_id'] = 10;
$_REQUEST['exclude_replies'] = true;
@ -49,6 +53,8 @@ class PublicTimelineTest extends ApiTest
*/
public function testApiStatusesPublicTimelineWithNegativePage()
{
self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader');
/*
$_REQUEST['page'] = -2;
$result = api_statuses_public_timeline('json');
@ -66,6 +72,8 @@ class PublicTimelineTest extends ApiTest
*/
public function testApiStatusesPublicTimelineWithUnallowedUser()
{
self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// api_statuses_public_timeline('json');
@ -78,6 +86,8 @@ class PublicTimelineTest extends ApiTest
*/
public function testApiStatusesPublicTimelineWithRss()
{
self::markTestIncomplete('Needs PublicTimeline to not set header during call (like at BaseApi::setLinkHeader');
// $result = api_statuses_public_timeline('rss');
// self::assertXml($result, 'statuses');
}

View file

@ -2,6 +2,7 @@
namespace Friendica\Test\src\Module\Api\Twitter\Account;
use Friendica\App\Router;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Account\RateLimitStatus;
@ -11,7 +12,7 @@ class RateLimitStatusTest extends ApiTest
{
public function testWithJson()
{
$rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']);
$rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']);
$response = $rateLimitStatus->run();
$result = json_decode($response->getBody());

View file

@ -0,0 +1,29 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\Account;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Account\UpdateProfile;
use Friendica\Test\src\Module\Api\ApiTest;
class UpdateProfileTest extends ApiTest
{
/**
* Test the api_account_update_profile() function.
*/
public function testApiAccountUpdateProfile()
{
$updateProfile = new UpdateProfile(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => 'json']);
$response = $updateProfile->run(['name' => 'new_name', 'description' => 'new_description']);
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
self::assertEquals('new_name', $json->name);
self::assertEquals('new_description', $json->description);
}
}

View file

@ -1,28 +0,0 @@
<?php
namespace Friendica\Test\src\Module\Api\Twitter\Account;
use Friendica\Test\src\Module\Api\ApiTest;
class UpdateTest extends ApiTest
{
/**
* Test the api_account_update_profile() function.
*
* @return void
*/
public function testApiAccountUpdateProfile()
{
/*
$_POST['name'] = 'new_name';
$_POST['description'] = 'new_description';
$result = api_account_update_profile('json');
// We can't use assertSelfUser() here because the user object is missing some properties.
self::assertEquals($this->selfUser['id'], $result['user']['cid']);
self::assertEquals('DFRN', $result['user']['location']);
self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
self::assertEquals('new_name', $result['user']['name']);
self::assertEquals('new_description', $result['user']['description']);
*/
}
}

View file

@ -2,30 +2,28 @@
namespace Friendica\Test\src\Module\Api\Twitter\Blocks;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Blocks\Lists;
use Friendica\Test\src\Module\Api\ApiTest;
class ListsTest extends ApiTest
{
/**
* Test the api_statuses_f() function.
*
* @return void
*/
public function testApiStatusesFWithBlocks()
{
// $result = api_statuses_f('blocks');
// self::assertArrayHasKey('user', $result);
}
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run();
/**
* Test the api_blocks_list() function.
*
* @return void
*/
public function testApiBlocksList()
{
// $result = api_blocks_list('json');
// self::assertArrayHasKey('user', $result);
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
self::assertIsArray($json->users);
}
/**
@ -35,6 +33,8 @@ class ListsTest extends ApiTest
*/
public function testApiBlocksListWithUndefinedCursor()
{
self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks');
// $_GET['cursor'] = 'undefined';
// self::assertFalse(api_blocks_list('json'));
}

View file

@ -2,30 +2,28 @@
namespace Friendica\Test\src\Module\Api\Twitter\Followers;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Followers\Lists;
use Friendica\Test\src\Module\Api\ApiTest;
class ListsTest extends ApiTest
{
/**
* Test the api_statuses_f() function.
*
* @return void
*/
public function testApiStatusesFWithFollowers()
{
// $result = api_statuses_f('followers');
// self::assertArrayHasKey('user', $result);
}
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run();
/**
* Test the api_statuses_followers() function.
*
* @return void
*/
public function testApiStatusesFollowers()
{
// $result = api_statuses_followers('json');
// self::assertArrayHasKey('user', $result);
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
self::assertIsArray($json->users);
}
/**
@ -35,6 +33,8 @@ class ListsTest extends ApiTest
*/
public function testApiStatusesFollowersWithUndefinedCursor()
{
self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks');
// $_GET['cursor'] = 'undefined';
// self::assertFalse(api_statuses_followers('json'));
}

View file

@ -2,6 +2,9 @@
namespace Friendica\Test\src\Module\Api\Twitter\Friends;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Friends\Lists;
use Friendica\Test\src\Module\Api\ApiTest;
class ListsTest extends ApiTest
@ -13,9 +16,16 @@ class ListsTest extends ApiTest
*/
public function testApiStatusesFWithFriends()
{
// $_GET['page'] = -1;
// $result = api_statuses_f('friends');
// self::assertArrayHasKey('user', $result);
$lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
self::assertIsArray($json->users);
}
/**
@ -25,29 +35,9 @@ class ListsTest extends ApiTest
*/
public function testApiStatusesFWithUndefinedCursor()
{
self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks');
// $_GET['cursor'] = 'undefined';
// self::assertFalse(api_statuses_f('friends'));
}
/**
* Test the api_statuses_friends() function.
*
* @return void
*/
public function testApiStatusesFriends()
{
// $result = api_statuses_friends('json');
// self::assertArrayHasKey('user', $result);
}
/**
* Test the api_statuses_friends() function an undefined cursor GET variable.
*
* @return void
*/
public function testApiStatusesFriendsWithUndefinedCursor()
{
// $_GET['cursor'] = 'undefined';
// self::assertFalse(api_statuses_friends('json'));
}
}

View file

@ -2,6 +2,9 @@
namespace Friendica\Test\src\Module\Api\Twitter\Friendships;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Friendships\Incoming;
use Friendica\Test\src\Module\Api\ApiTest;
class IncomingTest extends ApiTest
@ -13,8 +16,16 @@ class IncomingTest extends ApiTest
*/
public function testApiFriendshipsIncoming()
{
// $result = api_friendships_incoming('json');
// self::assertArrayHasKey('id', $result);
$lists = new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run();
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
self::assertIsArray($json->ids);
}
/**
@ -24,6 +35,8 @@ class IncomingTest extends ApiTest
*/
public function testApiFriendshipsIncomingWithUndefinedCursor()
{
self::markTestIncomplete('Needs refactoring of Incoming - replace filter_input() with $request parameter checks');
// $_GET['cursor'] = 'undefined';
// self::assertFalse(api_friendships_incoming('json'));
}

View file

@ -2,6 +2,10 @@
namespace Friendica\Test\src\Module\Api\Twitter\Lists;
use Friendica\App\Router;
use Friendica\DI;
use Friendica\Module\Api\Twitter\Lists\Statuses;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Test\src\Module\Api\ApiTest;
class StatusesTest extends ApiTest
@ -13,37 +17,41 @@ class StatusesTest extends ApiTest
*/
public function testApiListsStatuses()
{
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// api_lists_statuses('json');
$this->expectException(BadRequestException::class);
$lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$lists->run();
}
/**
* Test the api_lists_statuses() function with a list ID.
* @doesNotPerformAssertions
*/
public function testApiListsStatusesWithListId()
{
/*
$_REQUEST['list_id'] = 1;
$_REQUEST['page'] = -1;
$_REQUEST['max_id'] = 10;
$result = api_lists_statuses('json');
foreach ($result['status'] as $status) {
self::assertStatus($status);
$lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
$response = $lists->run(['list_id' => 1, 'page' => -1, 'max_id' => 10]);
$body = (string)$response->getBody();
self::assertJson($body);
$json = json_decode($body);
foreach ($json as $status) {
self::assertIsString($status->text);
self::assertIsInt($status->id);
}
*/
}
/**
* Test the api_lists_statuses() function with a list ID and a RSS result.
*
* @return void
*/
public function testApiListsStatusesWithListIdAndRss()
{
// $_REQUEST['list_id'] = 1;
// $result = api_lists_statuses('rss');
// self::assertXml($result, 'statuses');
$lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']);
$response = $lists->run(['list_id' => 1]);
self::assertXml((string)$response->getBody());
}
/**
@ -53,6 +61,8 @@ class StatusesTest extends ApiTest
*/
public function testApiListsStatusesWithUnallowedUser()
{
self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// api_lists_statuses('json');