]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Api/Twitter/DirectMessages/NewDMTest.php
b2bcfb37fa835b8b56c05e45a362eb51ce3e8da2
[friendica.git] / tests / src / Module / Api / Twitter / DirectMessages / NewDMTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
23
24 use Friendica\App\Router;
25 use Friendica\DI;
26 use Friendica\Factory\Api\Twitter\DirectMessage;
27 use Friendica\Module\Api\Twitter\DirectMessages\NewDM;
28 use Friendica\Test\src\Module\Api\ApiTest;
29
30 class NewDMTest extends ApiTest
31 {
32         /**
33          * Test the api_direct_messages_new() function.
34          *
35          * @return void
36          */
37         public function testApiDirectMessagesNew()
38         {
39                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
40
41                 $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
42                         ->run();
43
44                 self::assertEmpty((string)$response->getBody());
45         }
46
47         /**
48          * Test the api_direct_messages_new() function without an authenticated user.
49          *
50          * @return void
51          */
52         public function testApiDirectMessagesNewWithoutAuthenticatedUser()
53         {
54                 self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
55
56                 /*
57                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
58                 BasicAuth::setCurrentUserID();
59                 $_SESSION['authenticated'] = false;
60                 api_direct_messages_new('json');
61                 */
62         }
63
64         /**
65          * Test the api_direct_messages_new() function with an user ID.
66          *
67          * @return void
68          */
69         public function testApiDirectMessagesNewWithUserId()
70         {
71                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
72
73                 $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
74                         ->run([
75                                 'text'    => 'message_text',
76                                 'user_id' => 43
77                         ]);
78
79                 $json = $this->toJson($response);
80
81                 self::assertEquals(-1, $json->error);
82         }
83
84         /**
85          * Test the api_direct_messages_new() function with a screen name.
86          *
87          * @return void
88          */
89         public function testApiDirectMessagesNewWithScreenName()
90         {
91                 DI::app()->setLoggedInUserNickname('selfcontact');
92
93                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
94
95                 $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
96                         ->run([
97                                 'text'    => 'message_text',
98                                 'user_id' => 44
99                         ]);
100
101                 $json = $this->toJson($response);
102
103                 self::assertStringContainsString('message_text', $json->text);
104                 self::assertEquals('selfcontact', $json->sender_screen_name);
105                 self::assertEquals(1, $json->friendica_seen);
106         }
107
108         /**
109          * Test the api_direct_messages_new() function with a title.
110          *
111          * @return void
112          */
113         public function testApiDirectMessagesNewWithTitle()
114         {
115                 DI::app()->setLoggedInUserNickname('selfcontact');
116
117                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
118
119                 $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'json']))
120                         ->run([
121                                 'text'    => 'message_text',
122                                 'user_id' => 44,
123                                 'title'   => 'message_title',
124                         ]);
125
126                 $json = $this->toJson($response);
127
128                 self::assertStringContainsString('message_text', $json->text);
129                 self::assertStringContainsString('message_title', $json->text);
130                 self::assertEquals('selfcontact', $json->sender_screen_name);
131                 self::assertEquals(1, $json->friendica_seen);
132         }
133
134         /**
135          * Test the api_direct_messages_new() function with an RSS result.
136          *
137          * @return void
138          */
139         public function testApiDirectMessagesNewWithRss()
140         {
141                 DI::app()->setLoggedInUserNickname('selfcontact');
142
143                 $directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
144
145                 $response = (new NewDM($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], ['extension' => 'rss']))
146                         ->run([
147                                 'text'    => 'message_text',
148                                 'user_id' => 44,
149                                 'title'   => 'message_title',
150                         ]);
151
152                 self::assertXml((string)$response->getBody(), 'direct-messages');
153         }
154 }