From 3374cac767c0f6e3104a1bb110fc2fb3ae0ad026 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 19:46:13 +0100 Subject: [PATCH 01/23] Move DirectMessages/New tests --- tests/legacy/ApiTest.php | 95 ------------ .../Api/Twitter/DirectMessages/NewDMTest.php | 135 ++++++++++++++++++ 2 files changed, 135 insertions(+), 95 deletions(-) create mode 100644 tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 53c9cc6e14..808fa92fbd 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -1190,101 +1190,6 @@ class ApiTest extends FixtureTest } - /** - * Test the api_direct_messages_new() function. - * - * @return void - */ - public function testApiDirectMessagesNew() - { - //$result = api_direct_messages_new('json'); - //self::assertNull($result); - } - - /** - * Test the api_direct_messages_new() function without an authenticated user. - * - * @return void - */ - public function testApiDirectMessagesNewWithoutAuthenticatedUser() - { - /* - $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); - BasicAuth::setCurrentUserID(); - $_SESSION['authenticated'] = false; - api_direct_messages_new('json'); - */ - } - - /** - * Test the api_direct_messages_new() function with an user ID. - * - * @return void - */ - public function testApiDirectMessagesNewWithUserId() - { - /* - $_POST['text'] = 'message_text'; - $_REQUEST['user_id'] = $this->otherUser['id']; - $result = api_direct_messages_new('json'); - self::assertEquals(['direct_message' => ['error' => -1]], $result); - */ - } - - /** - * Test the api_direct_messages_new() function with a screen name. - * - * @return void - */ - public function testApiDirectMessagesNewWithScreenName() - { - /* - $this->app->setLoggedInUserNickname($this->selfUser['nick']); - $_POST['text'] = 'message_text'; - $_REQUEST['user_id'] = $this->friendUser['id']; - $result = api_direct_messages_new('json'); - self::assertStringContainsString('message_text', $result['direct_message']['text']); - self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']); - self::assertEquals(1, $result['direct_message']['friendica_seen']); - */ - } - - /** - * Test the api_direct_messages_new() function with a title. - * - * @return void - */ - public function testApiDirectMessagesNewWithTitle() - { - /* - $this->app->setLoggedInUserNickname($this->selfUser['nick']); - $_POST['text'] = 'message_text'; - $_REQUEST['user_id'] = $this->friendUser['id']; - $_REQUEST['title'] = 'message_title'; - $result = api_direct_messages_new('json'); - self::assertStringContainsString('message_text', $result['direct_message']['text']); - self::assertStringContainsString('message_title', $result['direct_message']['text']); - self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']); - self::assertEquals(1, $result['direct_message']['friendica_seen']); - */ - } - - /** - * Test the api_direct_messages_new() function with an RSS result. - * - * @return void - */ - public function testApiDirectMessagesNewWithRss() - { - /* - $this->app->setLoggedInUserNickname($this->selfUser['nick']); - $_POST['text'] = 'message_text'; - $_REQUEST['user_id'] = $this->friendUser['id']; - $result = api_direct_messages_new('rss'); - self::assertXml($result, 'direct-messages'); - */ - } - /** * Test the api_direct_messages_destroy() function. * diff --git a/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php b/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php new file mode 100644 index 0000000000..d9bcc87ed1 --- /dev/null +++ b/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php @@ -0,0 +1,135 @@ + Router::GET], ['extension' => 'json']); + $response = $newDm->run(); + + self::assertEmpty((string)$response->getBody()); + } + + /** + * Test the api_direct_messages_new() function without an authenticated user. + * + * @return void + */ + public function testApiDirectMessagesNewWithoutAuthenticatedUser() + { + self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first'); + + /* + $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); + BasicAuth::setCurrentUserID(); + $_SESSION['authenticated'] = false; + api_direct_messages_new('json'); + */ + } + + /** + * Test the api_direct_messages_new() function with an user ID. + * + * @return void + */ + public function testApiDirectMessagesNewWithUserId() + { + $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + + $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); + $response = $newDm->run([ + 'text' => 'message_text', + 'user_id' => 43 + ]); + + $json = $this->toJson($response); + + self::assertEquals(-1, $json->error); + } + + /** + * Test the api_direct_messages_new() function with a screen name. + * + * @return void + */ + public function testApiDirectMessagesNewWithScreenName() + { + DI::app()->setLoggedInUserNickname('selfcontact'); + + $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + + $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); + $response = $newDm->run([ + 'text' => 'message_text', + 'user_id' => 44 + ]); + + $json = $this->toJson($response); + + self::assertStringContainsString('message_text', $json->text); + self::assertEquals('selfcontact', $json->sender_screen_name); + self::assertEquals(1, $json->friendica_seen); + } + + /** + * Test the api_direct_messages_new() function with a title. + * + * @return void + */ + public function testApiDirectMessagesNewWithTitle() + { + DI::app()->setLoggedInUserNickname('selfcontact'); + + $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + + $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); + $response = $newDm->run([ + 'text' => 'message_text', + 'user_id' => 44, + 'title' => 'message_title', + ]); + + $json = $this->toJson($response); + + self::assertStringContainsString('message_text', $json->text); + self::assertStringContainsString('message_title', $json->text); + self::assertEquals('selfcontact', $json->sender_screen_name); + self::assertEquals(1, $json->friendica_seen); + } + + /** + * Test the api_direct_messages_new() function with an RSS result. + * + * @return void + */ + public function testApiDirectMessagesNewWithRss() + { + DI::app()->setLoggedInUserNickname('selfcontact'); + + $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + + $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']); + $response = $newDm->run([ + 'text' => 'message_text', + 'user_id' => 44, + 'title' => 'message_title', + ]); + + self::assertXml((string)$response->getBody(), 'direct-messages'); + } +} From 0c4c6faa54cde9ff4067beaf7cdd14aeec987332 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 19:58:19 +0100 Subject: [PATCH 02/23] Move DirectMessages/Destory tests & fix Destroy condition --- .../Api/Twitter/DirectMessages/Destroy.php | 2 +- tests/legacy/ApiTest.php | 97 --------------- .../Twitter/DirectMessages/DestroyTest.php | 112 ++++++++++++++++++ 3 files changed, 113 insertions(+), 98 deletions(-) create mode 100644 tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php diff --git a/src/Module/Api/Twitter/DirectMessages/Destroy.php b/src/Module/Api/Twitter/DirectMessages/Destroy.php index 0d697de448..df760907d6 100644 --- a/src/Module/Api/Twitter/DirectMessages/Destroy.php +++ b/src/Module/Api/Twitter/DirectMessages/Destroy.php @@ -58,7 +58,7 @@ class Destroy extends BaseApi $parenturi = $request['friendica_parenturi'] ?? ''; // error if no id or parenturi specified (for clients posting parent-uri as well) - if ($verbose && ($id == 0 || $parenturi == "")) { + if ($verbose && $id == 0 && $parenturi == "") { $answer = ['result' => 'error', 'message' => 'message id or parenturi not specified']; $this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); return; diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 808fa92fbd..239e297d3e 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -1189,103 +1189,6 @@ class ApiTest extends FixtureTest // self::assertArrayHasKey('user', $result); } - - /** - * Test the api_direct_messages_destroy() function. - * - * @return void - */ - public function testApiDirectMessagesDestroy() - { - //$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - //api_direct_messages_destroy('json'); - } - - /** - * Test the api_direct_messages_destroy() function with the friendica_verbose GET param. - * - * @return void - */ - public function testApiDirectMessagesDestroyWithVerbose() - { - /* - $_GET['friendica_verbose'] = 'true'; - $result = api_direct_messages_destroy('json'); - self::assertEquals( - [ - '$result' => [ - 'result' => 'error', - 'message' => 'message id or parenturi not specified' - ] - ], - $result - ); - */ - } - - /** - * Test the api_direct_messages_destroy() function without an authenticated user. - * - * @return void - */ - public function testApiDirectMessagesDestroyWithoutAuthenticatedUser() - { - /* - $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); - BasicAuth::setCurrentUserID(); - $_SESSION['authenticated'] = false; - api_direct_messages_destroy('json'); - */ - } - - /** - * Test the api_direct_messages_destroy() function with a non-zero ID. - * - * @return void - */ - public function testApiDirectMessagesDestroyWithId() - { - /* - $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - $_REQUEST['id'] = 1; - api_direct_messages_destroy('json'); - */ - } - - /** - * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param. - * - * @return void - */ - public function testApiDirectMessagesDestroyWithIdAndVerbose() - { - /* - $_REQUEST['id'] = 1; - $_REQUEST['friendica_parenturi'] = 'parent_uri'; - $_GET['friendica_verbose'] = 'true'; - $result = api_direct_messages_destroy('json'); - self::assertEquals( - [ - '$result' => [ - 'result' => 'error', - 'message' => 'message id not in database' - ] - ], - $result - ); - */ - } - - /** - * Test the api_direct_messages_destroy() function with a non-zero ID. - * - * @return void - */ - public function testApiDirectMessagesDestroyWithCorrectId() - { - $this->markTestIncomplete('We need to add a dataset for this.'); - } - /** * Test the api_direct_messages_box() function. * diff --git a/tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php b/tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php new file mode 100644 index 0000000000..f1ab18d5c4 --- /dev/null +++ b/tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php @@ -0,0 +1,112 @@ +expectException(\Friendica\Network\HTTPException\BadRequestException::class); + (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))->run(); + } + + /** + * Test the api_direct_messages_destroy() function with the friendica_verbose GET param. + * + * @return void + */ + public function testApiDirectMessagesDestroyWithVerbose() + { + $destroy = new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); + $response = $destroy->run([ + 'friendica_verbose' => true, + ]); + + $json = $this->toJson($response); + + self::assertEquals('error', $json->result); + self::assertEquals('message id or parenturi not specified', $json->message); + } + + /** + * Test the api_direct_messages_destroy() function without an authenticated user. + * + * @return void + */ + public function testApiDirectMessagesDestroyWithoutAuthenticatedUser() + { + self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first'); + + /* + $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); + BasicAuth::setCurrentUserID(); + $_SESSION['authenticated'] = false; + api_direct_messages_destroy('json'); + */ + } + + /** + * Test the api_direct_messages_destroy() function with a non-zero ID. + * + * @return void + */ + public function testApiDirectMessagesDestroyWithId() + { + $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); + (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))->run(['id' => 1]); + } + + /** + * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param. + * + * @return void + */ + public function testApiDirectMessagesDestroyWithIdAndVerbose() + { + $destroy = new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); + $response = $destroy->run([ + 'id' => 1, + 'friendica_parenturi' => 'parent_uri', + 'friendica_verbose' => true, + ]); + + $json = $this->toJson($response); + + self::assertEquals('error', $json->result); + self::assertEquals('message id not in database', $json->message); + } + + /** + * Test the api_direct_messages_destroy() function with a non-zero ID. + * + * @return void + */ + public function testApiDirectMessagesDestroyWithCorrectId() + { + $this->loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba()); + $ids = DBA::selectToArray('mail', ['id']); + $id = $ids[0]['id']; + + $destroy = new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); + $response = $destroy->run([ + 'id' => $id, + 'friendica_verbose' => true, + ]); + + $json = $this->toJson($response); + + self::assertEquals('ok', $json->result); + self::assertEquals('message deleted', $json->message); + } +} From e7c5bdc77974eae03484386b09e6924822b8ac57 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 20:02:53 +0100 Subject: [PATCH 03/23] Move DirectMessages/Inbox tests --- tests/legacy/ApiTest.php | 22 ----------- .../Api/Twitter/DirectMessages/InboxTest.php | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 239e297d3e..5203e90a55 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -1226,17 +1226,6 @@ class ApiTest extends FixtureTest //self::assertArrayHasKey('direct_message', $result); } - /** - * Test the api_direct_messages_box() function. - * - * @return void - */ - public function testApiDirectMessagesBoxWithInbox() - { - //$result = api_direct_messages_box('json', 'inbox', 'false'); - //self::assertArrayHasKey('direct_message', $result); - } - /** * Test the api_direct_messages_box() function. * @@ -1292,17 +1281,6 @@ class ApiTest extends FixtureTest //self::assertArrayHasKey('direct_message', $result); } - /** - * Test the api_direct_messages_inbox() function. - * - * @return void - */ - public function testApiDirectMessagesInbox() - { - //$result = api_direct_messages_inbox('json'); - //self::assertArrayHasKey('direct_message', $result); - } - /** * Test the api_direct_messages_all() function. * diff --git a/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php b/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php new file mode 100644 index 0000000000..582729c8b9 --- /dev/null +++ b/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php @@ -0,0 +1,38 @@ +loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba()); + + $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + + $destroy = new Inbox($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); + $response = $destroy->run(); + + $json = $this->toJson($response); + + print_r($json); + + self::assertGreaterThan(0, count($json)); + + foreach ($json as $item) { + self::assertIsInt($item->id); + self::assertIsString($item->text); + } + } +} From 95e3583c68429ee306104599bec410973723175c Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 20:04:32 +0100 Subject: [PATCH 04/23] Move DirectMessages/All tests --- tests/legacy/ApiTest.php | 22 ------------ .../Api/Twitter/DirectMessages/AllTest.php | 36 +++++++++++++++++++ .../Api/Twitter/DirectMessages/InboxTest.php | 2 -- 3 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 tests/src/Module/Api/Twitter/DirectMessages/AllTest.php diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 5203e90a55..c4b6c373fe 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -1215,17 +1215,6 @@ class ApiTest extends FixtureTest //self::assertArrayHasKey('direct_message', $result); } - /** - * Test the api_direct_messages_box() function. - * - * @return void - */ - public function testApiDirectMessagesBoxWithAll() - { - //$result = api_direct_messages_box('json', 'all', 'false'); - //self::assertArrayHasKey('direct_message', $result); - } - /** * Test the api_direct_messages_box() function. * @@ -1281,17 +1270,6 @@ class ApiTest extends FixtureTest //self::assertArrayHasKey('direct_message', $result); } - /** - * Test the api_direct_messages_all() function. - * - * @return void - */ - public function testApiDirectMessagesAll() - { - //$result = api_direct_messages_all('json'); - //self::assertArrayHasKey('direct_message', $result); - } - /** * Test the api_direct_messages_conversation() function. * diff --git a/tests/src/Module/Api/Twitter/DirectMessages/AllTest.php b/tests/src/Module/Api/Twitter/DirectMessages/AllTest.php new file mode 100644 index 0000000000..52021c71b9 --- /dev/null +++ b/tests/src/Module/Api/Twitter/DirectMessages/AllTest.php @@ -0,0 +1,36 @@ +loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba()); + + $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + + $destroy = new All($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); + $response = $destroy->run(); + + $json = $this->toJson($response); + + self::assertGreaterThan(0, count($json)); + + foreach ($json as $item) { + self::assertIsInt($item->id); + self::assertIsString($item->text); + } + } +} diff --git a/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php b/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php index 582729c8b9..42c0b59785 100644 --- a/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php +++ b/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php @@ -26,8 +26,6 @@ class InboxTest extends ApiTest $json = $this->toJson($response); - print_r($json); - self::assertGreaterThan(0, count($json)); foreach ($json as $item) { From 07eca542a41f56b977bb68054849a1b5a6ea2f63 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 20:16:48 +0100 Subject: [PATCH 05/23] Move DirectMessages/Sent tests --- tests/legacy/ApiTest.php | 53 ---------------- .../Api/Twitter/DirectMessages/SentTest.php | 61 +++++++++++++++++++ 2 files changed, 61 insertions(+), 53 deletions(-) create mode 100644 tests/src/Module/Api/Twitter/DirectMessages/SentTest.php diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index c4b6c373fe..743af75e0a 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -1215,60 +1215,7 @@ class ApiTest extends FixtureTest //self::assertArrayHasKey('direct_message', $result); } - /** - * Test the api_direct_messages_box() function. - * - * @return void - */ - public function testApiDirectMessagesBoxWithVerbose() - { - /* - $result = api_direct_messages_box('json', 'sentbox', 'true'); - self::assertEquals( - [ - '$result' => [ - 'result' => 'error', - 'message' => 'no mails available' - ] - ], - $result - ); - */ - } - /** - * Test the api_direct_messages_box() function with a RSS result. - * - * @return void - */ - public function testApiDirectMessagesBoxWithRss() - { - //$result = api_direct_messages_box('rss', 'sentbox', 'false'); - //self::assertXml($result, 'direct-messages'); - } - - /** - * Test the api_direct_messages_box() function without an authenticated user. - * - * @return void - */ - public function testApiDirectMessagesBoxWithUnallowedUser() - { - //$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); - //BasicAuth::setCurrentUserID(); - //api_direct_messages_box('json', 'sentbox', 'false'); - } - - /** - * Test the api_direct_messages_sentbox() function. - * - * @return void - */ - public function testApiDirectMessagesSentbox() - { - //$result = api_direct_messages_sentbox('json'); - //self::assertArrayHasKey('direct_message', $result); - } /** * Test the api_direct_messages_conversation() function. diff --git a/tests/src/Module/Api/Twitter/DirectMessages/SentTest.php b/tests/src/Module/Api/Twitter/DirectMessages/SentTest.php new file mode 100644 index 0000000000..3343716622 --- /dev/null +++ b/tests/src/Module/Api/Twitter/DirectMessages/SentTest.php @@ -0,0 +1,61 @@ + Router::GET], ['extension' => 'json']); + $response = $sent->run([ + 'friendica_verbose' => true, + ]); + + $json = $this->toJson($response); + + self::assertEquals('error', $json->result); + self::assertEquals('no mails available', $json->message); + } + + /** + * Test the api_direct_messages_box() function with a RSS result. + * + * @return void + */ + public function testApiDirectMessagesBoxWithRss() + { + $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + + $sent = new Sent($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']); + $response = $sent->run(); + + self::assertXml((string)$response->getBody(), 'direct-messages'); + } + + /** + * Test the api_direct_messages_box() function without an authenticated user. + * + * @return void + */ + public function testApiDirectMessagesBoxWithUnallowedUser() + { + self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first'); + + //$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); + //BasicAuth::setCurrentUserID(); + //api_direct_messages_box('json', 'sentbox', 'false'); + } +} From 0f40aec0e3431de8651774e67480fdbd9b7ba13e Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 20:18:34 +0100 Subject: [PATCH 06/23] Move DirectMessages/Conversation tests --- tests/legacy/ApiTest.php | 37 ------------------- .../DirectMessages/ConversationTest.php | 32 ++++++++++++++++ 2 files changed, 32 insertions(+), 37 deletions(-) create mode 100644 tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 743af75e0a..e7fba6583e 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -1189,44 +1189,7 @@ class ApiTest extends FixtureTest // self::assertArrayHasKey('user', $result); } - /** - * Test the api_direct_messages_box() function. - * - * @return void - */ - public function testApiDirectMessagesBoxWithSentbox() - { - /* - $_REQUEST['page'] = -1; - $_REQUEST['max_id'] = 10; - $result = api_direct_messages_box('json', 'sentbox', 'false'); - self::assertArrayHasKey('direct_message', $result); - */ - } - /** - * Test the api_direct_messages_box() function. - * - * @return void - */ - public function testApiDirectMessagesBoxWithConversation() - { - //$result = api_direct_messages_box('json', 'conversation', 'false'); - //self::assertArrayHasKey('direct_message', $result); - } - - - - /** - * Test the api_direct_messages_conversation() function. - * - * @return void - */ - public function testApiDirectMessagesConversation() - { - //$result = api_direct_messages_conversation('json'); - //self::assertArrayHasKey('direct_message', $result); - } /** * Test the api_oauth_request_token() function. diff --git a/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php b/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php new file mode 100644 index 0000000000..815d5eb577 --- /dev/null +++ b/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php @@ -0,0 +1,32 @@ + Router::GET], ['extension' => 'json']); + $response = $sent->run([ + 'friendica_verbose' => true, + ]); + + $json = $this->toJson($response); + + self::assertEquals('error', $json->result); + self::assertEquals('no mails available', $json->message); + } +} From 84ca2d6e9897fe6de930d904e6d92d2817313891 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 20:23:38 +0100 Subject: [PATCH 07/23] Cleanup: Remove already deprecated API tests --- tests/legacy/ApiTest.php | 112 --------------------------------------- 1 file changed, 112 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index e7fba6583e..f42b837e3d 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -1189,28 +1189,6 @@ class ApiTest extends FixtureTest // self::assertArrayHasKey('user', $result); } - - - /** - * Test the api_oauth_request_token() function. - * - * @return void - */ - public function testApiOauthRequestToken() - { - $this->markTestIncomplete('exit() kills phpunit as well'); - } - - /** - * Test the api_oauth_access_token() function. - * - * @return void - */ - public function testApiOauthAccessToken() - { - $this->markTestIncomplete('exit() kills phpunit as well'); - } - /** * Test the api_fr_photos_list() function. * @@ -1423,26 +1401,6 @@ class ApiTest extends FixtureTest $this->markTestIncomplete(); } - /** - * Test the api_share_as_retweet() function with a valid item. - * - * @return void - */ - public function testApiShareAsRetweetWithValidItem() - { - $this->markTestIncomplete(); - } - - /** - * Test the api_in_reply_to() function with a valid item. - * - * @return void - */ - public function testApiInReplyToWithValidItem() - { - $this->markTestIncomplete(); - } - /** * Test the api_clean_plain_items() function. * @@ -1455,16 +1413,6 @@ class ApiTest extends FixtureTest //self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result); } - /** - * Test the api_best_nickname() function with contacts. - * - * @return void - */ - public function testApiBestNicknameWithContacts() - { - $this->markTestIncomplete(); - } - /** * Test the api_friendica_group_show() function. * @@ -1475,16 +1423,6 @@ class ApiTest extends FixtureTest $this->markTestIncomplete(); } - /** - * Test the api_friendica_group_delete() function. - * - * @return void - */ - public function testApiFriendicaGroupDelete() - { - $this->markTestIncomplete(); - } - /** * Test the api_lists_destroy() function. * @@ -1525,16 +1463,6 @@ class ApiTest extends FixtureTest $this->markTestIncomplete(); } - /** - * Test the api_friendica_group_update() function. - * - * @return void - */ - public function testApiFriendicaGroupUpdate() - { - $this->markTestIncomplete(); - } - /** * Test the api_lists_update() function. * @@ -1544,44 +1472,4 @@ class ApiTest extends FixtureTest { $this->markTestIncomplete(); } - - /** - * Test the api_friendica_activity() function. - * - * @return void - */ - public function testApiFriendicaActivity() - { - $this->markTestIncomplete(); - } - - /** - * Test the api_friendica_notification_seen() function. - * - * @return void - */ - public function testApiFriendicaNotificationSeen() - { - $this->markTestIncomplete(); - } - - /** - * Test the api_friendica_direct_messages_setseen() function. - * - * @return void - */ - public function testApiFriendicaDirectMessagesSetseen() - { - $this->markTestIncomplete(); - } - - /** - * Test the api_friendica_direct_messages_search() function. - * - * @return void - */ - public function testApiFriendicaDirectMessagesSearch() - { - $this->markTestIncomplete(); - } } From 51c94016cde25d0cfd79a9116463ca04c5e3b4c7 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 20:50:42 +0100 Subject: [PATCH 08/23] Move API User tests --- tests/legacy/ApiTest.php | 148 --------------------- tests/src/Factory/Api/Twitter/UserTest.php | 127 ++++++++++++++++++ 2 files changed, 127 insertions(+), 148 deletions(-) create mode 100644 tests/src/Factory/Api/Twitter/UserTest.php diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index f42b837e3d..a76a59f5cc 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -504,154 +504,6 @@ class ApiTest extends FixtureTest */ } - /** - * Test the api_get_user() function. - * - * @return void - */ - public function testApiGetUser() - { - // $user = api_get_user(); - // self::assertSelfUser($user); - // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']); - // self::assertEquals('6fdbe8', $user['profile_link_color']); - // self::assertEquals('ededed', $user['profile_background_color']); - } - - /** - * Test the api_get_user() function with a Frio schema. - * - * @return void - */ - public function testApiGetUserWithFrioSchema() - { - // $pConfig = $this->dice->create(IManagePersonalConfigValues::class); - // $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red'); - // $user = api_get_user(); - // self::assertSelfUser($user); - // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']); - // self::assertEquals('6fdbe8', $user['profile_link_color']); - // self::assertEquals('ededed', $user['profile_background_color']); - } - - /** - * Test the api_get_user() function with an empty Frio schema. - * - * @return void - */ - public function testApiGetUserWithEmptyFrioSchema() - { - // $pConfig = $this->dice->create(IManagePersonalConfigValues::class); - // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---'); - // $user = api_get_user(); - // self::assertSelfUser($user); - // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']); - // self::assertEquals('6fdbe8', $user['profile_link_color']); - // self::assertEquals('ededed', $user['profile_background_color']); - } - - /** - * Test the api_get_user() function with a custom Frio schema. - * - * @return void - */ - public function testApiGetUserWithCustomFrioSchema() - { - // $pConfig = $this->dice->create(IManagePersonalConfigValues::class); - // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---'); - // $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456'); - // $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456'); - // $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456'); - // $user = api_get_user(); - // self::assertSelfUser($user); - // self::assertEquals('123456', $user['profile_sidebar_fill_color']); - // self::assertEquals('123456', $user['profile_link_color']); - // self::assertEquals('123456', $user['profile_background_color']); - } - - /** - * Test the api_get_user() function with an user that is not allowed to use the API. - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testApiGetUserWithoutApiUser() - { - // api_get_user() with empty parameters is not used anymore - /* - $_SERVER['PHP_AUTH_USER'] = 'Test user'; - $_SERVER['PHP_AUTH_PW'] = 'password'; - BasicAuth::setCurrentUserID(); - self::assertFalse(api_get_user()); - */ - } - - /** - * Test the api_get_user() function with an user ID in a GET parameter. - * - * @return void - */ - public function testApiGetUserWithGetId() - { - // self::assertOtherUser(api_get_user()); - } - - /** - * Test the api_get_user() function with a wrong user ID in a GET parameter. - * - * @return void - */ - public function testApiGetUserWithWrongGetId() - { - // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - // self::assertOtherUser(api_get_user()); - } - - /** - * Test the api_get_user() function with an user name in a GET parameter. - * - * @return void - */ - public function testApiGetUserWithGetName() - { - // self::assertSelfUser(api_get_user()); - } - - /** - * Test the api_get_user() function with a profile URL in a GET parameter. - * - * @return void - */ - public function testApiGetUserWithGetUrl() - { - // self::assertSelfUser(api_get_user()); - } - - /** - * Test the api_get_user() function with an user ID in the API path. - * - * @return void - */ - public function testApiGetUserWithNumericCalledApi() - { - // global $called_api; - // $called_api = ['api_path']; - // DI::args()->setArgv(['', $this->otherUser['id'] . '.json']); - // self::assertOtherUser(api_get_user()); - } - - /** - * Test the api_get_user() function with the $called_api global variable. - * - * @return void - */ - public function testApiGetUserWithCalledApi() - { - // global $called_api; - // $called_api = ['api', 'api_path']; - // self::assertSelfUser(api_get_user()); - } - /** * Test the Arrays::walkRecursive() function. * diff --git a/tests/src/Factory/Api/Twitter/UserTest.php b/tests/src/Factory/Api/Twitter/UserTest.php new file mode 100644 index 0000000000..93de318e6a --- /dev/null +++ b/tests/src/Factory/Api/Twitter/UserTest.php @@ -0,0 +1,127 @@ +createFromUserId(ApiTest::SELF_USER['id']); + $user = $userObj->toArray(); + + $this->assertSelfUser($user); + } + + /** + * Test the api_get_user() function with a Frio schema. + * + * @return void + */ + public function testApiGetUserWithFrioSchema() + { + $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.'); + + /* + DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', 'red'); + + $userFactory = new User(DI::logger(), DI::twitterStatus()); + $user = $userFactory->createFromUserId(42); + + $this->assertSelfUser($user->toArray()); + self::assertEquals('708fa0', $user['profile_sidebar_fill_color']); + self::assertEquals('6fdbe8', $user['profile_link_color']); + self::assertEquals('ededed', $user['profile_background_color']); + */ + } + + /** + * Test the api_get_user() function with an empty Frio schema. + * + * @return void + */ + public function testApiGetUserWithEmptyFrioSchema() + { + $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.'); + + /* + DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', '---'); + + $userFactory = new User(DI::logger(), DI::twitterStatus()); + $user = $userFactory->createFromUserId(42); + + $this->assertSelfUser($user->toArray()); + self::assertEquals('708fa0', $user['profile_sidebar_fill_color']); + self::assertEquals('6fdbe8', $user['profile_link_color']); + self::assertEquals('ededed', $user['profile_background_color']); + */ + } + + /** + * Test the api_get_user() function with a custom Frio schema. + * + * @return void + */ + public function testApiGetUserWithCustomFrioSchema() + { + $this->markTestIncomplete('Needs missing fields for profile colors at API User object first.'); + + /* + DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'schema', '---'); + DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'nav_bg', '#123456'); + DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'link_color', '#123456'); + DI::pConfig()->set(ApiTest::SELF_USER['id'], 'frio', 'background_color', '#123456'); + + $userFactory = new User(DI::logger(), DI::twitterStatus()); + $user = $userFactory->createFromUserId(42); + + $this->assertSelfUser($user->toArray()); + self::assertEquals('123456', $user['profile_sidebar_fill_color']); + self::assertEquals('123456', $user['profile_link_color']); + self::assertEquals('123456', $user['profile_background_color']); + */ + } + + /** + * Test the api_get_user() function with a wrong user ID in a GET parameter. + * + * @return void + */ + public function testApiGetUserWithWrongGetId() + { + $userFactory = new User(DI::logger(), DI::twitterStatus()); + $userObj = $userFactory->createFromUserId(-1); + $user = $userObj->toArray(); + + self::assertEquals(0, $user['id']); + self::assertEquals(0, $user['uid']); + self::assertEquals(0, $user['cid']); + self::assertEquals(0, $user['pid']); + self::assertEmpty($user['name']); + } +} From f0b97d8e13b4ed0a1def987ae4d41cfd1c4f7180 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 20:51:21 +0100 Subject: [PATCH 09/23] Move API User tests --- tests/legacy/ApiTest.php | 10 +--------- tests/src/Factory/Api/Twitter/UserTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index a76a59f5cc..eda1c6fdbe 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -153,15 +153,7 @@ class ApiTest extends FixtureTest self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID()); } - /** - * Test the api_user() function with an unallowed user. - * - * @return void - */ - public function testApiUserWithUnallowedUser() - { - // self::assertEquals(false, api_user()); - } + /** * Test the api_source() function. diff --git a/tests/src/Factory/Api/Twitter/UserTest.php b/tests/src/Factory/Api/Twitter/UserTest.php index 93de318e6a..a39055a91b 100644 --- a/tests/src/Factory/Api/Twitter/UserTest.php +++ b/tests/src/Factory/Api/Twitter/UserTest.php @@ -124,4 +124,16 @@ class UserTest extends FixtureTest self::assertEquals(0, $user['pid']); self::assertEmpty($user['name']); } + + /** + * Test the api_user() function with an unallowed user. + * + * @return void + */ + public function testApiUserWithUnallowedUser() + { + self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first'); + + // self::assertEquals(false, api_user()); + } } From 6412484fa6f45077da783dade5efe8202a0d7984 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 21:07:20 +0100 Subject: [PATCH 10/23] Move API DirectMessage tests --- src/Factory/Api/Twitter/DirectMessage.php | 2 +- tests/datasets/mail/mail.fixture.php | 4 +- tests/legacy/ApiTest.php | 79 --------------- .../Factory/Api/Twitter/DirectMessageTest.php | 95 +++++++++++++++++++ .../Friendica/DirectMessages/SearchTest.php | 2 +- 5 files changed, 99 insertions(+), 83 deletions(-) create mode 100644 tests/src/Factory/Api/Twitter/DirectMessageTest.php diff --git a/src/Factory/Api/Twitter/DirectMessage.php b/src/Factory/Api/Twitter/DirectMessage.php index f2a4771d37..07d3367b01 100644 --- a/src/Factory/Api/Twitter/DirectMessage.php +++ b/src/Factory/Api/Twitter/DirectMessage.php @@ -51,7 +51,7 @@ class DirectMessage extends BaseFactory * * @param int $id Mail id * @param int $uid Mail user - * @param string $text_mode Either empty, "html" or "text" + * @param string $text_mode Either empty, "html" or "plain" * * @return \Friendica\Object\Api\Twitter\DirectMessage */ diff --git a/tests/datasets/mail/mail.fixture.php b/tests/datasets/mail/mail.fixture.php index 215356beaa..74f8bc1300 100644 --- a/tests/datasets/mail/mail.fixture.php +++ b/tests/datasets/mail/mail.fixture.php @@ -10,8 +10,8 @@ return [ 'thr-parent-id' => 44, 'guid' => '123456', 'from-name' => 'Tester', - 'title' => 'test message', - 'body' => 'this is a test', + 'title' => 'item_title', + 'body' => '[b]item_body[/b]', ], ], ]; diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index eda1c6fdbe..db43fde421 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -679,85 +679,6 @@ class ApiTest extends FixtureTest // api_statuses_mediap('json'); } - /** - * Test the api_format_messages() function. - * - * @return void - */ - public function testApiFormatMessages() - { - /* - $result = api_format_messages( - ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'], - ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'], - ['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name'] - ); - self::assertEquals('item_title' . "\n" . 'item_body', $result['text']); - self::assertEquals(1, $result['id']); - self::assertEquals(2, $result['recipient_id']); - self::assertEquals(3, $result['sender_id']); - self::assertEquals('recipient_name', $result['recipient_screen_name']); - self::assertEquals('sender_name', $result['sender_screen_name']); - */ - } - - /** - * Test the api_format_messages() function with HTML. - * - * @return void - */ - public function testApiFormatMessagesWithHtmlText() - { - /* - $_GET['getText'] = 'html'; - $result = api_format_messages( - ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'], - ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'], - ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name'] - ); - self::assertEquals('item_title', $result['title']); - self::assertEquals('item_body', $result['text']); - */ - } - - /** - * Test the api_format_messages() function with plain text. - * - * @return void - */ - public function testApiFormatMessagesWithPlainText() - { - /* - $_GET['getText'] = 'plain'; - $result = api_format_messages( - ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'], - ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'], - ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name'] - ); - self::assertEquals('item_title', $result['title']); - self::assertEquals('item_body', $result['text']); - */ - } - - /** - * Test the api_format_messages() function with the getUserObjects GET parameter set to false. - * - * @return void - */ - public function testApiFormatMessagesWithoutUserObjects() - { - /* - $_GET['getUserObjects'] = 'false'; - $result = api_format_messages( - ['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'], - ['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'], - ['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name'] - ); - self::assertTrue(!isset($result['sender'])); - self::assertTrue(!isset($result['recipient'])); - */ - } - /** * Test the api_convert_item() function. * diff --git a/tests/src/Factory/Api/Twitter/DirectMessageTest.php b/tests/src/Factory/Api/Twitter/DirectMessageTest.php new file mode 100644 index 0000000000..9cc7560708 --- /dev/null +++ b/tests/src/Factory/Api/Twitter/DirectMessageTest.php @@ -0,0 +1,95 @@ +loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba()); + $ids = DI::dba()->selectToArray('mail', ['id']); + $id = $ids[0]['id']; + + $directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + $directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id']); + $directMessage = $directMessageObj->toArray(); + + self::assertEquals('item_title' . "\n" . 'item_body', $directMessage['text']); + self::assertIsInt($directMessage['id']); + self::assertIsInt($directMessage['recipient_id']); + self::assertIsInt($directMessage['sender_id']); + self::assertEquals('selfcontact', $directMessage['recipient_screen_name']); + self::assertEquals('friendcontact', $directMessage['sender_screen_name']); + } + + /** + * Test the api_format_messages() function with HTML. + * + * @return void + */ + public function testApiFormatMessagesWithHtmlText() + { + $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba()); + $ids = DI::dba()->selectToArray('mail', ['id']); + $id = $ids[0]['id']; + + $directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + $directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'html'); + $directMessage = $directMessageObj->toArray(); + + self::assertEquals('item_title', $directMessage['title']); + self::assertEquals('item_body', $directMessage['text']); + } + + /** + * Test the api_format_messages() function with plain text. + * + * @return void + */ + public function testApiFormatMessagesWithPlainText() + { + $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba()); + $ids = DI::dba()->selectToArray('mail', ['id']); + $id = $ids[0]['id']; + + $directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + $directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain'); + $directMessage = $directMessageObj->toArray(); + + self::assertEquals('item_title', $directMessage['title']); + self::assertEquals('item_body', $directMessage['text']); + } + + /** + * Test the api_format_messages() function with the getUserObjects GET parameter set to false. + * + * @return void + */ + public function testApiFormatMessagesWithoutUserObjects() + { + self::markTestIncomplete('Needs processing of "getUserObjects" first'); + + /* + $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba()); + $ids = DI::dba()->selectToArray('mail', ['id']); + $id = $ids[0]['id']; + + $directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); + $directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain', $$GETUSEROBJECTS$$); + $directMessage = $directMessageObj->toArray(); + + self::assertTrue(!isset($directMessage['sender'])); + self::assertTrue(!isset($directMessage['recipient'])); + */ + } +} diff --git a/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php b/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php index c66a1f42ed..9fe8f7ca70 100644 --- a/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php +++ b/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php @@ -52,7 +52,7 @@ class SearchTest extends ApiTest $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser()); $search = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $search->run(['searchstring' => 'test']); + $response = $search->run(['searchstring' => 'item_body']); $json = $this->toJson($response); From c03ddf08914358daac8b354f06284dcb8e8eb90f Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 21:52:18 +0100 Subject: [PATCH 11/23] Move API Status tests --- tests/datasets/api.fixture.php | 103 ++++++++++++++++++- tests/legacy/ApiTest.php | 87 ---------------- tests/src/Factory/Api/Twitter/StatusTest.php | 85 +++++++++++++++ 3 files changed, 187 insertions(+), 88 deletions(-) create mode 100644 tests/src/Factory/Api/Twitter/StatusTest.php diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 5f87159c49..a764c31a7b 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -105,7 +105,11 @@ return [ 'uri' => '6', 'guid' => '6', ], - + [ + 'id' => 7, + 'uri' => '7', + 'guid' => '7', + ], [ 'id' => 42, 'uri' => 'http://localhost/profile/selfcontact', @@ -342,6 +346,34 @@ return [ 'body' => 'Friend user status', 'plink' => 'http://localhost/display/6', ], + [ + 'uri-id' => 7, + 'title' => 'item_title', + 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' . + 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' . + 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' . + 'laudantium atque commodi alias voluptatem non possimus aperiam ' . + 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' . + 'repellendus quibusdam et et inventore mollitia rerum sit autem ' . + 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' . + 'veritatis nihil distinctio qui eum repellat officia illum quos ' . + 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' . + 'omnis exercitationem quo magnam consequatur maxime aut illum ' . + 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' . + 'temporibus corporis ratione blanditiis perspiciatis impedit ' . + 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' . + 'sunt consequatur inventore dolor officiis pariatur doloremque ' . + 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' . + 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' . + 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' . + 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' . + 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' . + 'repellat officia illum quos impedit quam iste esse unde qui ' . + 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' . + 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' . + 'et sed beatae nihil ullam temporibus corporis ratione blanditiis', + 'plink' => 'http://localhost/display/6', + ], ], 'post' => [ [ @@ -434,6 +466,21 @@ return [ 'visible' => 1, 'deleted' => 0, ], + [ + 'uri-id' => 7, + 'parent-uri-id' => 7, + 'thr-parent-id' => 7, + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'owner-id' => 42, + 'author-id' => 44, + 'causer-id' => 44, + 'vid' => 8, + 'private' => Item::PUBLIC, + 'global' => true, + 'visible' => 1, + 'deleted' => 0, + ], ], 'post-user' => [ [ @@ -687,6 +734,27 @@ return [ 'deleted' => 0, 'wall' => 0, ], + [ + 'id' => 13, + 'uri-id' => 7, + 'visible' => 1, + 'contact-id' => 44, + 'author-id' => 44, + 'owner-id' => 42, + 'causer-id' => 44, + 'uid' => 0, + 'vid' => 8, + 'unseen' => 0, + 'parent-uri-id' => 7, + 'thr-parent-id' => 7, + 'private' => Item::PUBLIC, + 'global' => true, + 'gravity' => GRAVITY_PARENT, + 'network' => Protocol::DFRN, + 'origin' => 0, + 'deleted' => 0, + 'wall' => 0, + ], ], 'post-thread' => [ [ @@ -710,6 +778,13 @@ return [ 'causer-id' => 44, 'network' => Protocol::DFRN, ], + [ + 'uri-id' => 7, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'network' => Protocol::DFRN, + ], ], 'post-thread-user' => [ [ @@ -790,6 +865,32 @@ return [ 'starred' => 0, 'origin' => 0, ], + [ + 'uri-id' => 7, + 'uid' => 42, + 'wall' => 1, + 'post-user-id' => 7, + 'author-id' => 44, + 'owner-id' => 44, + 'causer-id' => 44, + 'contact-id' => 44, + 'network' => Protocol::DFRN, + 'starred' => 0, + 'origin' => 1, + ], + [ + 'uri-id' => 7, + '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, + ], ], 'notify' => [ [ diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index db43fde421..206dff2a89 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -679,93 +679,6 @@ class ApiTest extends FixtureTest // api_statuses_mediap('json'); } - /** - * Test the api_convert_item() function. - * - * @return void - */ - public function testApiConvertItem() - { - /* - $result = api_convert_item( - [ - 'network' => 'feed', - 'title' => 'item_title', - 'uri-id' => 1, - // We need a long string to test that it is correctly cut - 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' . - 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' . - 'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' . - 'laudantium atque commodi alias voluptatem non possimus aperiam ' . - 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' . - 'repellendus quibusdam et et inventore mollitia rerum sit autem ' . - 'pariatur maiores ipsum accusantium perferendis vel sit possimus ' . - 'veritatis nihil distinctio qui eum repellat officia illum quos ' . - 'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' . - 'omnis exercitationem quo magnam consequatur maxime aut illum ' . - 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' . - 'temporibus corporis ratione blanditiis perspiciatis impedit ' . - 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' . - 'sunt consequatur inventore dolor officiis pariatur doloremque ' . - 'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' . - 'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' . - 'amet fugit quia aliquid praesentium repellendus quibusdam et et ' . - 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' . - 'perferendis vel sit possimus veritatis nihil distinctio qui eum ' . - 'repellat officia illum quos impedit quam iste esse unde qui ' . - 'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' . - 'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' . - 'et sed beatae nihil ullam temporibus corporis ratione blanditiis', - 'plink' => 'item_plink' - ] - ); - self::assertStringStartsWith('item_title', $result['text']); - self::assertStringStartsWith('

item_title


perspiciatis impedit voluptatem', $result['html']); - */ - } - - /** - * Test the api_convert_item() function with an empty item body. - * - * @return void - */ - public function testApiConvertItemWithoutBody() - { - /* - $result = api_convert_item( - [ - 'network' => 'feed', - 'title' => 'item_title', - 'uri-id' => -1, - 'body' => '', - 'plink' => 'item_plink' - ] - ); - self::assertEquals("item_title", $result['text']); - self::assertEquals('

item_title


item_plink', $result['html']); - */ - } - - /** - * Test the api_convert_item() function with the title in the body. - * - * @return void - */ - public function testApiConvertItemWithTitleInBody() - { - /* - $result = api_convert_item( - [ - 'title' => 'item_title', - 'body' => 'item_title item_body', - 'uri-id' => 1, - ] - ); - self::assertEquals('item_title item_body', $result['text']); - self::assertEquals('

item_title


item_title item_body', $result['html']); - */ - } - /** * Test the api_get_attachments() function. * diff --git a/tests/src/Factory/Api/Twitter/StatusTest.php b/tests/src/Factory/Api/Twitter/StatusTest.php new file mode 100644 index 0000000000..52814baba8 --- /dev/null +++ b/tests/src/Factory/Api/Twitter/StatusTest.php @@ -0,0 +1,85 @@ +createFromItemId(13, ApiTest::SELF_USER['id']); + $status = $statusObj->toArray(); + + self::assertStringStartsWith('item_title', $status['text']); + self::assertStringStartsWith('

item_title


perspiciatis impedit voluptatem', $status['html']); + } + + /** + * Test the api_convert_item() function with an empty item body. + * + * @return void + */ + public function testApiConvertItemWithoutBody() + { + self::markTestIncomplete('Needs a dataset first'); + + /* + $result = api_convert_item( + [ + 'network' => 'feed', + 'title' => 'item_title', + 'uri-id' => -1, + 'body' => '', + 'plink' => 'item_plink' + ] + ); + self::assertEquals("item_title", $result['text']); + self::assertEquals('

item_title


item_plink', $result['html']); + */ + } + + /** + * Test the api_convert_item() function with the title in the body. + * + * @return void + */ + public function testApiConvertItemWithTitleInBody() + { + self::markTestIncomplete('Needs a dataset first'); + + /* + $result = api_convert_item( + [ + 'title' => 'item_title', + 'body' => 'item_title item_body', + 'uri-id' => 1, + ] + ); + self::assertEquals('item_title item_body', $result['text']); + self::assertEquals('

item_title


item_title item_body', $result['html']); + */ + } +} From 0b08730a0b2cde30f4c392f8b22b536b9b512d80 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 21:56:22 +0100 Subject: [PATCH 12/23] Move getAttachement tests --- tests/legacy/ApiTest.php | 32 -------------------- tests/src/Model/Post/MediaTest.php | 48 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 tests/src/Model/Post/MediaTest.php diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 206dff2a89..fa1afbe6ed 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -679,39 +679,7 @@ class ApiTest extends FixtureTest // api_statuses_mediap('json'); } - /** - * Test the api_get_attachments() function. - * - * @return void - */ - public function testApiGetAttachments() - { - // $body = 'body'; - // self::assertEmpty(api_get_attachments($body, 0)); - } - /** - * Test the api_get_attachments() function with an img tag. - * - * @return void - */ - public function testApiGetAttachmentsWithImage() - { - // $body = '[img]http://via.placeholder.com/1x1.png[/img]'; - // self::assertIsArray(api_get_attachments($body, 0)); - } - - /** - * Test the api_get_attachments() function with an img tag and an AndStatus user agent. - * - * @return void - */ - public function testApiGetAttachmentsWithImageAndAndStatus() - { - // $_SERVER['HTTP_USER_AGENT'] = 'AndStatus'; - // $body = '[img]http://via.placeholder.com/1x1.png[/img]'; - // self::assertIsArray(api_get_attachments($body, 0)); - } /** * Test the api_get_entitities() function. diff --git a/tests/src/Model/Post/MediaTest.php b/tests/src/Model/Post/MediaTest.php new file mode 100644 index 0000000000..ee675524b8 --- /dev/null +++ b/tests/src/Model/Post/MediaTest.php @@ -0,0 +1,48 @@ + Date: Thu, 30 Dec 2021 21:57:55 +0100 Subject: [PATCH 13/23] Remove deprectated mediap tests --- tests/legacy/ApiTest.php | 43 ---------------------------------------- 1 file changed, 43 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index fa1afbe6ed..955a25235a 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -638,49 +638,6 @@ class ApiTest extends FixtureTest ); } - /** - * Test the api_statuses_mediap() function. - * - * @return void - */ - public function testApiStatusesMediap() - { - /* - DI::args()->setArgc(2); - - $_FILES = [ - 'media' => [ - 'id' => 666, - 'size' => 666, - 'width' => 666, - 'height' => 666, - 'tmp_name' => $this->getTempImage(), - 'name' => 'spacer.png', - 'type' => 'image/png' - ] - ]; - $_GET['status'] = 'Status content'; - - $result = api_statuses_mediap('json'); - self::assertStatus($result['status']); - */ - } - - /** - * Test the api_statuses_mediap() function without an authenticated user. - * - * @return void - */ - public function testApiStatusesMediapWithoutAuthenticatedUser() - { - // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class); - // BasicAuth::setCurrentUserID(); - // $_SESSION['authenticated'] = false; - // api_statuses_mediap('json'); - } - - - /** * Test the api_get_entitities() function. * From 2c15fb03fff8c9f295c017038ea542b1b817748e Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 22:02:57 +0100 Subject: [PATCH 14/23] Move API status tests --- tests/legacy/ApiTest.php | 29 -------------------- tests/src/Factory/Api/Twitter/StatusTest.php | 26 ++++++++++++++++++ 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 955a25235a..bc2837225f 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -638,35 +638,6 @@ class ApiTest extends FixtureTest ); } - /** - * Test the api_get_entitities() function. - * - * @return void - */ - public function testApiGetEntitities() - { - // $text = 'text'; - // self::assertIsArray(api_get_entitities($text, 'bbcode', 0)); - } - - /** - * Test the api_get_entitities() function with the include_entities parameter. - * - * @return void - */ - public function testApiGetEntititiesWithIncludeEntities() - { - /* - $_REQUEST['include_entities'] = 'true'; - $text = 'text'; - $result = api_get_entitities($text, 'bbcode', 0); - self::assertIsArray($result['hashtags']); - self::assertIsArray($result['symbols']); - self::assertIsArray($result['urls']); - self::assertIsArray($result['user_mentions']); - */ - } - /** * Test the api_format_items_embeded_images() function. * diff --git a/tests/src/Factory/Api/Twitter/StatusTest.php b/tests/src/Factory/Api/Twitter/StatusTest.php index 52814baba8..b4ba6bf28a 100644 --- a/tests/src/Factory/Api/Twitter/StatusTest.php +++ b/tests/src/Factory/Api/Twitter/StatusTest.php @@ -82,4 +82,30 @@ class StatusTest extends FixtureTest self::assertEquals('

item_title


item_title item_body', $result['html']); */ } + + /** + * Test the api_get_entitities() function. + * + * @return void + */ + public function testApiGetEntititiesWithIncludeEntities() + { + $hashTagFac = new Hashtag(DI::logger()); + $mediaFac = new Media(DI::logger(), DI::baseUrl()); + $urlFac = new Url(DI::logger()); + $mentionFac = new Mention(DI::logger(), DI::baseUrl()); + $activitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); + $attachmentFac = new Attachment(DI::logger()); + + $statusFac = new Status(DI::logger(), DI::dba(), DI::twitterUser(), $hashTagFac, $mediaFac, $urlFac, $mentionFac, $activitiesFac, $attachmentFac); + $statusObj = $statusFac->createFromItemId(13, ApiTest::SELF_USER['id'], true); + $status = $statusObj->toArray(); + + self::assertIsArray($status['entities']); + self::assertIsArray($status['extended_entities']); + self::assertIsArray($status['entities']['hashtags']); + self::assertIsArray($status['entities']['media']); + self::assertIsArray($status['entities']['urls']); + self::assertIsArray($status['entities']['user_mentions']); + } } From 2e221943d48bd123dbd3eb1de8e110aaa5603b46 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 22:08:46 +0100 Subject: [PATCH 15/23] Move ApiResponse & Twitter Status tests --- tests/legacy/ApiTest.php | 133 ---------------- .../src/Factory/Api/Twitter/ActvitiesTest.php | 48 ++++++ tests/src/Module/Api/ApiResponseTest.php | 146 ++++++++++++++++++ 3 files changed, 194 insertions(+), 133 deletions(-) create mode 100644 tests/src/Factory/Api/Twitter/ActvitiesTest.php diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index bc2837225f..e4427c9194 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -8,7 +8,6 @@ namespace Friendica\Test\legacy; use Friendica\App; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\DI; -use Friendica\Module\Api\ApiResponse; use Friendica\Module\BaseApi; use Friendica\Security\BasicAuth; use Friendica\Test\FixtureTest; @@ -536,107 +535,7 @@ class ApiTest extends FixtureTest ); } - /** - * Test the BaseApi::reformatXML() function. - * - * @return void - */ - public function testApiReformatXml() - { - $item = true; - $key = ''; - self::assertTrue(ApiResponse::reformatXML($item, $key)); - self::assertEquals('true', $item); - } - /** - * Test the BaseApi::reformatXML() function with a statusnet_api key. - * - * @return void - */ - public function testApiReformatXmlWithStatusnetKey() - { - $item = ''; - $key = 'statusnet_api'; - self::assertTrue(ApiResponse::reformatXML($item, $key)); - self::assertEquals('statusnet:api', $key); - } - - /** - * Test the BaseApi::reformatXML() function with a friendica_api key. - * - * @return void - */ - public function testApiReformatXmlWithFriendicaKey() - { - $item = ''; - $key = 'friendica_api'; - self::assertTrue(ApiResponse::reformatXML($item, $key)); - self::assertEquals('friendica:api', $key); - } - - /** - * Test the BaseApi::createXML() function. - * - * @return void - */ - public function testApiCreateXml() - { - self::assertEquals( - '' . "\n" . - '' . "\n" . - ' some_data' . "\n" . - '' . "\n", - DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element') - ); - } - - /** - * Test the BaseApi::createXML() function without any XML namespace. - * - * @return void - */ - public function testApiCreateXmlWithoutNamespaces() - { - self::assertEquals( - '' . "\n" . - '' . "\n" . - ' some_data' . "\n" . - '' . "\n", - DI::apiResponse()->createXML(['data' => ['some_data']], 'ok') - ); - } - - /** - * Test the BaseApi::formatData() function. - * - * @return void - */ - public function testApiFormatData() - { - $data = ['some_data']; - self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data)); - } - - /** - * Test the BaseApi::formatData() function with an XML result. - * - * @return void - */ - public function testApiFormatDataWithXml() - { - self::assertEquals( - '' . "\n" . - '' . "\n" . - ' some_data' . "\n" . - '' . "\n", - DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']]) - ); - } /** * Test the api_format_items_embeded_images() function. @@ -653,38 +552,6 @@ class ApiTest extends FixtureTest */ } - /** - * Test the api_format_items_activities() function. - * - * @return void - */ - public function testApiFormatItemsActivities() - { - $item = ['uid' => 0, 'uri-id' => 1]; - $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']); - self::assertArrayHasKey('like', $result); - self::assertArrayHasKey('dislike', $result); - self::assertArrayHasKey('attendyes', $result); - self::assertArrayHasKey('attendno', $result); - self::assertArrayHasKey('attendmaybe', $result); - } - - /** - * Test the api_format_items_activities() function with an XML result. - * - * @return void - */ - public function testApiFormatItemsActivitiesWithXml() - { - $item = ['uid' => 0, 'uri-id' => 1]; - $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml'); - self::assertArrayHasKey('friendica:like', $result); - self::assertArrayHasKey('friendica:dislike', $result); - self::assertArrayHasKey('friendica:attendyes', $result); - self::assertArrayHasKey('friendica:attendno', $result); - self::assertArrayHasKey('friendica:attendmaybe', $result); - } - /** * Test the api_format_items() function. * @doesNotPerformAssertions diff --git a/tests/src/Factory/Api/Twitter/ActvitiesTest.php b/tests/src/Factory/Api/Twitter/ActvitiesTest.php new file mode 100644 index 0000000000..d213843293 --- /dev/null +++ b/tests/src/Factory/Api/Twitter/ActvitiesTest.php @@ -0,0 +1,48 @@ + 0, 'uri-id' => 1]; + + $friendicaActivitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); + $result = $friendicaActivitiesFac->createFromUriId($item['uri-id'], $item['uid']); + + self::assertArrayHasKey('like', $result); + self::assertArrayHasKey('dislike', $result); + self::assertArrayHasKey('attendyes', $result); + self::assertArrayHasKey('attendno', $result); + self::assertArrayHasKey('attendmaybe', $result); + } + + /** + * Test the api_format_items_activities() function with an XML result. + * + * @return void + */ + public function testApiFormatItemsActivitiesWithXml() + { + $item = ['uid' => 0, 'uri-id' => 1]; + + $friendicaActivitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); + $result = $friendicaActivitiesFac->createFromUriId($item['uri-id'], $item['uid'], 'xml'); + + self::assertArrayHasKey('friendica:like', $result); + self::assertArrayHasKey('friendica:dislike', $result); + self::assertArrayHasKey('friendica:attendyes', $result); + self::assertArrayHasKey('friendica:attendno', $result); + self::assertArrayHasKey('friendica:attendmaybe', $result); + } +} diff --git a/tests/src/Module/Api/ApiResponseTest.php b/tests/src/Module/Api/ApiResponseTest.php index 99e3a8d5da..3599b8f413 100644 --- a/tests/src/Module/Api/ApiResponseTest.php +++ b/tests/src/Module/Api/ApiResponseTest.php @@ -113,4 +113,150 @@ class ApiResponseTest extends MockedTest self::assertEquals('{"error":"API endpoint %s %s is not implemented","error_description":"The API endpoint is currently not implemented but might be in the future."}', $response->getContent()); } + + /** + * Test the BaseApi::reformatXML() function. + * + * @return void + */ + public function testApiReformatXml() + { + $item = true; + $key = ''; + self::assertTrue(ApiResponse::reformatXML($item, $key)); + self::assertEquals('true', $item); + } + + /** + * Test the BaseApi::reformatXML() function with a statusnet_api key. + * + * @return void + */ + public function testApiReformatXmlWithStatusnetKey() + { + $item = ''; + $key = 'statusnet_api'; + self::assertTrue(ApiResponse::reformatXML($item, $key)); + self::assertEquals('statusnet:api', $key); + } + + /** + * Test the BaseApi::reformatXML() function with a friendica_api key. + * + * @return void + */ + public function testApiReformatXmlWithFriendicaKey() + { + $item = ''; + $key = 'friendica_api'; + self::assertTrue(ApiResponse::reformatXML($item, $key)); + self::assertEquals('friendica:api', $key); + } + + /** + * Test the BaseApi::createXML() function. + * + * @return void + */ + public function testApiCreateXml() + { + $l10n = \Mockery::mock(L10n::class); + $l10n->shouldReceive('t')->andReturnUsing(function ($args) { + return $args; + }); + $args = \Mockery::mock(Arguments::class); + $args->shouldReceive('getQueryString')->andReturn(''); + $baseUrl = \Mockery::mock(BaseURL::class); + $twitterUser = \Mockery::mock(User::class); + + $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser); + + self::assertEquals( + '' . "\n" . + '' . "\n" . + ' some_data' . "\n" . + '' . "\n", + $response->createXML(['data' => ['some_data']], 'root_element') + ); + } + + /** + * Test the BaseApi::createXML() function without any XML namespace. + * + * @return void + */ + public function testApiCreateXmlWithoutNamespaces() + { + $l10n = \Mockery::mock(L10n::class); + $l10n->shouldReceive('t')->andReturnUsing(function ($args) { + return $args; + }); + $args = \Mockery::mock(Arguments::class); + $args->shouldReceive('getQueryString')->andReturn(''); + $baseUrl = \Mockery::mock(BaseURL::class); + $twitterUser = \Mockery::mock(User::class); + + $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser); + + self::assertEquals( + '' . "\n" . + '' . "\n" . + ' some_data' . "\n" . + '' . "\n", + $response->createXML(['data' => ['some_data']], 'ok') + ); + } + + /** + * Test the BaseApi::formatData() function. + * + * @return void + */ + public function testApiFormatData() + { + $l10n = \Mockery::mock(L10n::class); + $l10n->shouldReceive('t')->andReturnUsing(function ($args) { + return $args; + }); + $args = \Mockery::mock(Arguments::class); + $args->shouldReceive('getQueryString')->andReturn(''); + $baseUrl = \Mockery::mock(BaseURL::class); + $twitterUser = \Mockery::mock(User::class); + + $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser); + + $data = ['some_data']; + self::assertEquals($data, $response->formatData('root_element', 'json', $data)); + } + + /** + * Test the BaseApi::formatData() function with an XML result. + * + * @return void + */ + public function testApiFormatDataWithXml() + { + $l10n = \Mockery::mock(L10n::class); + $l10n->shouldReceive('t')->andReturnUsing(function ($args) { + return $args; + }); + $args = \Mockery::mock(Arguments::class); + $args->shouldReceive('getQueryString')->andReturn(''); + $baseUrl = \Mockery::mock(BaseURL::class); + $twitterUser = \Mockery::mock(User::class); + + $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser); + + self::assertEquals( + '' . "\n" . + '' . "\n" . + ' some_data' . "\n" . + '' . "\n", + $response->formatData('root_element', 'xml', ['data' => ['some_data']]) + ); + } } From 29dbfb58c776451f4ab61608be3673e6953f1e4e Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 22:17:03 +0100 Subject: [PATCH 16/23] Move another API status tests --- tests/legacy/ApiTest.php | 32 -------------------- tests/src/Factory/Api/Twitter/StatusTest.php | 24 +++++++++++++++ 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index e4427c9194..2186e36d67 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -535,8 +535,6 @@ class ApiTest extends FixtureTest ); } - - /** * Test the api_format_items_embeded_images() function. * @@ -552,36 +550,6 @@ class ApiTest extends FixtureTest */ } - /** - * Test the api_format_items() function. - * @doesNotPerformAssertions - */ - public function testApiFormatItems() - { - /* - $items = Post::selectToArray([], ['uid' => 42]); - foreach ($items as $item) { - $status = api_format_item($item); - self::assertStatus($status); - } - */ - } - - /** - * Test the api_format_items() function with an XML result. - * @doesNotPerformAssertions - */ - public function testApiFormatItemsWithXml() - { - /* - $items = Post::selectToArray([], ['uid' => 42]); - foreach ($items as $item) { - $status = api_format_item($item, 'xml'); - self::assertStatus($status); - } - */ - } - /** * Test the api_lists_list() function. * diff --git a/tests/src/Factory/Api/Twitter/StatusTest.php b/tests/src/Factory/Api/Twitter/StatusTest.php index b4ba6bf28a..61dcb0a9cb 100644 --- a/tests/src/Factory/Api/Twitter/StatusTest.php +++ b/tests/src/Factory/Api/Twitter/StatusTest.php @@ -108,4 +108,28 @@ class StatusTest extends FixtureTest self::assertIsArray($status['entities']['urls']); self::assertIsArray($status['entities']['user_mentions']); } + + /** + * Test the api_format_items() function. + */ + public function testApiFormatItems() + { + $hashTagFac = new Hashtag(DI::logger()); + $mediaFac = new Media(DI::logger(), DI::baseUrl()); + $urlFac = new Url(DI::logger()); + $mentionFac = new Mention(DI::logger(), DI::baseUrl()); + $activitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); + $attachmentFac = new Attachment(DI::logger()); + + $statusFac = new Status(DI::logger(), DI::dba(), DI::twitterUser(), $hashTagFac, $mediaFac, $urlFac, $mentionFac, $activitiesFac, $attachmentFac); + + $posts = DI::dba()->selectToArray('post-view', ['uri-id']); + foreach ($posts as $item) { + $statusObj = $statusFac->createFromUriId($item['uri-id'], ApiTest::SELF_USER['id']); + $status = $statusObj->toArray(); + + self::assertIsInt($status['id']); + self::assertIsString($status['text']); + } + } } From 9d8a420391153a9c8f9ffaad75822c78bd06b67f Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 22:37:23 +0100 Subject: [PATCH 17/23] Move API RSS tests --- tests/legacy/ApiTest.php | 39 --------------- tests/src/Module/Api/ApiResponseTest.php | 64 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 39 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 2186e36d67..18989b2eb6 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -454,46 +454,7 @@ class ApiTest extends FixtureTest ); } - /** - * Test the api_rss_extra() function. - * - * @return void - */ - public function testApiRssExtra() - { - /* - $user_info = ['url' => 'user_url', 'lang' => 'en']; - $result = api_rss_extra([], $user_info); - self::assertEquals($user_info, $result['$user']); - self::assertEquals($user_info['url'], $result['$rss']['alternate']); - self::assertArrayHasKey('self', $result['$rss']); - self::assertArrayHasKey('base', $result['$rss']); - self::assertArrayHasKey('updated', $result['$rss']); - self::assertArrayHasKey('atom_updated', $result['$rss']); - self::assertArrayHasKey('language', $result['$rss']); - self::assertArrayHasKey('logo', $result['$rss']); - */ - } - /** - * Test the api_rss_extra() function without any user info. - * - * @return void - */ - public function testApiRssExtraWithoutUserInfo() - { - /* - $result = api_rss_extra([], null); - self::assertIsArray($result['$user']); - self::assertArrayHasKey('alternate', $result['$rss']); - self::assertArrayHasKey('self', $result['$rss']); - self::assertArrayHasKey('base', $result['$rss']); - self::assertArrayHasKey('updated', $result['$rss']); - self::assertArrayHasKey('atom_updated', $result['$rss']); - self::assertArrayHasKey('language', $result['$rss']); - self::assertArrayHasKey('logo', $result['$rss']); - */ - } /** * Test the Arrays::walkRecursive() function. diff --git a/tests/src/Module/Api/ApiResponseTest.php b/tests/src/Module/Api/ApiResponseTest.php index 3599b8f413..33239caf22 100644 --- a/tests/src/Module/Api/ApiResponseTest.php +++ b/tests/src/Module/Api/ApiResponseTest.php @@ -259,4 +259,68 @@ class ApiResponseTest extends MockedTest $response->formatData('root_element', 'xml', ['data' => ['some_data']]) ); } + + /** + * Test the api_rss_extra() function. + * + * @return void + */ + public function testApiRssExtra() + { + self::markTestIncomplete('Cannot mock it yet.'); + + /* + $user_info = ['url' => 'user_url', 'lang' => 'en']; + $userMock = \Mockery::mock(\Friendica\Object\Api\Twitter\User::class); + $userMock->shouldReceive('toArray')->andReturn($user_info); + + $l10n = \Mockery::mock(L10n::class); + $l10n->shouldReceive('t')->andReturnUsing(function ($args) { + return $args; + }); + $args = \Mockery::mock(Arguments::class); + $args->shouldReceive('getQueryString')->andReturn(''); + $baseUrl = \Mockery::mock(BaseURL::class); + $baseUrl->shouldReceive('__toString')->andReturn('https://friendica.local'); + $twitterUser = \Mockery::mock(User::class); + $twitterUser->shouldReceive('createFromContactId')->with(1)->andReturn($userMock); + + $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser); + + $result = $response->formatData('root_element', 'rss', ['data' => ['some_data']], 1); + + print_r($result); + + self::assertEquals($user_info, $result['$user']); + self::assertEquals($user_info['url'], $result['$rss']['alternate']); + self::assertArrayHasKey('self', $result['$rss']); + self::assertArrayHasKey('base', $result['$rss']); + self::assertArrayHasKey('updated', $result['$rss']); + self::assertArrayHasKey('atom_updated', $result['$rss']); + self::assertArrayHasKey('language', $result['$rss']); + self::assertArrayHasKey('logo', $result['$rss']); + */ + } + + /** + * Test the api_rss_extra() function without any user info. + * + * @return void + */ + public function testApiRssExtraWithoutUserInfo() + { + self::markTestIncomplete('Cannot mock it yet.'); + + /* + $result = api_rss_extra([], null); + self::assertIsArray($result['$user']); + self::assertArrayHasKey('alternate', $result['$rss']); + self::assertArrayHasKey('self', $result['$rss']); + self::assertArrayHasKey('base', $result['$rss']); + self::assertArrayHasKey('updated', $result['$rss']); + self::assertArrayHasKey('atom_updated', $result['$rss']); + self::assertArrayHasKey('language', $result['$rss']); + self::assertArrayHasKey('logo', $result['$rss']); + */ + } } From 14e7f12aa4243f767677ee716d77699f1de61434 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 30 Dec 2021 22:39:03 +0100 Subject: [PATCH 18/23] Remove deprecated tests --- tests/legacy/ApiTest.php | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 18989b2eb6..7d08b6ec99 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -454,8 +454,6 @@ class ApiTest extends FixtureTest ); } - - /** * Test the Arrays::walkRecursive() function. * @@ -496,21 +494,6 @@ class ApiTest extends FixtureTest ); } - /** - * Test the api_format_items_embeded_images() function. - * - * @return void - */ - public function testApiFormatItemsEmbededImages() - { - /* - self::assertEquals( - 'text ' . DI::baseUrl() . '/display/item_guid', - api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo') - ); - */ - } - /** * Test the api_lists_list() function. * @@ -548,17 +531,6 @@ class ApiTest extends FixtureTest api_lists_ownerships('json'); } - /** - * Test the api_statuses_f() function. - * - * @return void - */ - public function testApiStatusesFWithIncoming() - { - // $result = api_statuses_f('incoming'); - // self::assertArrayHasKey('user', $result); - } - /** * Test the api_fr_photos_list() function. * @@ -771,18 +743,6 @@ class ApiTest extends FixtureTest $this->markTestIncomplete(); } - /** - * Test the api_clean_plain_items() function. - * - * @return void - */ - public function testApiCleanPlainItems() - { - //$_REQUEST['include_entities'] = 'true'; - //$result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]'); - //self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result); - } - /** * Test the api_friendica_group_show() function. * From 2f13afb4c0547fb86856a45ed335c4762db105cb Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 1 Jan 2022 21:24:16 +0100 Subject: [PATCH 19/23] Fix database lock driver test --- tests/src/Core/Lock/DatabaseLockDriverTest.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tests/src/Core/Lock/DatabaseLockDriverTest.php b/tests/src/Core/Lock/DatabaseLockDriverTest.php index 3bf0a96ef3..56c7c35205 100644 --- a/tests/src/Core/Lock/DatabaseLockDriverTest.php +++ b/tests/src/Core/Lock/DatabaseLockDriverTest.php @@ -23,6 +23,7 @@ namespace Friendica\Test\src\Core\Lock; use Friendica\Core\Lock\Type\DatabaseLock; use Friendica\Core\Config\Factory\Config; +use Friendica\DI; use Friendica\Test\DatabaseTestTrait; use Friendica\Test\Util\Database\StaticDatabase; use Friendica\Test\Util\VFSTrait; @@ -48,20 +49,7 @@ class DatabaseLockDriverTest extends LockTest protected function getInstance() { - $logger = new NullLogger(); - $profiler = Mockery::mock(Profiler::class); - $profiler->shouldReceive('startRecording'); - $profiler->shouldReceive('stopRecording'); - $profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true); - - // load real config to avoid mocking every config-entry which is related to the Database class - $configFactory = new Config(); - $loader = (new Config())->createConfigFileLoader($this->root->url(), []); - $configCache = $configFactory->createCache($loader); - - $dba = new StaticDatabase($configCache, $profiler, $logger); - - return new DatabaseLock($dba, $this->pid); + return new DatabaseLock(DI::dba(), $this->pid); } protected function tearDown(): void From 4c77e99f8907b8dc22312f4fd9f5b85cdae2611b Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 1 Jan 2022 23:14:52 +0100 Subject: [PATCH 20/23] Add title to the text/html content for Twitter status object --- src/Factory/Api/Twitter/Status.php | 18 ++++++++++++++++-- src/Object/Api/Twitter/Status.php | 7 +++---- tests/src/Factory/Api/Twitter/StatusTest.php | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Factory/Api/Twitter/Status.php b/src/Factory/Api/Twitter/Status.php index 2db1cf1355..57547b0a35 100644 --- a/src/Factory/Api/Twitter/Status.php +++ b/src/Factory/Api/Twitter/Status.php @@ -119,7 +119,21 @@ class Status extends BaseFactory $friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => GRAVITY_COMMENT]); - $text = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']); + $text = ''; + + // Add the title to text / html if set + if (!empty($item['title'])) { + $text .= $item['title'] . ' '; + + $title = sprintf("[h4]%s[/h4]\n", $item['title']); + $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($title . $item['raw-body'] ?? $item['body']), BBCode::API); + $friendicaHtml = BBCode::convertForUriId($item['uri-id'], $title . $item['body'], BBCode::EXTERNAL); + } else { + $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API); + $friendicaHtml = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL); + } + + $text .= Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']); $text = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], $text, BBCode::API), 0)); @@ -190,6 +204,6 @@ class Status extends BaseFactory $entities = []; } - return new \Friendica\Object\Api\Twitter\Status($text, $item, $author, $owner, $retweeted, $quoted, $geo, $friendica_activities, $entities, $attachments, $friendica_comments, $liked); + return new \Friendica\Object\Api\Twitter\Status($text, $statusnetHtml, $friendicaHtml, $item, $author, $owner, $retweeted, $quoted, $geo, $friendica_activities, $entities, $attachments, $friendica_comments, $liked); } } diff --git a/src/Object/Api/Twitter/Status.php b/src/Object/Api/Twitter/Status.php index ed52deedb8..86ff6b6afd 100644 --- a/src/Object/Api/Twitter/Status.php +++ b/src/Object/Api/Twitter/Status.php @@ -23,7 +23,6 @@ namespace Friendica\Object\Api\Twitter; use Friendica\BaseDataTransferObject; use Friendica\Content\ContactSelector; -use Friendica\Content\Text\BBCode; use Friendica\Model\Item; use Friendica\Util\DateTimeFormat; @@ -99,7 +98,7 @@ class Status extends BaseDataTransferObject * @param array $item * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function __construct(string $text, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked) + public function __construct(string $text, string $statusnetHtml, string $friendicaHtml, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked) { $this->id = (int)$item['id']; $this->id_str = (string)$item['id']; @@ -117,8 +116,8 @@ class Status extends BaseDataTransferObject $this->text = $text; $this->friendica_title = $item['title']; - $this->statusnet_html = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API); - $this->friendica_html = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL); + $this->statusnet_html = $statusnetHtml; + $this->friendica_html = $friendicaHtml; $this->user = $author->toArray(); $this->friendica_author = $author->toArray(); $this->friendica_owner = $owner->toArray(); diff --git a/tests/src/Factory/Api/Twitter/StatusTest.php b/tests/src/Factory/Api/Twitter/StatusTest.php index 61dcb0a9cb..1073867ee2 100644 --- a/tests/src/Factory/Api/Twitter/StatusTest.php +++ b/tests/src/Factory/Api/Twitter/StatusTest.php @@ -34,7 +34,7 @@ class StatusTest extends FixtureTest $status = $statusObj->toArray(); self::assertStringStartsWith('item_title', $status['text']); - self::assertStringStartsWith('

item_title


perspiciatis impedit voluptatem', $status['html']); + self::assertStringStartsWith('

item_title


perspiciatis impedit voluptatem', $status['friendica_html']); } /** From e61ed419728999fcdaf8c79597b0490655e69867 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 2 Jan 2022 00:21:01 +0100 Subject: [PATCH 21/23] Add feedback (title/text/html) --- src/Factory/Api/Twitter/Status.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Factory/Api/Twitter/Status.php b/src/Factory/Api/Twitter/Status.php index 57547b0a35..f37d18a583 100644 --- a/src/Factory/Api/Twitter/Status.php +++ b/src/Factory/Api/Twitter/Status.php @@ -119,20 +119,18 @@ class Status extends BaseFactory $friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => GRAVITY_COMMENT]); - $text = ''; + $text = ''; + $title = ''; // Add the title to text / html if set if (!empty($item['title'])) { $text .= $item['title'] . ' '; - - $title = sprintf("[h4]%s[/h4]\n", $item['title']); - $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($title . $item['raw-body'] ?? $item['body']), BBCode::API); - $friendicaHtml = BBCode::convertForUriId($item['uri-id'], $title . $item['body'], BBCode::EXTERNAL); - } else { - $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API); - $friendicaHtml = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL); + $title = sprintf("[h4]%s[/h4]\n", $item['title']); } + $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($title . ($item['raw-body'] ?? $item['body'])), BBCode::API); + $friendicaHtml = BBCode::convertForUriId($item['uri-id'], $title . $item['body'], BBCode::EXTERNAL); + $text .= Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']); $text = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], $text, BBCode::API), 0)); From adf0d7bc954dca344df78f8b2356b47ca7419ffa Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 2 Jan 2022 00:21:38 +0100 Subject: [PATCH 22/23] Fix typo --- .../Api/Twitter/{ActvitiesTest.php => ActivitiesTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/src/Factory/Api/Twitter/{ActvitiesTest.php => ActivitiesTest.php} (97%) diff --git a/tests/src/Factory/Api/Twitter/ActvitiesTest.php b/tests/src/Factory/Api/Twitter/ActivitiesTest.php similarity index 97% rename from tests/src/Factory/Api/Twitter/ActvitiesTest.php rename to tests/src/Factory/Api/Twitter/ActivitiesTest.php index d213843293..43f976e353 100644 --- a/tests/src/Factory/Api/Twitter/ActvitiesTest.php +++ b/tests/src/Factory/Api/Twitter/ActivitiesTest.php @@ -6,7 +6,7 @@ use Friendica\DI; use Friendica\Factory\Api\Friendica\Activities; use Friendica\Test\FixtureTest; -class ActvitiesTest extends FixtureTest +class ActivitiesTest extends FixtureTest { /** * Test the api_format_items_activities() function. From 301ac83ebfe9149b63e14ee1305eb8d6ab8c035a Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 2 Jan 2022 01:04:04 +0100 Subject: [PATCH 23/23] Add feedback - avoid intermediate variables --- .../Factory/Api/Twitter/ActivitiesTest.php | 8 +-- .../Factory/Api/Twitter/DirectMessageTest.php | 24 ++++---- tests/src/Factory/Api/Twitter/StatusTest.php | 58 +++++++++---------- tests/src/Factory/Api/Twitter/UserTest.php | 12 ++-- .../Friendica/DirectMessages/SearchTest.php | 15 +++-- .../Module/Api/Friendica/NotificationTest.php | 18 ++++-- .../Module/Api/Friendica/Photo/DeleteTest.php | 12 ++-- .../Api/Friendica/Photoalbum/DeleteTest.php | 14 +++-- .../Api/Friendica/Photoalbum/UpdateTest.php | 20 +++++-- .../Api/GnuSocial/GnuSocial/ConfigTest.php | 4 +- .../Api/GnuSocial/GnuSocial/VersionTest.php | 9 ++- .../Module/Api/GnuSocial/Help/TestTest.php | 18 ++++-- .../Accounts/VerifyCredentialsTest.php | 4 +- .../Twitter/Account/RateLimitStatusTest.php | 18 ++++-- .../Api/Twitter/Account/UpdateProfileTest.php | 7 ++- .../Module/Api/Twitter/Blocks/ListsTest.php | 4 +- .../Api/Twitter/DirectMessages/AllTest.php | 4 +- .../DirectMessages/ConversationTest.php | 8 +-- .../Twitter/DirectMessages/DestroyTest.php | 38 ++++++------ .../Api/Twitter/DirectMessages/InboxTest.php | 4 +- .../Api/Twitter/DirectMessages/NewDMTest.php | 48 +++++++-------- .../Api/Twitter/DirectMessages/SentTest.php | 12 ++-- .../Api/Twitter/Favorites/CreateTest.php | 16 +++-- .../Api/Twitter/Favorites/DestroyTest.php | 10 ++-- .../src/Module/Api/Twitter/FavoritesTest.php | 15 ++--- .../Api/Twitter/Followers/ListsTest.php | 4 +- .../Module/Api/Twitter/Friends/ListsTest.php | 4 +- .../Api/Twitter/Friendships/IncomingTest.php | 4 +- .../Module/Api/Twitter/Lists/StatusesTest.php | 18 ++++-- .../Module/Api/Twitter/Media/UploadTest.php | 16 +++-- .../Module/Api/Twitter/SavedSearchesTest.php | 4 +- .../Api/Twitter/Statuses/DestroyTest.php | 10 ++-- .../Api/Twitter/Statuses/MentionsTest.php | 18 ++++-- .../Statuses/NetworkPublicTimelineTest.php | 19 ++++-- .../Api/Twitter/Statuses/RetweetTest.php | 16 +++-- .../Module/Api/Twitter/Statuses/ShowTest.php | 18 ++++-- .../Api/Twitter/Statuses/UpdateTest.php | 22 +++---- .../Api/Twitter/Statuses/UserTimelineTest.php | 32 +++++----- .../Module/Api/Twitter/Users/LookupTest.php | 10 ++-- .../Module/Api/Twitter/Users/SearchTest.php | 17 ++++-- .../src/Module/Api/Twitter/Users/ShowTest.php | 9 +-- tests/src/Module/NodeInfoTest.php | 18 ++---- 42 files changed, 367 insertions(+), 272 deletions(-) diff --git a/tests/src/Factory/Api/Twitter/ActivitiesTest.php b/tests/src/Factory/Api/Twitter/ActivitiesTest.php index 43f976e353..b468bdd1e7 100644 --- a/tests/src/Factory/Api/Twitter/ActivitiesTest.php +++ b/tests/src/Factory/Api/Twitter/ActivitiesTest.php @@ -17,8 +17,8 @@ class ActivitiesTest extends FixtureTest { $item = ['uid' => 0, 'uri-id' => 1]; - $friendicaActivitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); - $result = $friendicaActivitiesFac->createFromUriId($item['uri-id'], $item['uid']); + $result = (new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser())) + ->createFromUriId($item['uri-id'], $item['uid']); self::assertArrayHasKey('like', $result); self::assertArrayHasKey('dislike', $result); @@ -36,8 +36,8 @@ class ActivitiesTest extends FixtureTest { $item = ['uid' => 0, 'uri-id' => 1]; - $friendicaActivitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); - $result = $friendicaActivitiesFac->createFromUriId($item['uri-id'], $item['uid'], 'xml'); + $result = (new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser())) + ->createFromUriId($item['uri-id'], $item['uid'], 'xml'); self::assertArrayHasKey('friendica:like', $result); self::assertArrayHasKey('friendica:dislike', $result); diff --git a/tests/src/Factory/Api/Twitter/DirectMessageTest.php b/tests/src/Factory/Api/Twitter/DirectMessageTest.php index 9cc7560708..8ba821c760 100644 --- a/tests/src/Factory/Api/Twitter/DirectMessageTest.php +++ b/tests/src/Factory/Api/Twitter/DirectMessageTest.php @@ -20,9 +20,9 @@ class DirectMessageTest extends FixtureTest $ids = DI::dba()->selectToArray('mail', ['id']); $id = $ids[0]['id']; - $directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id']); - $directMessage = $directMessageObj->toArray(); + $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser())) + ->createFromMailId($id, ApiTest::SELF_USER['id']) + ->toArray(); self::assertEquals('item_title' . "\n" . 'item_body', $directMessage['text']); self::assertIsInt($directMessage['id']); @@ -43,9 +43,9 @@ class DirectMessageTest extends FixtureTest $ids = DI::dba()->selectToArray('mail', ['id']); $id = $ids[0]['id']; - $directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'html'); - $directMessage = $directMessageObj->toArray(); + $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser())) + ->createFromMailId($id, ApiTest::SELF_USER['id'], 'html') + ->toArray(); self::assertEquals('item_title', $directMessage['title']); self::assertEquals('item_body', $directMessage['text']); @@ -62,9 +62,9 @@ class DirectMessageTest extends FixtureTest $ids = DI::dba()->selectToArray('mail', ['id']); $id = $ids[0]['id']; - $directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain'); - $directMessage = $directMessageObj->toArray(); + $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser())) + ->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain') + ->toArray(); self::assertEquals('item_title', $directMessage['title']); self::assertEquals('item_body', $directMessage['text']); @@ -84,9 +84,9 @@ class DirectMessageTest extends FixtureTest $ids = DI::dba()->selectToArray('mail', ['id']); $id = $ids[0]['id']; - $directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain', $$GETUSEROBJECTS$$); - $directMessage = $directMessageObj->toArray(); + $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser())) + ->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain', $$GETUSEROBJECTS$$) + ->toArray(); self::assertTrue(!isset($directMessage['sender'])); self::assertTrue(!isset($directMessage['recipient'])); diff --git a/tests/src/Factory/Api/Twitter/StatusTest.php b/tests/src/Factory/Api/Twitter/StatusTest.php index 1073867ee2..a2d9d7171c 100644 --- a/tests/src/Factory/Api/Twitter/StatusTest.php +++ b/tests/src/Factory/Api/Twitter/StatusTest.php @@ -15,6 +15,24 @@ use Friendica\Test\src\Module\Api\ApiTest; class StatusTest extends FixtureTest { + protected $statusFactory; + + protected function setUp(): void + { + parent::setUp(); + + $this->statusFactory = new Status( + DI::logger(), + DI::dba(), + DI::twitterUser(), + new Hashtag(DI::logger()), + new Media(DI::logger(), DI::baseUrl()), + new Url(DI::logger()), + new Mention(DI::logger(), DI::baseUrl()), + new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()), + new Attachment(DI::logger())); + } + /** * Test the api_convert_item() function. * @@ -22,16 +40,9 @@ class StatusTest extends FixtureTest */ public function testApiConvertItem() { - $hashTagFac = new Hashtag(DI::logger()); - $mediaFac = new Media(DI::logger(), DI::baseUrl()); - $urlFac = new Url(DI::logger()); - $mentionFac = new Mention(DI::logger(), DI::baseUrl()); - $activitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); - $attachmentFac = new Attachment(DI::logger()); - - $statusFac = new Status(DI::logger(), DI::dba(), DI::twitterUser(), $hashTagFac, $mediaFac, $urlFac, $mentionFac, $activitiesFac, $attachmentFac); - $statusObj = $statusFac->createFromItemId(13, ApiTest::SELF_USER['id']); - $status = $statusObj->toArray(); + $status = $this->statusFactory + ->createFromItemId(13, ApiTest::SELF_USER['id']) + ->toArray(); self::assertStringStartsWith('item_title', $status['text']); self::assertStringStartsWith('

item_title


perspiciatis impedit voluptatem', $status['friendica_html']); @@ -90,16 +101,9 @@ class StatusTest extends FixtureTest */ public function testApiGetEntititiesWithIncludeEntities() { - $hashTagFac = new Hashtag(DI::logger()); - $mediaFac = new Media(DI::logger(), DI::baseUrl()); - $urlFac = new Url(DI::logger()); - $mentionFac = new Mention(DI::logger(), DI::baseUrl()); - $activitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); - $attachmentFac = new Attachment(DI::logger()); - - $statusFac = new Status(DI::logger(), DI::dba(), DI::twitterUser(), $hashTagFac, $mediaFac, $urlFac, $mentionFac, $activitiesFac, $attachmentFac); - $statusObj = $statusFac->createFromItemId(13, ApiTest::SELF_USER['id'], true); - $status = $statusObj->toArray(); + $status = $this->statusFactory + ->createFromItemId(13, ApiTest::SELF_USER['id'], true) + ->toArray(); self::assertIsArray($status['entities']); self::assertIsArray($status['extended_entities']); @@ -114,19 +118,11 @@ class StatusTest extends FixtureTest */ public function testApiFormatItems() { - $hashTagFac = new Hashtag(DI::logger()); - $mediaFac = new Media(DI::logger(), DI::baseUrl()); - $urlFac = new Url(DI::logger()); - $mentionFac = new Mention(DI::logger(), DI::baseUrl()); - $activitiesFac = new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()); - $attachmentFac = new Attachment(DI::logger()); - - $statusFac = new Status(DI::logger(), DI::dba(), DI::twitterUser(), $hashTagFac, $mediaFac, $urlFac, $mentionFac, $activitiesFac, $attachmentFac); - $posts = DI::dba()->selectToArray('post-view', ['uri-id']); foreach ($posts as $item) { - $statusObj = $statusFac->createFromUriId($item['uri-id'], ApiTest::SELF_USER['id']); - $status = $statusObj->toArray(); + $status = $this->statusFactory + ->createFromUriId($item['uri-id'], ApiTest::SELF_USER['id']) + ->toArray(); self::assertIsInt($status['id']); self::assertIsString($status['text']); diff --git a/tests/src/Factory/Api/Twitter/UserTest.php b/tests/src/Factory/Api/Twitter/UserTest.php index a39055a91b..9a279ee7fe 100644 --- a/tests/src/Factory/Api/Twitter/UserTest.php +++ b/tests/src/Factory/Api/Twitter/UserTest.php @@ -31,9 +31,9 @@ class UserTest extends FixtureTest */ public function testApiGetUser() { - $userFactory = new User(DI::logger(), DI::twitterStatus()); - $userObj = $userFactory->createFromUserId(ApiTest::SELF_USER['id']); - $user = $userObj->toArray(); + $user = (new User(DI::logger(), DI::twitterStatus())) + ->createFromUserId(ApiTest::SELF_USER['id']) + ->toArray(); $this->assertSelfUser($user); } @@ -114,9 +114,9 @@ class UserTest extends FixtureTest */ public function testApiGetUserWithWrongGetId() { - $userFactory = new User(DI::logger(), DI::twitterStatus()); - $userObj = $userFactory->createFromUserId(-1); - $user = $userObj->toArray(); + $user = (new User(DI::logger(), DI::twitterStatus())) + ->createFromUserId(-1) + ->toArray(); self::assertEquals(0, $user['id']); self::assertEquals(0, $user['uid']); diff --git a/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php b/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php index 9fe8f7ca70..af12be2c1b 100644 --- a/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php +++ b/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php @@ -34,7 +34,8 @@ class SearchTest extends ApiTest { $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser()); - $response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))->run(); + $response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); $json = $this->toJson($response); @@ -51,8 +52,10 @@ class SearchTest extends ApiTest $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser()); - $search = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $search->run(['searchstring' => 'item_body']); + $response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'searchstring' => 'item_body' + ]); $json = $this->toJson($response); @@ -70,8 +73,10 @@ class SearchTest extends ApiTest { $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser()); - $search = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $search->run(['searchstring' => 'test']); + $response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'searchstring' => 'test' + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Friendica/NotificationTest.php b/tests/src/Module/Api/Friendica/NotificationTest.php index f05387bd88..bd0edf046f 100644 --- a/tests/src/Module/Api/Friendica/NotificationTest.php +++ b/tests/src/Module/Api/Friendica/NotificationTest.php @@ -66,17 +66,20 @@ class NotificationTest extends ApiTest XML; - $notification = new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']); - $response = $notification->run(); + $response = (new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml'])) + ->run(); self::assertXmlStringEqualsXmlString($assertXml, (string)$response->getBody()); - self::assertEquals(['Content-type' => ['text/xml'], ICanCreateResponses::X_HEADER => ['xml']], $response->getHeaders()); + self::assertEquals([ + 'Content-type' => ['text/xml'], + ICanCreateResponses::X_HEADER => ['xml'] + ], $response->getHeaders()); } public function testWithJsonResult() { - $notification = new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); - $response = $notification->run(); + $response = (new Notification(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json'])) + ->run(); $json = $this->toJson($response); @@ -88,6 +91,9 @@ XML; self::assertIsString($note->msg); } - self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); + self::assertEquals([ + 'Content-type' => ['application/json'], + ICanCreateResponses::X_HEADER => ['json'] + ], $response->getHeaders()); } } diff --git a/tests/src/Module/Api/Friendica/Photo/DeleteTest.php b/tests/src/Module/Api/Friendica/Photo/DeleteTest.php index 05808d56c4..2f8bdb8fd9 100644 --- a/tests/src/Module/Api/Friendica/Photo/DeleteTest.php +++ b/tests/src/Module/Api/Friendica/Photo/DeleteTest.php @@ -50,8 +50,10 @@ class DeleteTest extends ApiTest { $this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba()); - $delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $delete->run(['photo_id' => '709057080661a283a6aa598501504178']); + $response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'photo_id' => '709057080661a283a6aa598501504178' + ]); $json = $this->toJson($response); @@ -63,8 +65,10 @@ class DeleteTest extends ApiTest { $this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba()); - $delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $delete->run(['photo_id' => '709057080661a283a6aa598501504178']); + $response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'photo_id' => '709057080661a283a6aa598501504178' + ]); $responseText = (string)$response->getBody(); diff --git a/tests/src/Module/Api/Friendica/Photoalbum/DeleteTest.php b/tests/src/Module/Api/Friendica/Photoalbum/DeleteTest.php index 230ba70c89..b4c6df2d54 100644 --- a/tests/src/Module/Api/Friendica/Photoalbum/DeleteTest.php +++ b/tests/src/Module/Api/Friendica/Photoalbum/DeleteTest.php @@ -32,22 +32,28 @@ class DeleteTest extends ApiTest public function testEmpty() { $this->expectException(BadRequestException::class); - (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); + (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } public function testWrong() { $this->expectException(BadRequestException::class); - (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'album_name']); + (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'album' => 'album_name' + ]); } public function testValidWithDelete() { $this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba()); - $delete = new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $delete->run(['album' => 'test_album']); + $response = (new Delete(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'album' => 'test_album'] + ); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Friendica/Photoalbum/UpdateTest.php b/tests/src/Module/Api/Friendica/Photoalbum/UpdateTest.php index fa4638e370..e370ba3f91 100644 --- a/tests/src/Module/Api/Friendica/Photoalbum/UpdateTest.php +++ b/tests/src/Module/Api/Friendica/Photoalbum/UpdateTest.php @@ -32,19 +32,27 @@ class UpdateTest extends ApiTest public function testEmpty() { $this->expectException(BadRequestException::class); - (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); + (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } public function testTooFewArgs() { $this->expectException(BadRequestException::class); - (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'album_name']); + (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'album' => 'album_name' + ]); } public function testWrongUpdate() { $this->expectException(BadRequestException::class); - (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'album_name', 'album_new' => 'album_name']); + (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'album' => 'album_name', + 'album_new' => 'album_name' + ]); } public function testWithoutAuthenticatedUser() @@ -56,7 +64,11 @@ class UpdateTest extends ApiTest { $this->loadFixture(__DIR__ . '/../../../../../datasets/photo/photo.fixture.php', DI::dba()); - $response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(['album' => 'test_album', 'album_new' => 'test_album_2']); + $response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'album' => 'test_album', + 'album_new' => 'test_album_2' + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php index b1874d8386..07e43479d2 100644 --- a/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php +++ b/tests/src/Module/Api/GnuSocial/GnuSocial/ConfigTest.php @@ -17,8 +17,8 @@ class ConfigTest extends ApiTest { 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(); + $response = (new Config(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/GnuSocial/GnuSocial/VersionTest.php b/tests/src/Module/Api/GnuSocial/GnuSocial/VersionTest.php index 0f65318319..7d98e365c1 100644 --- a/tests/src/Module/Api/GnuSocial/GnuSocial/VersionTest.php +++ b/tests/src/Module/Api/GnuSocial/GnuSocial/VersionTest.php @@ -11,10 +11,13 @@ class VersionTest extends ApiTest { public function test() { - $version = new Version(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); - $response = $version->run(); + $response = (new Version(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json'])) + ->run(); - self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); + self::assertEquals([ + 'Content-type' => ['application/json'], + ICanCreateResponses::X_HEADER => ['json'] + ], $response->getHeaders()); self::assertEquals('"0.9.7"', $response->getBody()); } } diff --git a/tests/src/Module/Api/GnuSocial/Help/TestTest.php b/tests/src/Module/Api/GnuSocial/Help/TestTest.php index 858c9b6cdc..4c9e0c169e 100644 --- a/tests/src/Module/Api/GnuSocial/Help/TestTest.php +++ b/tests/src/Module/Api/GnuSocial/Help/TestTest.php @@ -11,21 +11,27 @@ class TestTest extends ApiTest { public function testJson() { - $test = new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); - $response = $test->run(); + $response = (new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json'])) + ->run(); $json = $this->toJson($response); - self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); + self::assertEquals([ + 'Content-type' => ['application/json'], + ICanCreateResponses::X_HEADER => ['json'] + ], $response->getHeaders()); self::assertEquals('ok', $json); } public function testXml() { - $test = new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']); - $response = $test->run(); + $response = (new Test(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml'])) + ->run(); - self::assertEquals(['Content-type' => ['text/xml'], ICanCreateResponses::X_HEADER => ['xml']], $response->getHeaders()); + self::assertEquals([ + 'Content-type' => ['text/xml'], + ICanCreateResponses::X_HEADER => ['xml'] + ], $response->getHeaders()); self::assertxml($response->getBody(), 'ok'); } } diff --git a/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php b/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php index 51d76696f6..5942aa1d27 100644 --- a/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php +++ b/tests/src/Module/Api/Mastodon/Accounts/VerifyCredentialsTest.php @@ -16,8 +16,8 @@ class VerifyCredentialsTest extends ApiTest */ public function testApiAccountVerifyCredentials() { - $verifyCredentials = new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $verifyCredentials->run(); + $response = (new VerifyCredentials(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php b/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php index a76b5d87e0..9b29d314be 100644 --- a/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php +++ b/tests/src/Module/Api/Twitter/Account/RateLimitStatusTest.php @@ -12,12 +12,15 @@ class RateLimitStatusTest extends ApiTest { public function testWithJson() { - $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(); + $response = (new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run(); $result = $this->toJson($response); - self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); + self::assertEquals([ + 'Content-type' => ['application/json'], + ICanCreateResponses::X_HEADER => ['json'] + ], $response->getHeaders()); self::assertEquals(150, $result->remaining_hits); self::assertEquals(150, $result->hourly_limit); self::assertIsInt($result->reset_time_in_seconds); @@ -25,10 +28,13 @@ class RateLimitStatusTest extends ApiTest public function testWithXml() { - $rateLimitStatus = new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml']); - $response = $rateLimitStatus->run(); + $response = (new RateLimitStatus(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'xml'])) + ->run(); - self::assertEquals(['Content-type' => ['text/xml'], ICanCreateResponses::X_HEADER => ['xml']], $response->getHeaders()); + self::assertEquals([ + 'Content-type' => ['text/xml'], + ICanCreateResponses::X_HEADER => ['xml'] + ], $response->getHeaders()); self::assertXml($response->getBody(), 'hash'); } } diff --git a/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php b/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php index e06e8d4848..76cb27c919 100644 --- a/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php +++ b/tests/src/Module/Api/Twitter/Account/UpdateProfileTest.php @@ -14,8 +14,11 @@ class UpdateProfileTest extends ApiTest */ 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']); + $response = (new UpdateProfile(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => 'json'])) + ->run([ + 'name' => 'new_name', + 'description' => 'new_description' + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Blocks/ListsTest.php b/tests/src/Module/Api/Twitter/Blocks/ListsTest.php index a37b59f036..77c45ada83 100644 --- a/tests/src/Module/Api/Twitter/Blocks/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Blocks/ListsTest.php @@ -14,8 +14,8 @@ class ListsTest extends ApiTest */ public function testApiStatusesFWithBlocks() { - $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $lists->run(); + $response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/DirectMessages/AllTest.php b/tests/src/Module/Api/Twitter/DirectMessages/AllTest.php index 52021c71b9..63290368aa 100644 --- a/tests/src/Module/Api/Twitter/DirectMessages/AllTest.php +++ b/tests/src/Module/Api/Twitter/DirectMessages/AllTest.php @@ -21,8 +21,8 @@ class AllTest extends ApiTest $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $destroy = new All($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $destroy->run(); + $response = (new All($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run(); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php b/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php index 815d5eb577..5667b72768 100644 --- a/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php +++ b/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php @@ -19,10 +19,10 @@ class ConversationTest extends ApiTest { $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $sent = new Conversation($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $sent->run([ - 'friendica_verbose' => true, - ]); + $response = (new Conversation($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'friendica_verbose' => true, + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php b/tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php index f1ab18d5c4..b743227789 100644 --- a/tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php +++ b/tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php @@ -18,7 +18,8 @@ class DestroyTest extends ApiTest public function testApiDirectMessagesDestroy() { $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))->run(); + (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run(); } /** @@ -28,10 +29,10 @@ class DestroyTest extends ApiTest */ public function testApiDirectMessagesDestroyWithVerbose() { - $destroy = new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $destroy->run([ - 'friendica_verbose' => true, - ]); + $response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'friendica_verbose' => true, + ]); $json = $this->toJson($response); @@ -64,7 +65,10 @@ class DestroyTest extends ApiTest public function testApiDirectMessagesDestroyWithId() { $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class); - (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))->run(['id' => 1]); + (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'id' => 1 + ]); } /** @@ -74,12 +78,12 @@ class DestroyTest extends ApiTest */ public function testApiDirectMessagesDestroyWithIdAndVerbose() { - $destroy = new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $destroy->run([ - 'id' => 1, - 'friendica_parenturi' => 'parent_uri', - 'friendica_verbose' => true, - ]); + $response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'id' => 1, + 'friendica_parenturi' => 'parent_uri', + 'friendica_verbose' => true, + ]); $json = $this->toJson($response); @@ -98,11 +102,11 @@ class DestroyTest extends ApiTest $ids = DBA::selectToArray('mail', ['id']); $id = $ids[0]['id']; - $destroy = new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $destroy->run([ - 'id' => $id, - 'friendica_verbose' => true, - ]); + $response = (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'id' => $id, + 'friendica_verbose' => true, + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php b/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php index 42c0b59785..beb61ee968 100644 --- a/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php +++ b/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php @@ -21,8 +21,8 @@ class InboxTest extends ApiTest $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $destroy = new Inbox($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $destroy->run(); + $response = (new Inbox($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run(); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php b/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php index d9bcc87ed1..3cae992fa2 100644 --- a/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php +++ b/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php @@ -19,8 +19,8 @@ class NewDMTest extends ApiTest { $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $newDm->run(); + $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run(); self::assertEmpty((string)$response->getBody()); } @@ -51,11 +51,11 @@ class NewDMTest extends ApiTest { $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $newDm->run([ - 'text' => 'message_text', - 'user_id' => 43 - ]); + $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'text' => 'message_text', + 'user_id' => 43 + ]); $json = $this->toJson($response); @@ -73,11 +73,11 @@ class NewDMTest extends ApiTest $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $newDm->run([ - 'text' => 'message_text', - 'user_id' => 44 - ]); + $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'text' => 'message_text', + 'user_id' => 44 + ]); $json = $this->toJson($response); @@ -97,12 +97,12 @@ class NewDMTest extends ApiTest $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $newDm->run([ - 'text' => 'message_text', - 'user_id' => 44, - 'title' => 'message_title', - ]); + $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'text' => 'message_text', + 'user_id' => 44, + 'title' => 'message_title', + ]); $json = $this->toJson($response); @@ -123,12 +123,12 @@ class NewDMTest extends ApiTest $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $newDm = new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']); - $response = $newDm->run([ - 'text' => 'message_text', - 'user_id' => 44, - 'title' => 'message_title', - ]); + $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss'])) + ->run([ + 'text' => 'message_text', + 'user_id' => 44, + 'title' => 'message_title', + ]); self::assertXml((string)$response->getBody(), 'direct-messages'); } diff --git a/tests/src/Module/Api/Twitter/DirectMessages/SentTest.php b/tests/src/Module/Api/Twitter/DirectMessages/SentTest.php index 3343716622..ccea4fd539 100644 --- a/tests/src/Module/Api/Twitter/DirectMessages/SentTest.php +++ b/tests/src/Module/Api/Twitter/DirectMessages/SentTest.php @@ -19,10 +19,10 @@ class SentTest extends ApiTest { $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $sent = new Sent($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']); - $response = $sent->run([ - 'friendica_verbose' => true, - ]); + $response = (new Sent($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json'])) + ->run([ + 'friendica_verbose' => true, + ]); $json = $this->toJson($response); @@ -39,8 +39,8 @@ class SentTest extends ApiTest { $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()); - $sent = new Sent($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']); - $response = $sent->run(); + $response = (new Sent($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss'])) + ->run(); self::assertXml((string)$response->getBody(), 'direct-messages'); } diff --git a/tests/src/Module/Api/Twitter/Favorites/CreateTest.php b/tests/src/Module/Api/Twitter/Favorites/CreateTest.php index 00a99643bf..1055dd9d1a 100644 --- a/tests/src/Module/Api/Twitter/Favorites/CreateTest.php +++ b/tests/src/Module/Api/Twitter/Favorites/CreateTest.php @@ -20,8 +20,8 @@ class CreateTest extends ApiTest { $this->expectException(BadRequestException::class); - $create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $create->run(); + (new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } /** @@ -31,8 +31,10 @@ class CreateTest extends ApiTest */ public function testApiFavoritesCreateDestroyWithCreateAction() { - $create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $create->run(['id' => 3]); + $response = (new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'id' => 3 + ]); $json = $this->toJson($response); @@ -46,8 +48,10 @@ class CreateTest extends ApiTest */ public function testApiFavoritesCreateDestroyWithCreateActionAndRss() { - $create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => ICanCreateResponses::TYPE_RSS]); - $response = $create->run(['id' => 3]); + $response = (new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => ICanCreateResponses::TYPE_RSS])) + ->run([ + 'id' => 3 + ]); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); diff --git a/tests/src/Module/Api/Twitter/Favorites/DestroyTest.php b/tests/src/Module/Api/Twitter/Favorites/DestroyTest.php index 3d8ce8a212..65113f5568 100644 --- a/tests/src/Module/Api/Twitter/Favorites/DestroyTest.php +++ b/tests/src/Module/Api/Twitter/Favorites/DestroyTest.php @@ -19,8 +19,8 @@ class DestroyTest extends ApiTest { $this->expectException(BadRequestException::class); - $destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $destroy->run(); + (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } /** @@ -30,8 +30,10 @@ class DestroyTest extends ApiTest */ public function testApiFavoritesCreateDestroyWithDestroyAction() { - $destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $destroy->run(['id' => 3]); + $response = (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'id' => 3 + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/FavoritesTest.php b/tests/src/Module/Api/Twitter/FavoritesTest.php index dd95d73f90..1f0faa971a 100644 --- a/tests/src/Module/Api/Twitter/FavoritesTest.php +++ b/tests/src/Module/Api/Twitter/FavoritesTest.php @@ -17,11 +17,11 @@ class FavoritesTest extends ApiTest */ public function testApiFavorites() { - $favorites = new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $favorites->run([ - 'page' => -1, - 'max_id' => 10, - ]); + $response = (new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'page' => -1, + 'max_id' => 10, + ]); $json = $this->toJson($response); @@ -37,8 +37,9 @@ class FavoritesTest extends ApiTest */ public function testApiFavoritesWithRss() { - $favorites = new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]); - $response = $favorites->run(); + $response = (new Favorites(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [ + 'extension' => ICanCreateResponses::TYPE_RSS + ]))->run(); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); diff --git a/tests/src/Module/Api/Twitter/Followers/ListsTest.php b/tests/src/Module/Api/Twitter/Followers/ListsTest.php index 7ea3863eaf..e9946bb735 100644 --- a/tests/src/Module/Api/Twitter/Followers/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Followers/ListsTest.php @@ -14,8 +14,8 @@ class ListsTest extends ApiTest */ public function testApiStatusesFWithFollowers() { - $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $lists->run(); + $response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Friends/ListsTest.php b/tests/src/Module/Api/Twitter/Friends/ListsTest.php index 7cb5bd10a7..3628f5c963 100644 --- a/tests/src/Module/Api/Twitter/Friends/ListsTest.php +++ b/tests/src/Module/Api/Twitter/Friends/ListsTest.php @@ -16,8 +16,8 @@ class ListsTest extends ApiTest */ public function testApiStatusesFWithFriends() { - $lists = new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $lists->run(); + $response = (new Lists(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php b/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php index c1309e1f0a..d8e5cc3da0 100644 --- a/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php +++ b/tests/src/Module/Api/Twitter/Friendships/IncomingTest.php @@ -16,8 +16,8 @@ class IncomingTest extends ApiTest */ public function testApiFriendshipsIncoming() { - $lists = new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $lists->run(); + $response = (new Incoming(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Lists/StatusesTest.php b/tests/src/Module/Api/Twitter/Lists/StatusesTest.php index 3f47fcaca6..66ebf8bbd7 100644 --- a/tests/src/Module/Api/Twitter/Lists/StatusesTest.php +++ b/tests/src/Module/Api/Twitter/Lists/StatusesTest.php @@ -19,8 +19,8 @@ class StatusesTest extends ApiTest { $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(); + (new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); } /** @@ -28,8 +28,12 @@ class StatusesTest extends ApiTest */ public function testApiListsStatusesWithListId() { - $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]); + $response = (new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'list_id' => 1, + 'page' => -1, + 'max_id' => 10 + ]); $json = $this->toJson($response); @@ -44,8 +48,10 @@ class StatusesTest extends ApiTest */ public function testApiListsStatusesWithListIdAndRss() { - $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]); + $response = (new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss'])) + ->run([ + 'list_id' => 1 + ]); self::assertXml((string)$response->getBody()); } diff --git a/tests/src/Module/Api/Twitter/Media/UploadTest.php b/tests/src/Module/Api/Twitter/Media/UploadTest.php index 4b0ffada12..b3516c3079 100644 --- a/tests/src/Module/Api/Twitter/Media/UploadTest.php +++ b/tests/src/Module/Api/Twitter/Media/UploadTest.php @@ -19,8 +19,9 @@ class UploadTest extends ApiTest public function testApiMediaUpload() { $this->expectException(BadRequestException::class); - $upload = new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $upload->run(); + + (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } /** @@ -32,7 +33,9 @@ class UploadTest extends ApiTest { $this->expectException(UnauthorizedException::class); AuthTestConfig::$authenticated = false; - (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); + + (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } /** @@ -49,7 +52,9 @@ class UploadTest extends ApiTest 'tmp_name' => 'tmp_name' ] ]; - (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); + + (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } /** @@ -71,7 +76,8 @@ class UploadTest extends ApiTest ] ]; - $response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]))->run(); + $response = (new Upload(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); $media = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/SavedSearchesTest.php b/tests/src/Module/Api/Twitter/SavedSearchesTest.php index 5735f8eef0..667caf98ca 100644 --- a/tests/src/Module/Api/Twitter/SavedSearchesTest.php +++ b/tests/src/Module/Api/Twitter/SavedSearchesTest.php @@ -11,8 +11,8 @@ class SavedSearchesTest extends ApiTest { public function test() { - $savedSearch = new SavedSearches(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']); - $response = $savedSearch->run(); + $response = (new SavedSearches(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json'])) + ->run(); $result = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Statuses/DestroyTest.php b/tests/src/Module/Api/Twitter/Statuses/DestroyTest.php index 9b2110eb6b..0480ba8c2b 100644 --- a/tests/src/Module/Api/Twitter/Statuses/DestroyTest.php +++ b/tests/src/Module/Api/Twitter/Statuses/DestroyTest.php @@ -19,8 +19,8 @@ class DestroyTest extends ApiTest { $this->expectException(BadRequestException::class); - $destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $destroy->run(); + (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } /** @@ -45,8 +45,10 @@ class DestroyTest extends ApiTest */ public function testApiStatusesDestroyWithId() { - $destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $destroy->run(['id' => 1]); + $response = (new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'id' => 1 + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Statuses/MentionsTest.php b/tests/src/Module/Api/Twitter/Statuses/MentionsTest.php index 364af4a569..d92f26f72b 100644 --- a/tests/src/Module/Api/Twitter/Statuses/MentionsTest.php +++ b/tests/src/Module/Api/Twitter/Statuses/MentionsTest.php @@ -17,8 +17,10 @@ class MentionsTest extends ApiTest */ public function testApiStatusesMentions() { - $mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $mentions->run(['max_id' => 10]); + $response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'max_id' => 10 + ]); $json = $this->toJson($response); @@ -33,8 +35,10 @@ class MentionsTest extends ApiTest */ public function testApiStatusesMentionsWithNegativePage() { - $mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $mentions->run(['page' => -2]); + $response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'page' => -2 + ]); $json = $this->toJson($response); @@ -63,8 +67,10 @@ class MentionsTest extends ApiTest */ public function testApiStatusesMentionsWithRss() { - $mentions = new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]); - $response = $mentions->run(['page' => -2]); + $response = (new Mentions(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS])) + ->run([ + 'page' => -2 + ]); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); diff --git a/tests/src/Module/Api/Twitter/Statuses/NetworkPublicTimelineTest.php b/tests/src/Module/Api/Twitter/Statuses/NetworkPublicTimelineTest.php index 7d75cdd7d7..a5217fb715 100644 --- a/tests/src/Module/Api/Twitter/Statuses/NetworkPublicTimelineTest.php +++ b/tests/src/Module/Api/Twitter/Statuses/NetworkPublicTimelineTest.php @@ -17,8 +17,10 @@ class NetworkPublicTimelineTest extends ApiTest */ public function testApiStatusesNetworkpublicTimeline() { - $networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $networkPublicTimeline->run(['max_id' => 10]); + $response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'max_id' => 10 + ]); $json = $this->toJson($response); @@ -37,8 +39,10 @@ class NetworkPublicTimelineTest extends ApiTest */ public function testApiStatusesNetworkpublicTimelineWithNegativePage() { - $networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $networkPublicTimeline->run(['page' => -2]); + $response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'page' => -2 + ]); $json = $this->toJson($response); @@ -71,8 +75,11 @@ class NetworkPublicTimelineTest extends ApiTest */ public function testApiStatusesNetworkpublicTimelineWithRss() { - $networkPublicTimeline = new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]); - $response = $networkPublicTimeline->run(['page' => -2]); + $response = (new NetworkPublicTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [ + 'extension' => ICanCreateResponses::TYPE_RSS + ]))->run([ + 'page' => -2 + ]); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); diff --git a/tests/src/Module/Api/Twitter/Statuses/RetweetTest.php b/tests/src/Module/Api/Twitter/Statuses/RetweetTest.php index 1b527ccc9f..1d93c02969 100644 --- a/tests/src/Module/Api/Twitter/Statuses/RetweetTest.php +++ b/tests/src/Module/Api/Twitter/Statuses/RetweetTest.php @@ -19,8 +19,8 @@ class RetweetTest extends ApiTest { $this->expectException(BadRequestException::class); - $retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $retweet->run(); + (new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run(); } /** @@ -45,8 +45,10 @@ class RetweetTest extends ApiTest */ public function testApiStatusesRepeatWithId() { - $retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $retweet->run(['id' => 1]); + $response = (new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'id' => 1 + ]); $json = $this->toJson($response); @@ -60,8 +62,10 @@ class RetweetTest extends ApiTest */ public function testApiStatusesRepeatWithSharedId() { - $retweet = new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $retweet->run(['id' => 5]); + $response = (new Retweet(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'id' => 5 + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Statuses/ShowTest.php b/tests/src/Module/Api/Twitter/Statuses/ShowTest.php index c2d87a95f4..f9d302f0ef 100644 --- a/tests/src/Module/Api/Twitter/Statuses/ShowTest.php +++ b/tests/src/Module/Api/Twitter/Statuses/ShowTest.php @@ -19,8 +19,9 @@ class ShowTest extends ApiTest { $this->expectException(BadRequestException::class); - $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $show->run(); + + (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); } /** @@ -30,8 +31,10 @@ class ShowTest extends ApiTest */ public function testApiStatusesShowWithId() { - $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $show->run(['id' => 1]); + $response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'id' => 1 + ]); $json = $this->toJson($response); @@ -46,8 +49,11 @@ class ShowTest extends ApiTest */ public function testApiStatusesShowWithConversation() { - $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $show->run(['id' => 1, 'conversation' => 1]); + $response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'id' => 1, + 'conversation' => 1 + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Statuses/UpdateTest.php b/tests/src/Module/Api/Twitter/Statuses/UpdateTest.php index 1d181dd523..f3f6b5a929 100644 --- a/tests/src/Module/Api/Twitter/Statuses/UpdateTest.php +++ b/tests/src/Module/Api/Twitter/Statuses/UpdateTest.php @@ -28,13 +28,13 @@ class UpdateTest extends ApiTest ] ]; - $show = new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $show->run([ - 'status' => 'Status content #friendica', - 'in_reply_to_status_id' => 0, - 'lat' => 48, - 'long' => 7, - ]); + $response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'status' => 'Status content #friendica', + 'in_reply_to_status_id' => 0, + 'lat' => 48, + 'long' => 7, + ]); $json = $this->toJson($response); @@ -50,10 +50,10 @@ class UpdateTest extends ApiTest */ public function testApiStatusesUpdateWithHtml() { - $show = new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]); - $response = $show->run([ - 'htmlstatus' => 'Status content', - ]); + $response = (new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST])) + ->run([ + 'htmlstatus' => 'Status content', + ]); $json = $this->toJson($response); diff --git a/tests/src/Module/Api/Twitter/Statuses/UserTimelineTest.php b/tests/src/Module/Api/Twitter/Statuses/UserTimelineTest.php index fc2565e31c..eb06133f36 100644 --- a/tests/src/Module/Api/Twitter/Statuses/UserTimelineTest.php +++ b/tests/src/Module/Api/Twitter/Statuses/UserTimelineTest.php @@ -17,14 +17,13 @@ class UserTimelineTest extends ApiTest */ public function testApiStatusesUserTimeline() { - $networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - - $response = $networkPublicTimeline->run([ - 'user_id' => 42, - 'max_id' => 10, - 'exclude_replies' => true, - 'conversation_id' => 7, - ]); + $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'user_id' => 42, + 'max_id' => 10, + 'exclude_replies' => true, + 'conversation_id' => 7, + ]); $json = $this->toJson($response); @@ -43,12 +42,11 @@ class UserTimelineTest extends ApiTest */ public function testApiStatusesUserTimelineWithNegativePage() { - $networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - - $response = $networkPublicTimeline->run([ - 'user_id' => 42, - 'page' => -2, - ]); + $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'user_id' => 42, + 'page' => -2, + ]); $json = $this->toJson($response); @@ -67,9 +65,9 @@ class UserTimelineTest extends ApiTest */ public function testApiStatusesUserTimelineWithRss() { - $networkPublicTimeline = new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_RSS]); - - $response = $networkPublicTimeline->run(); + $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [ + 'extension' => ICanCreateResponses::TYPE_RSS + ]))->run(); self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); diff --git a/tests/src/Module/Api/Twitter/Users/LookupTest.php b/tests/src/Module/Api/Twitter/Users/LookupTest.php index e54d20dcfb..2c5739e828 100644 --- a/tests/src/Module/Api/Twitter/Users/LookupTest.php +++ b/tests/src/Module/Api/Twitter/Users/LookupTest.php @@ -19,8 +19,8 @@ class LookupTest extends ApiTest { $this->expectException(NotFoundException::class); - $lookup = new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $lookup->run(); + (new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); } /** @@ -30,8 +30,10 @@ class LookupTest extends ApiTest */ public function testApiUsersLookupWithUserId() { - $lookup = new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $respone = $lookup->run(['user_id' => static::OTHER_USER['id']]); + $respone = (new Lookup(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'user_id' => static::OTHER_USER['id'] + ]); $json = $this->toJson($respone); diff --git a/tests/src/Module/Api/Twitter/Users/SearchTest.php b/tests/src/Module/Api/Twitter/Users/SearchTest.php index 4fee774dac..c88999e459 100644 --- a/tests/src/Module/Api/Twitter/Users/SearchTest.php +++ b/tests/src/Module/Api/Twitter/Users/SearchTest.php @@ -18,8 +18,10 @@ class SearchTest extends ApiTest */ public function testApiUsersSearch() { - $search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $respone = $search->run(['q' => static::OTHER_USER['name']]); + $respone = (new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run([ + 'q' => static::OTHER_USER['name'] + ]); $json = $this->toJson($respone); @@ -33,8 +35,11 @@ class SearchTest extends ApiTest */ public function testApiUsersSearchWithXml() { - $search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_XML]); - $respone = $search->run(['q' => static::OTHER_USER['name']]); + $respone = (new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [ + 'extension' => ICanCreateResponses::TYPE_XML + ]))->run([ + 'q' => static::OTHER_USER['name'] + ]); self::assertXml((string)$respone->getBody(), 'users'); } @@ -48,7 +53,7 @@ class SearchTest extends ApiTest { $this->expectException(BadRequestException::class); - $search = new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $search->run(); + (new Search(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); } } diff --git a/tests/src/Module/Api/Twitter/Users/ShowTest.php b/tests/src/Module/Api/Twitter/Users/ShowTest.php index 975bf6d8f1..dd63c3e519 100644 --- a/tests/src/Module/Api/Twitter/Users/ShowTest.php +++ b/tests/src/Module/Api/Twitter/Users/ShowTest.php @@ -17,8 +17,8 @@ class ShowTest extends ApiTest */ public function testApiUsersShow() { - $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]); - $response = $show->run(); + $response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET])) + ->run(); $json = $this->toJson($response); @@ -37,8 +37,9 @@ class ShowTest extends ApiTest */ public function testApiUsersShowWithXml() { - $show = new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => ICanCreateResponses::TYPE_XML]); - $response = $show->run(); + $response = (new Show(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], [ + 'extension' => ICanCreateResponses::TYPE_XML + ]))->run(); self::assertEquals(ICanCreateResponses::TYPE_XML, $response->getHeaderLine(ICanCreateResponses::X_HEADER)); diff --git a/tests/src/Module/NodeInfoTest.php b/tests/src/Module/NodeInfoTest.php index 53a2926f9f..b80057e174 100644 --- a/tests/src/Module/NodeInfoTest.php +++ b/tests/src/Module/NodeInfoTest.php @@ -14,10 +14,8 @@ class NodeInfoTest extends FixtureTest { public function testNodeInfo110() { - $response = new Response(); - - $nodeinfo = new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []); - $response = $nodeinfo->run(); + $response = (new NodeInfo110(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), [])) + ->run(); self::assertJson($response->getBody()); self::assertEquals(['Content-type' => ['application/json'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); @@ -37,10 +35,8 @@ class NodeInfoTest extends FixtureTest public function testNodeInfo120() { - $response = new Response(); - - $nodeinfo = new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []); - $response = $nodeinfo->run(); + $response = (new NodeInfo120(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), [])) + ->run(); self::assertJson($response->getBody()); self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders()); @@ -59,10 +55,8 @@ class NodeInfoTest extends FixtureTest public function testNodeInfo210() { - $response = new Response(); - - $nodeinfo = new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), $response, DI::config(), []); - $response = $nodeinfo->run(); + $response = (new NodeInfo210(DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), DI::config(), [])) + ->run(); self::assertJson($response->getBody()); self::assertEquals(['Content-type' => ['application/json; charset=utf-8'], ICanCreateResponses::X_HEADER => ['json']], $response->getHeaders());