From d57cb05a242a3fcac0e537e9e5e2d67a5ca3af7a Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Dec 2021 06:22:04 +0000 Subject: [PATCH 01/17] Fix: array_reverse returns the reversed content as return value --- src/Module/Api/Mastodon/Accounts/Followers.php | 2 +- src/Module/Api/Mastodon/Accounts/Following.php | 2 +- src/Module/Api/Mastodon/Accounts/Statuses.php | 2 +- src/Module/Api/Mastodon/Blocks.php | 2 +- src/Module/Api/Mastodon/Bookmarks.php | 2 +- src/Module/Api/Mastodon/Conversations.php | 2 +- src/Module/Api/Mastodon/Favourited.php | 2 +- src/Module/Api/Mastodon/Lists/Accounts.php | 2 +- src/Module/Api/Mastodon/Mutes.php | 2 +- src/Module/Api/Mastodon/ScheduledStatuses.php | 2 +- src/Module/Api/Mastodon/Search.php | 2 +- src/Module/Api/Mastodon/Timelines/Direct.php | 2 +- src/Module/Api/Mastodon/Timelines/Home.php | 2 +- src/Module/Api/Mastodon/Timelines/ListTimeline.php | 2 +- src/Module/Api/Mastodon/Timelines/PublicTimeline.php | 2 +- src/Module/Api/Mastodon/Timelines/Tag.php | 2 +- src/Module/Api/Twitter/Blocks/Ids.php | 2 +- src/Module/Api/Twitter/Blocks/Lists.php | 2 +- src/Module/Api/Twitter/Followers/Ids.php | 2 +- src/Module/Api/Twitter/Followers/Lists.php | 2 +- src/Module/Api/Twitter/Friends/Ids.php | 2 +- src/Module/Api/Twitter/Friends/Lists.php | 2 +- src/Module/Api/Twitter/Friendships/Incoming.php | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Module/Api/Mastodon/Accounts/Followers.php b/src/Module/Api/Mastodon/Accounts/Followers.php index 3e06528bd7..cf5d63c7a5 100644 --- a/src/Module/Api/Mastodon/Accounts/Followers.php +++ b/src/Module/Api/Mastodon/Accounts/Followers.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Accounts/Following.php b/src/Module/Api/Mastodon/Accounts/Following.php index 2aace2683e..6e65c446ec 100644 --- a/src/Module/Api/Mastodon/Accounts/Following.php +++ b/src/Module/Api/Mastodon/Accounts/Following.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Accounts/Statuses.php b/src/Module/Api/Mastodon/Accounts/Statuses.php index 0ab5a2a50a..d24af5341a 100644 --- a/src/Module/Api/Mastodon/Accounts/Statuses.php +++ b/src/Module/Api/Mastodon/Accounts/Statuses.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Blocks.php b/src/Module/Api/Mastodon/Blocks.php index a299185aeb..38badfabaa 100644 --- a/src/Module/Api/Mastodon/Blocks.php +++ b/src/Module/Api/Mastodon/Blocks.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Bookmarks.php b/src/Module/Api/Mastodon/Bookmarks.php index a3d00dcd82..a9efacd128 100644 --- a/src/Module/Api/Mastodon/Bookmarks.php +++ b/src/Module/Api/Mastodon/Bookmarks.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Conversations.php b/src/Module/Api/Mastodon/Conversations.php index 6cc364c9cb..7bd797a2b4 100644 --- a/src/Module/Api/Mastodon/Conversations.php +++ b/src/Module/Api/Mastodon/Conversations.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Favourited.php b/src/Module/Api/Mastodon/Favourited.php index 243d119f96..8248474339 100644 --- a/src/Module/Api/Mastodon/Favourited.php +++ b/src/Module/Api/Mastodon/Favourited.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Lists/Accounts.php b/src/Module/Api/Mastodon/Lists/Accounts.php index 96b6f5bc93..ea103b0318 100644 --- a/src/Module/Api/Mastodon/Lists/Accounts.php +++ b/src/Module/Api/Mastodon/Lists/Accounts.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Mutes.php b/src/Module/Api/Mastodon/Mutes.php index 96a0c7eac4..80e04f3dd2 100644 --- a/src/Module/Api/Mastodon/Mutes.php +++ b/src/Module/Api/Mastodon/Mutes.php @@ -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(); diff --git a/src/Module/Api/Mastodon/ScheduledStatuses.php b/src/Module/Api/Mastodon/ScheduledStatuses.php index a40406e8dc..9edad365c0 100644 --- a/src/Module/Api/Mastodon/ScheduledStatuses.php +++ b/src/Module/Api/Mastodon/ScheduledStatuses.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Search.php b/src/Module/Api/Mastodon/Search.php index dcc9969f79..4fc5fe1f10 100644 --- a/src/Module/Api/Mastodon/Search.php +++ b/src/Module/Api/Mastodon/Search.php @@ -167,7 +167,7 @@ class Search extends BaseApi DBA::close($items); if (!empty($min_id)) { - array_reverse($statuses); + $statuses = array_reverse($statuses); } self::setLinkHeader(); diff --git a/src/Module/Api/Mastodon/Timelines/Direct.php b/src/Module/Api/Mastodon/Timelines/Direct.php index ea3a296dcd..42d42809b8 100644 --- a/src/Module/Api/Mastodon/Timelines/Direct.php +++ b/src/Module/Api/Mastodon/Timelines/Direct.php @@ -75,7 +75,7 @@ class Direct extends BaseApi } if (!empty($request['min_id'])) { - array_reverse($statuses); + $statuses = array_reverse($statuses); } self::setLinkHeader(); diff --git a/src/Module/Api/Mastodon/Timelines/Home.php b/src/Module/Api/Mastodon/Timelines/Home.php index bc53e9bcf8..fb31e37b0c 100644 --- a/src/Module/Api/Mastodon/Timelines/Home.php +++ b/src/Module/Api/Mastodon/Timelines/Home.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Timelines/ListTimeline.php b/src/Module/Api/Mastodon/Timelines/ListTimeline.php index c3e525f764..3cd2c0bd69 100644 --- a/src/Module/Api/Mastodon/Timelines/ListTimeline.php +++ b/src/Module/Api/Mastodon/Timelines/ListTimeline.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Timelines/PublicTimeline.php b/src/Module/Api/Mastodon/Timelines/PublicTimeline.php index c3ebe7af0f..54da38d5e0 100644 --- a/src/Module/Api/Mastodon/Timelines/PublicTimeline.php +++ b/src/Module/Api/Mastodon/Timelines/PublicTimeline.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Timelines/Tag.php b/src/Module/Api/Mastodon/Timelines/Tag.php index 441de039d8..3611b7173c 100644 --- a/src/Module/Api/Mastodon/Timelines/Tag.php +++ b/src/Module/Api/Mastodon/Timelines/Tag.php @@ -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(); diff --git a/src/Module/Api/Twitter/Blocks/Ids.php b/src/Module/Api/Twitter/Blocks/Ids.php index ea8655a63f..8a905f0ee3 100644 --- a/src/Module/Api/Twitter/Blocks/Ids.php +++ b/src/Module/Api/Twitter/Blocks/Ids.php @@ -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); diff --git a/src/Module/Api/Twitter/Blocks/Lists.php b/src/Module/Api/Twitter/Blocks/Lists.php index c0322ed6eb..1260b9c7bd 100644 --- a/src/Module/Api/Twitter/Blocks/Lists.php +++ b/src/Module/Api/Twitter/Blocks/Lists.php @@ -80,7 +80,7 @@ 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); diff --git a/src/Module/Api/Twitter/Followers/Ids.php b/src/Module/Api/Twitter/Followers/Ids.php index 5f203a0522..d30238300a 100644 --- a/src/Module/Api/Twitter/Followers/Ids.php +++ b/src/Module/Api/Twitter/Followers/Ids.php @@ -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); diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index a812e38da6..5f6696341d 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -85,7 +85,7 @@ 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); diff --git a/src/Module/Api/Twitter/Friends/Ids.php b/src/Module/Api/Twitter/Friends/Ids.php index 62164840dc..dfc5ba4e5f 100644 --- a/src/Module/Api/Twitter/Friends/Ids.php +++ b/src/Module/Api/Twitter/Friends/Ids.php @@ -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); diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 57841c3c90..7b38ed3668 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -85,7 +85,7 @@ 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); diff --git a/src/Module/Api/Twitter/Friendships/Incoming.php b/src/Module/Api/Twitter/Friendships/Incoming.php index 8a4a99565f..fed2bffbcc 100644 --- a/src/Module/Api/Twitter/Friendships/Incoming.php +++ b/src/Module/Api/Twitter/Friendships/Incoming.php @@ -79,7 +79,7 @@ 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); From 902bcc506f8c66b28803600d9453f35cefb750be Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 21:58:09 +0100 Subject: [PATCH 02/17] Re-enable StatusNetConfig test --- .../Api/GnuSocial/GnuSocial/ConfigTest.php | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php index 287b47b40c..83742e0c79 100644 --- a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php +++ b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php @@ -2,29 +2,36 @@ namespace Friendica\Test\src\Module\Api\GnuSocial\GnuSocial; +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']); - */ + $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); } } From cc7b2fae4e1d319f49fce6db60e0bb8f18b22acc Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 22:34:51 +0100 Subject: [PATCH 03/17] Re-enable AccountVerifyCredentials test --- .../Mastodon/Accounts/VerifyCredentials.php | 2 +- tests/datasets/api.fixture.php | 393 ++++++++++-------- .../Api/Mastodon/Accounts/StatusesTest.php | 7 + .../Accounts/VerifyCredentialsTest.php | 18 +- 4 files changed, 246 insertions(+), 174 deletions(-) diff --git a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php index 472ca7f565..4318fac7b5 100644 --- a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php +++ b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php @@ -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->exit('account', ['account' => $account->toArray()]); } } diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 9e0174c029..014692ccd1 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -36,7 +36,7 @@ return [ 'mail', 'post-delivery-data', // Base test config to avoid notice messages - 'config' => [ + 'config' => [ [ 'cat' => 'system', 'k' => 'url', @@ -63,7 +63,7 @@ return [ 'v' => '1', ], ], - 'user' => [ + 'user' => [ [ 'uid' => 42, 'username' => 'Test user', @@ -73,7 +73,7 @@ return [ 'theme' => 'frio', ], ], - 'item-uri' => [ + 'item-uri' => [ [ 'id' => 1, 'uri' => '1', @@ -128,100 +128,149 @@ return [ ], 'contact' => [ [ - 'id' => 42, - 'uid' => 42, - 'uri-id' => 42, - 'name' => 'Self contact', - 'nick' => 'selfcontact', - 'self' => 1, - '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, + 'id' => 42, + 'uid' => 42, + 'uri-id' => 42, + 'name' => 'Self contact', + 'nick' => 'selfcontact', + 'self' => 1, + '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', ], // Having the same name and nick allows us to test // the fallback to api_get_nick() in api_get_user() [ - 'id' => 43, - 'uid' => 0, - 'uri-id' => 43, - 'name' => 'othercontact', - 'nick' => 'othercontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/othercontact', - 'url' => 'http://localhost/profile/othercontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::NOTHING, - 'network' => Protocol::DFRN, + 'id' => 43, + 'uid' => 0, + 'uri-id' => 43, + 'name' => 'othercontact', + 'nick' => 'othercontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/othercontact', + 'url' => 'http://localhost/profile/othercontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::NOTHING, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], [ - 'id' => 44, - 'uid' => 42, - 'uri-id' => 44, - 'name' => 'Friend contact', - 'nick' => 'friendcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/friendcontact', - 'url' => 'http://localhost/profile/friendcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, + 'id' => 44, + 'uid' => 42, + 'uri-id' => 44, + 'name' => 'Friend contact', + 'nick' => 'friendcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/friendcontact', + 'url' => 'http://localhost/profile/friendcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], [ - 'id' => 45, - 'uid' => 0, - 'uri-id' => 44, - 'name' => 'Friend contact', - 'nick' => 'friendcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/friendcontact', - 'url' => 'http://localhost/profile/friendcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, + 'id' => 45, + 'uid' => 0, + 'uri-id' => 44, + 'name' => 'Friend contact', + 'nick' => 'friendcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/friendcontact', + 'url' => 'http://localhost/profile/friendcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], [ - 'id' => 46, - 'uid' => 42, - 'uri-id' => 46, - 'name' => 'Mutual contact', - 'nick' => 'mutualcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/mutualcontact', - 'url' => 'http://localhost/profile/mutualcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::FRIEND, - 'network' => Protocol::DFRN, + 'id' => 46, + 'uid' => 42, + 'uri-id' => 46, + 'name' => 'Mutual contact', + 'nick' => 'mutualcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/mutualcontact', + 'url' => 'http://localhost/profile/mutualcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::FRIEND, + 'network' => Protocol::DFRN, 'location' => 'DFRN', ], [ - 'id' => 47, - 'uid' => 0, - 'uri-id' => 46, - 'name' => 'Mutual contact', - 'nick' => 'mutualcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/mutualcontact', - 'url' => 'http://localhost/profile/mutualcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, + 'id' => 47, + 'uid' => 0, + 'uri-id' => 46, + 'name' => 'Mutual contact', + 'nick' => 'mutualcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/mutualcontact', + 'url' => 'http://localhost/profile/mutualcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 42, + 'uid' => 0, + 'uri-id' => 42, + 'name' => 'Self contact', + 'nick' => 'selfcontact', + 'self' => 1, + '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', ], ], - 'verb' => [ + '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' => [ [ 'id' => 0, 'name' => '', @@ -291,7 +340,7 @@ return [ 'plink' => 'http://localhost/display/6', ], ], - 'post' => [ + 'post' => [ [ 'uri-id' => 1, 'parent-uri-id' => 1, @@ -636,135 +685,135 @@ return [ 'wall' => 0, ], ], - 'post-thread' => [ + 'post-thread' => [ [ - 'uri-id' => 1, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'network' => Protocol::DFRN, + 'uri-id' => 1, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'network' => Protocol::DFRN, ], [ - 'uri-id' => 3, - 'author-id' => 43, - 'owner-id' => 43, - 'causer-id' => 43, - 'network' => Protocol::DFRN, + 'uri-id' => 3, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'network' => Protocol::DFRN, ], [ - 'uri-id' => 6, - 'author-id' => 44, - 'owner-id' => 44, - 'causer-id' => 44, - 'network' => Protocol::DFRN, + 'uri-id' => 6, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'network' => Protocol::DFRN, ], ], - 'post-thread-user' => [ + 'post-thread-user' => [ [ - 'uri-id' => 1, - 'uid' => 42, - 'wall' => 1, + 'uri-id' => 1, + 'uid' => 42, + 'wall' => 1, 'post-user-id' => 1, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'contact-id' => 42, - 'network' => Protocol::DFRN, - 'starred' => 1, - 'origin' => 1, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'contact-id' => 42, + 'network' => Protocol::DFRN, + 'starred' => 1, + 'origin' => 1, ], [ - 'uri-id' => 3, - 'uid' => 42, - 'wall' => 1, + 'uri-id' => 3, + 'uid' => 42, + 'wall' => 1, 'post-user-id' => 3, - 'author-id' => 43, - 'owner-id' => 43, - 'causer-id' => 43, - 'contact-id' => 43, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 1, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'contact-id' => 43, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 1, ], [ - 'uri-id' => 6, - 'uid' => 42, - 'wall' => 1, + 'uri-id' => 6, + 'uid' => 42, + 'wall' => 1, 'post-user-id' => 6, - 'author-id' => 44, - 'owner-id' => 44, - 'causer-id' => 44, - 'contact-id' => 44, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 1, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'contact-id' => 44, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 1, ], [ - 'uri-id' => 1, - 'uid' => 0, - 'wall' => 0, + 'uri-id' => 1, + 'uid' => 0, + 'wall' => 0, 'post-user-id' => 7, - 'author-id' => 42, - 'owner-id' => 42, - 'causer-id' => 42, - 'contact-id' => 42, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 0, + 'author-id' => 42, + 'owner-id' => 42, + 'causer-id' => 42, + 'contact-id' => 42, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], [ - 'uri-id' => 3, - 'uid' => 0, - 'wall' => 0, + 'uri-id' => 3, + 'uid' => 0, + 'wall' => 0, 'post-user-id' => 9, - 'author-id' => 43, - 'owner-id' => 43, - 'causer-id' => 43, - 'contact-id' => 43, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 0, + 'author-id' => 43, + 'owner-id' => 43, + 'causer-id' => 43, + 'contact-id' => 43, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], [ - 'uri-id' => 6, - 'uid' => 0, - 'wall' => 0, + 'uri-id' => 6, + 'uid' => 0, + 'wall' => 0, 'post-user-id' => 12, - 'author-id' => 44, - 'owner-id' => 44, - 'causer-id' => 44, - 'contact-id' => 44, - 'network' => Protocol::DFRN, - 'starred' => 0, - 'origin' => 0, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'contact-id' => 44, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 0, ], ], 'notify' => [ [ - 'id' => 1, - 'type' => 8, - 'name' => 'Reply to', - 'url' => 'http://localhost/display/1', - 'photo' => 'http://localhost/', - 'date' => '2020-01-01 12:12:02', - 'msg' => 'A test reply from an item', - 'uid' => 42, - 'link' => 'http://localhost/notification/1', - 'iid' => 4, - 'seen' => 0, - 'verb' => \Friendica\Protocol\Activity::POST, - 'otype' => Notification\ObjectType::ITEM, + 'id' => 1, + 'type' => 8, + 'name' => 'Reply to', + 'url' => 'http://localhost/display/1', + 'photo' => 'http://localhost/', + 'date' => '2020-01-01 12:12:02', + 'msg' => 'A test reply from an item', + 'uid' => 42, + 'link' => 'http://localhost/notification/1', + 'iid' => 4, + 'seen' => 0, + 'verb' => \Friendica\Protocol\Activity::POST, + 'otype' => Notification\ObjectType::ITEM, 'name_cache' => 'Reply to', - 'msg_cache' => 'A test reply from an item', + 'msg_cache' => 'A test reply from an item', ], ], 'profile' => [ [ - 'id' => 1, + 'id' => 1, 'uid' => 42, ], ], - 'group' => [ + 'group' => [ [ 'id' => 1, 'uid' => 42, @@ -778,7 +827,7 @@ return [ 'name' => 'Private list', ], ], - 'search' => [ + 'search' => [ [ 'id' => 1, 'term' => 'Saved search', diff --git a/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php b/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php index 885afbb3e3..0c6aab8867 100644 --- a/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php +++ b/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php @@ -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 Stastuses 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 Stastuses to not set header during call (like at BaseApi::setLinkHeader'); + // $result = api_status_show('xml', 1); // self::assertXml($result, 'statuses'); } diff --git a/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php b/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php index 25611b245f..c627050808 100644 --- a/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php +++ b/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php @@ -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(42, $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; From 215979c2acf801a3e4ca8ad8d53ee3f04bc81474 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 22:37:44 +0100 Subject: [PATCH 04/17] mark Timeline tests incomplete because of needed refactoring --- tests/src/Module/Api/Mastodon/Timelines/HomeTest.php | 8 ++++++++ .../Api/Mastodon/Timelines/PublicTimelineTest.php | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/src/Module/Api/Mastodon/Timelines/HomeTest.php b/tests/src/Module/Api/Mastodon/Timelines/HomeTest.php index 74b32ba798..b25cee3783 100644 --- a/tests/src/Module/Api/Mastodon/Timelines/HomeTest.php +++ b/tests/src/Module/Api/Mastodon/Timelines/HomeTest.php @@ -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'); } diff --git a/tests/src/Module/Api/Mastodon/Timelines/PublicTimelineTest.php b/tests/src/Module/Api/Mastodon/Timelines/PublicTimelineTest.php index c475dc2d6a..a75c2f1116 100644 --- a/tests/src/Module/Api/Mastodon/Timelines/PublicTimelineTest.php +++ b/tests/src/Module/Api/Mastodon/Timelines/PublicTimelineTest.php @@ -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'); } From 226f6038de3a2533081c4c59a82c1ec8d97bf28f Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 23:08:12 +0100 Subject: [PATCH 05/17] mark remaining Mastodon tests incomplete because of needed refactoring --- .../src/Module/Api/Mastodon/ConversationsTest.php | 6 ++++++ tests/src/Module/Api/Mastodon/SearchTest.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/src/Module/Api/Mastodon/ConversationsTest.php b/tests/src/Module/Api/Mastodon/ConversationsTest.php index 838c591c2f..e645cb8ddf 100644 --- a/tests/src/Module/Api/Mastodon/ConversationsTest.php +++ b/tests/src/Module/Api/Mastodon/ConversationsTest.php @@ -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'); diff --git a/tests/src/Module/Api/Mastodon/SearchTest.php b/tests/src/Module/Api/Mastodon/SearchTest.php index 417cb4d4b8..caa0ed976d 100644 --- a/tests/src/Module/Api/Mastodon/SearchTest.php +++ b/tests/src/Module/Api/Mastodon/SearchTest.php @@ -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'); } From 6b03ee29229e1c56e1ba71fb3ff062fa4f1ce51a Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 23:16:16 +0100 Subject: [PATCH 06/17] Re enable UpdateProfile test --- .../Api/Twitter/Account/UpdateProfile.php | 18 +++++------ .../Api/Twitter/Account/UpdateProfileTest.php | 32 +++++++++++++++++++ .../Module/Api/Twitter/Account/UpdateTest.php | 28 ---------------- 3 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php delete mode 100644 tests/src/Module/Api/Twitter/Account/UpdateTest.php diff --git a/src/Module/Api/Twitter/Account/UpdateProfile.php b/src/Module/Api/Twitter/Account/UpdateProfile.php index 5a66e2772e..a518fbad2f 100644 --- a/src/Module/Api/Twitter/Account/UpdateProfile.php +++ b/src/Module/Api/Twitter/Account/UpdateProfile.php @@ -39,17 +39,17 @@ 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); diff --git a/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php b/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php new file mode 100644 index 0000000000..5bfa789e02 --- /dev/null +++ b/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php @@ -0,0 +1,32 @@ + 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(42, $json->id); + self::assertEquals('DFRN', $json->location); + self::assertEquals('selfcontact', $json->screen_name); + self::assertEquals('new_name', $json->name); + self::assertEquals('new_description', $json->description); + } +} diff --git a/tests/src/Module/Api/Twitter/Account/UpdateTest.php b/tests/src/Module/Api/Twitter/Account/UpdateTest.php deleted file mode 100644 index 0be8700424..0000000000 --- a/tests/src/Module/Api/Twitter/Account/UpdateTest.php +++ /dev/null @@ -1,28 +0,0 @@ -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']); - */ - } -} From 7ca47e8d213241f1b9cc00df61b418bb960adc2f Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 23:24:56 +0100 Subject: [PATCH 07/17] Re enable Blocks/Lists test --- src/Module/Api/Twitter/Blocks/Lists.php | 2 +- .../Twitter/Account/RateLimitStatusTest.php | 3 +- .../Module/Api/Twitter/Blocks/ListsTest.php | 28 +++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Module/Api/Twitter/Blocks/Lists.php b/src/Module/Api/Twitter/Blocks/Lists.php index 1260b9c7bd..44ffe00248 100644 --- a/src/Module/Api/Twitter/Blocks/Lists.php +++ b/src/Module/Api/Twitter/Blocks/Lists.php @@ -87,6 +87,6 @@ class Lists extends ContactEndpoint self::setLinkHeader(); - System::jsonExit($return); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php b/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php index 64becb75c5..1368990d08 100644 --- a/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php +++ b/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php @@ -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()); diff --git a/tests/src/Module/Api/Twitter/Blocks/ListsTest.php b/tests/src/Module/Api/Twitter/Blocks/ListsTest.php index 9783a51e47..4f63581a70 100644 --- a/tests/src/Module/Api/Twitter/Blocks/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Blocks/ListsTest.php @@ -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')); } From 6d8b8d95b1a83a4d61bd8b490b68ed4f8266b680 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 23:29:29 +0100 Subject: [PATCH 08/17] Reenable Followers&Friends Lists and fixes a array_reverse() Bug --- src/Module/Api/Twitter/Followers/Lists.php | 2 +- src/Module/Api/Twitter/Friends/Lists.php | 2 +- .../Api/Twitter/Followers/ListsTest.php | 28 ++++++------- .../Module/Api/Twitter/Friends/ListsTest.php | 39 ++++++++----------- 4 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index 5f6696341d..1982d921be 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -92,6 +92,6 @@ class Lists extends ContactEndpoint self::setLinkHeader(); - System::jsonExit($return); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 7b38ed3668..16947d0721 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -92,6 +92,6 @@ class Lists extends ContactEndpoint self::setLinkHeader(); - System::jsonExit($return); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/tests/src/Module/Api/Twitter/Followers/ListsTest.php b/tests/src/Module/Api/Twitter/Followers/ListsTest.php index 2008227951..c1e053e5a1 100644 --- a/tests/src/Module/Api/Twitter/Followers/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Followers/ListsTest.php @@ -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')); } diff --git a/tests/src/Module/Api/Twitter/Friends/ListsTest.php b/tests/src/Module/Api/Twitter/Friends/ListsTest.php index c4c48daced..fbc5868424 100644 --- a/tests/src/Module/Api/Twitter/Friends/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Friends/ListsTest.php @@ -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,7 +16,17 @@ class ListsTest extends ApiTest */ public function testApiStatusesFWithFriends() { - // $_GET['page'] = -1; + $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); + // $result = api_statuses_f('friends'); // self::assertArrayHasKey('user', $result); } @@ -25,29 +38,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')); - } } From 85b9f2b02c586757f335060560202466f42e5da2 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 23:32:03 +0100 Subject: [PATCH 09/17] Reenable Incoming test and fixes an array_reverse() bug --- src/Module/Api/Twitter/Friendships/Incoming.php | 2 +- .../Module/Api/Twitter/Friends/ListsTest.php | 3 --- .../Api/Twitter/Friendships/IncomingTest.php | 17 +++++++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Module/Api/Twitter/Friendships/Incoming.php b/src/Module/Api/Twitter/Friendships/Incoming.php index fed2bffbcc..9cfcd056dc 100644 --- a/src/Module/Api/Twitter/Friendships/Incoming.php +++ b/src/Module/Api/Twitter/Friendships/Incoming.php @@ -86,6 +86,6 @@ class Incoming extends ContactEndpoint self::setLinkHeader(); - System::jsonExit($return); + $this->response->exit('incoming', ['incoming' => $return]); } } diff --git a/tests/src/Module/Api/Twitter/Friends/ListsTest.php b/tests/src/Module/Api/Twitter/Friends/ListsTest.php index fbc5868424..363f8d73c3 100644 --- a/tests/src/Module/Api/Twitter/Friends/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Friends/ListsTest.php @@ -26,9 +26,6 @@ class ListsTest extends ApiTest $json = json_decode($body); self::assertIsArray($json->users); - - // $result = api_statuses_f('friends'); - // self::assertArrayHasKey('user', $result); } /** diff --git a/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php b/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php index 5832800972..8c5cb6426b 100644 --- a/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php +++ b/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php @@ -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')); } From 9081b37762f3111ec5b0cab707b79641c653f3ef Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 4 Dec 2021 23:57:52 +0100 Subject: [PATCH 10/17] Fix Twitter statuses list & reenable tests --- src/Module/Api/Twitter/Lists/Statuses.php | 20 ++++----- tests/datasets/api.fixture.php | 7 ++++ .../Module/Api/Twitter/Lists/StatusesTest.php | 42 ++++++++++++------- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/Module/Api/Twitter/Lists/Statuses.php b/src/Module/Api/Twitter/Lists/Statuses.php index d647e4a271..9763e4575d 100644 --- a/src/Module/Api/Twitter/Lists/Statuses.php +++ b/src/Module/Api/Twitter/Lists/Statuses.php @@ -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)) { diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 014692ccd1..e85313ca61 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -827,6 +827,13 @@ return [ 'name' => 'Private list', ], ], + 'group_member' => [ + [ + 'id' => 1, + 'gid' => 1, + 'contact-id' => 42, + ], + ], 'search' => [ [ 'id' => 1, diff --git a/tests/src/Module/Api/Twitter/Lists/StatusesTest.php b/tests/src/Module/Api/Twitter/Lists/StatusesTest.php index 8dcb9d3313..5d989b71e7 100644 --- a/tests/src/Module/Api/Twitter/Lists/StatusesTest.php +++ b/tests/src/Module/Api/Twitter/Lists/StatusesTest.php @@ -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'); From dbfe918a8b1a86c8d2d221588b2618685fafe339 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 5 Dec 2021 00:03:11 +0100 Subject: [PATCH 11/17] Fix tests --- src/Module/Api/Twitter/Account/UpdateProfile.php | 2 +- tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Module/Api/Twitter/Account/UpdateProfile.php b/src/Module/Api/Twitter/Account/UpdateProfile.php index a518fbad2f..100b121b35 100644 --- a/src/Module/Api/Twitter/Account/UpdateProfile.php +++ b/src/Module/Api/Twitter/Account/UpdateProfile.php @@ -54,7 +54,7 @@ class UpdateProfile extends BaseApi Profile::publishUpdate($uid); - $skip_status = $_REQUEST['skip_status'] ?? false; + $skip_status = $request['skip_status'] ?? false; $user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray(); diff --git a/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php b/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php index 5bfa789e02..4ce3420d26 100644 --- a/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php +++ b/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php @@ -23,9 +23,6 @@ class UpdateProfileTest extends ApiTest $json = json_decode($body); - self::assertEquals(42, $json->id); - self::assertEquals('DFRN', $json->location); - self::assertEquals('selfcontact', $json->screen_name); self::assertEquals('new_name', $json->name); self::assertEquals('new_description', $json->description); } From df1aabd3046aa1f8b3ff3c3c6435b73706723892 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 5 Dec 2021 00:19:24 +0100 Subject: [PATCH 12/17] Fix dataset --- tests/datasets/api.fixture.php | 4 ++-- tests/legacy/ApiTest.php | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index e85313ca61..a8705696f2 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -221,12 +221,12 @@ return [ 'location' => 'DFRN', ], [ - 'id' => 42, + 'id' => 48, 'uid' => 0, 'uri-id' => 42, 'name' => 'Self contact', 'nick' => 'selfcontact', - 'self' => 1, + 'self' => 0, 'nurl' => 'http://localhost/profile/selfcontact', 'url' => 'http://localhost/profile/selfcontact', 'about' => 'User used in tests', diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index eb5394ec9e..2067a35362 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -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'; From 4efc12232a70488929134dc72d4af5145265a407 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 5 Dec 2021 00:20:46 +0100 Subject: [PATCH 13/17] Fix test --- .../src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php b/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php index c627050808..5170f1cb2f 100644 --- a/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php +++ b/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php @@ -25,7 +25,7 @@ class VerifyCredentialsTest extends ApiTest $json = json_decode($body); - self::assertEquals(42, $json->id); + self::assertEquals(48, $json->id); self::assertIsArray($json->emojis); self::assertIsArray($json->fields); } From d925e2542430bc508c46f14d371c70de5479158e Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 5 Dec 2021 00:23:12 +0100 Subject: [PATCH 14/17] Force right SSL_POLICY for test --- tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php index 83742e0c79..3cc1df2961 100644 --- a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php +++ b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php @@ -2,6 +2,7 @@ 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; @@ -14,6 +15,8 @@ class ConfigTest extends ApiTest */ public function testApiStatusnetConfig() { + 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(); From fb1e8e75f5eef9c4e05bec047bda6077e6c275de Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 6 Dec 2021 00:06:56 +0100 Subject: [PATCH 15/17] Add response for JSON only --- src/Module/Api/ApiResponse.php | 10 ++++++++++ src/Module/Api/Mastodon/Accounts/VerifyCredentials.php | 2 +- .../src/Module/Api/Mastodon/Accounts/StatusesTest.php | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Module/Api/ApiResponse.php b/src/Module/Api/ApiResponse.php index c4b9b1e943..a6a94ad81c 100644 --- a/src/Module/Api/ApiResponse.php +++ b/src/Module/Api/ApiResponse.php @@ -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 * diff --git a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php index 4318fac7b5..058a52f630 100644 --- a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php +++ b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php @@ -52,6 +52,6 @@ class VerifyCredentials extends BaseApi // @todo Support the source property, $account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid); - $this->response->exit('account', ['account' => $account->toArray()]); + $this->response->exitWithJson($account->toArray()); } } diff --git a/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php b/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php index 0c6aab8867..f2a709531c 100644 --- a/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php +++ b/tests/src/Module/Api/Mastodon/Accounts/StatusesTest.php @@ -14,7 +14,7 @@ class StatusesTest extends ApiTest */ public function testApiStatusShowWithJson() { - self::markTestIncomplete('Needs Stastuses to not set header during call (like at BaseApi::setLinkHeader'); + self::markTestIncomplete('Needs Statuses to not set header during call (like at BaseApi::setLinkHeader'); // $result = api_status_show('json', 1); // self::assertStatus($result['status']); @@ -25,7 +25,7 @@ class StatusesTest extends ApiTest */ public function testApiStatusShowWithXml() { - self::markTestIncomplete('Needs Stastuses to not set header during call (like at BaseApi::setLinkHeader'); + self::markTestIncomplete('Needs Statuses to not set header during call (like at BaseApi::setLinkHeader'); // $result = api_status_show('xml', 1); // self::assertXml($result, 'statuses'); From ad1aea0a2b4cc5befa5a8e3e45d91789b182c6ef Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 6 Dec 2021 19:27:22 -0500 Subject: [PATCH 16/17] Suppress Undefined property message in Core\Protocol - Address https://github.com/friendica/friendica/issues/10755#issuecomment-979427147 --- src/Core/Protocol.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Protocol.php b/src/Core/Protocol.php index bba7149a04..3b3a29d071 100644 --- a/src/Core/Protocol.php +++ b/src/Core/Protocol.php @@ -176,7 +176,7 @@ class Protocol $statusnet_user = $matches[2]; $UserData = DI::httpClient()->fetch('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user); $user = json_decode($UserData); - if ($user) { + if (!empty($user->screen_name)) { $matches[2] = $user->screen_name; return self::STATUSNET; } From b04809ced4577d75be4316a34e65f2e813c86756 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 6 Dec 2021 20:16:46 -0500 Subject: [PATCH 17/17] Initialize $permissions variable in ActivityPub\Transmitter::fetchPermissionBlockFromConversation - Address https://github.com/friendica/friendica/issues/10757#issuecomment-927361800 --- src/Protocol/ActivityPub/Transmitter.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 44b0463b03..9b5d052138 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -437,6 +437,13 @@ class Transmitter return []; } + $permissions = [ + 'to' => [], + 'cc' => [], + 'bto' => [], + 'bcc' => [], + ]; + $activity = json_decode($conversation['source'], true); $actor = JsonLD::fetchElement($activity, 'actor', 'id');