3 namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
5 use Friendica\App\Router;
7 use Friendica\Factory\Api\Twitter\DirectMessage;
8 use Friendica\Module\Api\Twitter\DirectMessages\NewDM;
9 use Friendica\Test\src\Module\Api\ApiTest;
11 class NewDMTest extends ApiTest
14 * Test the api_direct_messages_new() function.
18 public function testApiDirectMessagesNew()
20 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
22 $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']))
25 self::assertEmpty((string)$response->getBody());
29 * Test the api_direct_messages_new() function without an authenticated user.
33 public function testApiDirectMessagesNewWithoutAuthenticatedUser()
35 self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
38 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
39 BasicAuth::setCurrentUserID();
40 $_SESSION['authenticated'] = false;
41 api_direct_messages_new('json');
46 * Test the api_direct_messages_new() function with an user ID.
50 public function testApiDirectMessagesNewWithUserId()
52 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
54 $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']))
56 'text' => 'message_text',
60 $json = $this->toJson($response);
62 self::assertEquals(-1, $json->error);
66 * Test the api_direct_messages_new() function with a screen name.
70 public function testApiDirectMessagesNewWithScreenName()
72 DI::app()->setLoggedInUserNickname('selfcontact');
74 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
76 $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']))
78 'text' => 'message_text',
82 $json = $this->toJson($response);
84 self::assertStringContainsString('message_text', $json->text);
85 self::assertEquals('selfcontact', $json->sender_screen_name);
86 self::assertEquals(1, $json->friendica_seen);
90 * Test the api_direct_messages_new() function with a title.
94 public function testApiDirectMessagesNewWithTitle()
96 DI::app()->setLoggedInUserNickname('selfcontact');
98 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
100 $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']))
102 'text' => 'message_text',
104 'title' => 'message_title',
107 $json = $this->toJson($response);
109 self::assertStringContainsString('message_text', $json->text);
110 self::assertStringContainsString('message_title', $json->text);
111 self::assertEquals('selfcontact', $json->sender_screen_name);
112 self::assertEquals(1, $json->friendica_seen);
116 * Test the api_direct_messages_new() function with an RSS result.
120 public function testApiDirectMessagesNewWithRss()
122 DI::app()->setLoggedInUserNickname('selfcontact');
124 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
126 $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']))
128 'text' => 'message_text',
130 'title' => 'message_title',
133 self::assertXml((string)$response->getBody(), 'direct-messages');