3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Factory\Api\Twitter;
25 use Friendica\Factory\Api\Twitter\DirectMessage;
26 use Friendica\Test\FixtureTest;
27 use Friendica\Test\src\Module\Api\ApiTest;
29 class DirectMessageTest extends FixtureTest
32 * Test the api_format_messages() function.
36 public function testApiFormatMessages()
38 $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
39 $ids = DI::dba()->selectToArray('mail', ['id']);
42 $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
43 ->createFromMailId($id, ApiTest::SELF_USER['id'])
46 self::assertEquals('item_title' . "\n" . 'item_body', $directMessage['text']);
47 self::assertIsInt($directMessage['id']);
48 self::assertIsInt($directMessage['recipient_id']);
49 self::assertIsInt($directMessage['sender_id']);
50 self::assertEquals('selfcontact', $directMessage['recipient_screen_name']);
51 self::assertEquals('friendcontact', $directMessage['sender_screen_name']);
55 * Test the api_format_messages() function with HTML.
59 public function testApiFormatMessagesWithHtmlText()
61 $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
62 $ids = DI::dba()->selectToArray('mail', ['id']);
65 $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
66 ->createFromMailId($id, ApiTest::SELF_USER['id'], 'html')
69 self::assertEquals('item_title', $directMessage['title']);
70 self::assertEquals('<strong>item_body</strong>', $directMessage['text']);
74 * Test the api_format_messages() function with plain text.
78 public function testApiFormatMessagesWithPlainText()
80 $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
81 $ids = DI::dba()->selectToArray('mail', ['id']);
84 $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
85 ->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain')
88 self::assertEquals('item_title', $directMessage['title']);
89 self::assertEquals('item_body', $directMessage['text']);
93 * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
97 public function testApiFormatMessagesWithoutUserObjects()
99 self::markTestIncomplete('Needs processing of "getUserObjects" first');
102 $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
103 $ids = DI::dba()->selectToArray('mail', ['id']);
106 $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
107 ->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain', $$GETUSEROBJECTS$$)
110 self::assertTrue(!isset($directMessage['sender']));
111 self::assertTrue(!isset($directMessage['recipient']));