3 namespace Friendica\Test\src\Module\Api\Twitter\DirectMessages;
5 use Friendica\App\Router;
6 use Friendica\Database\DBA;
8 use Friendica\Module\Api\Twitter\DirectMessages\Destroy;
9 use Friendica\Test\src\Module\Api\ApiTest;
11 class DestroyTest extends ApiTest
14 * Test the api_direct_messages_destroy() function.
18 public function testApiDirectMessagesDestroy()
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']))
26 * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
30 public function testApiDirectMessagesDestroyWithVerbose()
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']))
34 'friendica_verbose' => true,
37 $json = $this->toJson($response);
39 self::assertEquals('error', $json->result);
40 self::assertEquals('message id or parenturi not specified', $json->message);
44 * Test the api_direct_messages_destroy() function without an authenticated user.
48 public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
50 self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
53 $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
54 BasicAuth::setCurrentUserID();
55 $_SESSION['authenticated'] = false;
56 api_direct_messages_destroy('json');
61 * Test the api_direct_messages_destroy() function with a non-zero ID.
65 public function testApiDirectMessagesDestroyWithId()
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']))
75 * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
79 public function testApiDirectMessagesDestroyWithIdAndVerbose()
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']))
84 'friendica_parenturi' => 'parent_uri',
85 'friendica_verbose' => true,
88 $json = $this->toJson($response);
90 self::assertEquals('error', $json->result);
91 self::assertEquals('message id not in database', $json->message);
95 * Test the api_direct_messages_destroy() function with a non-zero ID.
99 public function testApiDirectMessagesDestroyWithCorrectId()
101 $this->loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba());
102 $ids = DBA::selectToArray('mail', ['id']);
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']))
108 'friendica_verbose' => true,
111 $json = $this->toJson($response);
113 self::assertEquals('ok', $json->result);
114 self::assertEquals('message deleted', $json->message);