]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Api/Twitter/DirectMessages/DestroyTest.php
Fix test
[friendica.git] / tests / src / Module / Api / Twitter / DirectMessages / DestroyTest.php
1 <?php
2
3 namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
4
5 use Friendica\App\Router;
6 use Friendica\Database\DBA;
7 use Friendica\DI;
8 use Friendica\Module\Api\Twitter\DirectMessages\Destroy;
9 use Friendica\Test\src\Module\Api\ApiTest;
10
11 class DestroyTest extends ApiTest
12 {
13         /**
14          * Test the api_direct_messages_destroy() function.
15          *
16          * @return void
17          */
18         public function testApiDirectMessagesDestroy()
19         {
20                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
21                 (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
22                         ->run();
23         }
24
25         /**
26          * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
27          *
28          * @return void
29          */
30         public function testApiDirectMessagesDestroyWithVerbose()
31         {
32                 $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']))
33                         ->run([
34                                 'friendica_verbose' => true,
35                         ]);
36
37                 $json = $this->toJson($response);
38
39                 self::assertEquals('error', $json->result);
40                 self::assertEquals('message id or parenturi not specified', $json->message);
41         }
42
43         /**
44          * Test the api_direct_messages_destroy() function without an authenticated user.
45          *
46          * @return void
47          */
48         public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
49         {
50                 self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
51
52                 /*
53                 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
54                 BasicAuth::setCurrentUserID();
55                 $_SESSION['authenticated'] = false;
56                 api_direct_messages_destroy('json');
57                 */
58         }
59
60         /**
61          * Test the api_direct_messages_destroy() function with a non-zero ID.
62          *
63          * @return void
64          */
65         public function testApiDirectMessagesDestroyWithId()
66         {
67                 $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
68                 (new Destroy(DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'json']))
69                         ->run([
70                                 'id' => 1
71                         ]);
72         }
73
74         /**
75          * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
76          *
77          * @return void
78          */
79         public function testApiDirectMessagesDestroyWithIdAndVerbose()
80         {
81                 $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']))
82                         ->run([
83                                 'id'                  => 1,
84                                 'friendica_parenturi' => 'parent_uri',
85                                 'friendica_verbose'   => true,
86                         ]);
87
88                 $json = $this->toJson($response);
89
90                 self::assertEquals('error', $json->result);
91                 self::assertEquals('message id not in database', $json->message);
92         }
93
94         /**
95          * Test the api_direct_messages_destroy() function with a non-zero ID.
96          *
97          * @return void
98          */
99         public function testApiDirectMessagesDestroyWithCorrectId()
100         {
101                 $this->loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba());
102                 $ids = DBA::selectToArray('mail', ['id']);
103                 $id  = $ids[0]['id'];
104
105                 $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']))
106                         ->run([
107                                 'id'                => $id,
108                                 'friendica_verbose' => true,
109                         ]);
110
111                 $json = $this->toJson($response);
112
113                 self::assertEquals('ok', $json->result);
114                 self::assertEquals('message deleted', $json->message);
115         }
116 }