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/src/Factory/Api/Twitter/Status.php b/src/Factory/Api/Twitter/Status.php
index 2db1cf1355..f37d18a583 100644
--- a/src/Factory/Api/Twitter/Status.php
+++ b/src/Factory/Api/Twitter/Status.php
@@ -119,7 +119,19 @@ 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 = '';
+ $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);
+
+ $text .= Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
$text = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], $text, BBCode::API), 0));
@@ -190,6 +202,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/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/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/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/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 53c9cc6e14..7d08b6ec99 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;
@@ -153,15 +152,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.
@@ -463,195 +454,6 @@ 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 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.
*
@@ -692,455 +494,6 @@ 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_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_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.
- *
- * @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.
- *
- * @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.
- *
- * @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.
- *
- * @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_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
- */
- 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.
*
@@ -1178,365 +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_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.
- *
- * @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.
- *
- * @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_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.
- *
- * @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.
- *
- * @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_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.
- *
- * @return void
- */
- public function testApiDirectMessagesAll()
- {
- //$result = api_direct_messages_all('json');
- //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.
- *
- * @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.
*
@@ -1749,48 +743,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.
- *
- * @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_best_nickname() function with contacts.
- *
- * @return void
- */
- public function testApiBestNicknameWithContacts()
- {
- $this->markTestIncomplete();
- }
-
/**
* Test the api_friendica_group_show() function.
*
@@ -1801,16 +753,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.
*
@@ -1851,16 +793,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.
*
@@ -1870,44 +802,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();
- }
}
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
diff --git a/tests/src/Factory/Api/Twitter/ActivitiesTest.php b/tests/src/Factory/Api/Twitter/ActivitiesTest.php
new file mode 100644
index 0000000000..b468bdd1e7
--- /dev/null
+++ b/tests/src/Factory/Api/Twitter/ActivitiesTest.php
@@ -0,0 +1,48 @@
+ 0, 'uri-id' => 1];
+
+ $result = (new Activities(DI::logger(), DI::baseUrl(), DI::twitterUser()))
+ ->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 = (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);
+ self::assertArrayHasKey('friendica:attendyes', $result);
+ self::assertArrayHasKey('friendica:attendno', $result);
+ self::assertArrayHasKey('friendica:attendmaybe', $result);
+ }
+}
diff --git a/tests/src/Factory/Api/Twitter/DirectMessageTest.php b/tests/src/Factory/Api/Twitter/DirectMessageTest.php
new file mode 100644
index 0000000000..8ba821c760
--- /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'];
+
+ $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']);
+ 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'];
+
+ $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']);
+ }
+
+ /**
+ * 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'];
+
+ $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']);
+ }
+
+ /**
+ * 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'];
+
+ $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
new file mode 100644
index 0000000000..a2d9d7171c
--- /dev/null
+++ b/tests/src/Factory/Api/Twitter/StatusTest.php
@@ -0,0 +1,131 @@
+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.
+ *
+ * @return void
+ */
+ public function testApiConvertItem()
+ {
+ $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']);
+ }
+
+ /**
+ * 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']);
+ */
+ }
+
+ /**
+ * Test the api_get_entitities() function.
+ *
+ * @return void
+ */
+ public function testApiGetEntititiesWithIncludeEntities()
+ {
+ $status = $this->statusFactory
+ ->createFromItemId(13, ApiTest::SELF_USER['id'], true)
+ ->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']);
+ }
+
+ /**
+ * Test the api_format_items() function.
+ */
+ public function testApiFormatItems()
+ {
+ $posts = DI::dba()->selectToArray('post-view', ['uri-id']);
+ foreach ($posts as $item) {
+ $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
new file mode 100644
index 0000000000..9a279ee7fe
--- /dev/null
+++ b/tests/src/Factory/Api/Twitter/UserTest.php
@@ -0,0 +1,139 @@
+createFromUserId(ApiTest::SELF_USER['id'])
+ ->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()
+ {
+ $user = (new User(DI::logger(), DI::twitterStatus()))
+ ->createFromUserId(-1)
+ ->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']);
+ }
+
+ /**
+ * 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());
+ }
+}
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 @@
+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']])
+ );
+ }
+
+ /**
+ * 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']);
+ */
+ }
}
diff --git a/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php b/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php
index c66a1f42ed..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' => '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' => '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
new file mode 100644
index 0000000000..63290368aa
--- /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());
+
+ $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);
+
+ 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/ConversationTest.php b/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php
new file mode 100644
index 0000000000..5667b72768
--- /dev/null
+++ b/tests/src/Module/Api/Twitter/DirectMessages/ConversationTest.php
@@ -0,0 +1,32 @@
+ Router::GET], ['extension' => 'json']))
+ ->run([
+ 'friendica_verbose' => true,
+ ]);
+
+ $json = $this->toJson($response);
+
+ self::assertEquals('error', $json->result);
+ self::assertEquals('no mails available', $json->message);
+ }
+}
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..b743227789
--- /dev/null
+++ b/tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php
@@ -0,0 +1,116 @@
+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()
+ {
+ $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);
+
+ 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()
+ {
+ $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);
+
+ 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'];
+
+ $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);
+
+ self::assertEquals('ok', $json->result);
+ self::assertEquals('message deleted', $json->message);
+ }
+}
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..beb61ee968
--- /dev/null
+++ b/tests/src/Module/Api/Twitter/DirectMessages/InboxTest.php
@@ -0,0 +1,36 @@
+loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba());
+
+ $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
+
+ $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);
+
+ 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/NewDMTest.php b/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php
new file mode 100644
index 0000000000..3cae992fa2
--- /dev/null
+++ b/tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php
@@ -0,0 +1,135 @@
+ Router::GET], ['extension' => 'json']))
+ ->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());
+
+ $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);
+
+ 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());
+
+ $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);
+
+ 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());
+
+ $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);
+
+ 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());
+
+ $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
new file mode 100644
index 0000000000..ccea4fd539
--- /dev/null
+++ b/tests/src/Module/Api/Twitter/DirectMessages/SentTest.php
@@ -0,0 +1,61 @@
+ Router::GET], ['extension' => 'json']))
+ ->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());
+
+ $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');
+ }
+
+ /**
+ * 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');
+ }
+}
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());