]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php
Fix test
[friendica.git] / tests / src / Module / Api / Twitter / DirectMessages / NewDMTest.php
1 <?php
2
3 namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
4
5 use Friendica\App\Router;
6 use Friendica\DI;
7 use Friendica\Factory\Api\Twitter\DirectMessage;
8 use Friendica\Module\Api\Twitter\DirectMessages\NewDM;
9 use Friendica\Test\src\Module\Api\ApiTest;
10
11 class NewDMTest extends ApiTest
12 {
13         /**
14          * Test the api_direct_messages_new() function.
15          *
16          * @return void
17          */
18         public function testApiDirectMessagesNew()
19         {
20                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
21
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']))
23                         ->run();
24
25                 self::assertEmpty((string)$response->getBody());
26         }
27
28         /**
29          * Test the api_direct_messages_new() function without an authenticated user.
30          *
31          * @return void
32          */
33         public function testApiDirectMessagesNewWithoutAuthenticatedUser()
34         {
35                 self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
36
37                 /*
38                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
39                 BasicAuth::setCurrentUserID();
40                 $_SESSION['authenticated'] = false;
41                 api_direct_messages_new('json');
42                 */
43         }
44
45         /**
46          * Test the api_direct_messages_new() function with an user ID.
47          *
48          * @return void
49          */
50         public function testApiDirectMessagesNewWithUserId()
51         {
52                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
53
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']))
55                         ->run([
56                                 'text'    => 'message_text',
57                                 'user_id' => 43
58                         ]);
59
60                 $json = $this->toJson($response);
61
62                 self::assertEquals(-1, $json->error);
63         }
64
65         /**
66          * Test the api_direct_messages_new() function with a screen name.
67          *
68          * @return void
69          */
70         public function testApiDirectMessagesNewWithScreenName()
71         {
72                 DI::app()->setLoggedInUserNickname('selfcontact');
73
74                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
75
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']))
77                         ->run([
78                                 'text'    => 'message_text',
79                                 'user_id' => 44
80                         ]);
81
82                 $json = $this->toJson($response);
83
84                 self::assertStringContainsString('message_text', $json->text);
85                 self::assertEquals('selfcontact', $json->sender_screen_name);
86                 self::assertEquals(1, $json->friendica_seen);
87         }
88
89         /**
90          * Test the api_direct_messages_new() function with a title.
91          *
92          * @return void
93          */
94         public function testApiDirectMessagesNewWithTitle()
95         {
96                 DI::app()->setLoggedInUserNickname('selfcontact');
97
98                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
99
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']))
101                         ->run([
102                                 'text'    => 'message_text',
103                                 'user_id' => 44,
104                                 'title'   => 'message_title',
105                         ]);
106
107                 $json = $this->toJson($response);
108
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);
113         }
114
115         /**
116          * Test the api_direct_messages_new() function with an RSS result.
117          *
118          * @return void
119          */
120         public function testApiDirectMessagesNewWithRss()
121         {
122                 DI::app()->setLoggedInUserNickname('selfcontact');
123
124                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
125
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']))
127                         ->run([
128                                 'text'    => 'message_text',
129                                 'user_id' => 44,
130                                 'title'   => 'message_title',
131                         ]);
132
133                 self::assertXml((string)$response->getBody(), 'direct-messages');
134         }
135 }