]> git.mxchange.org Git - friendica.git/blob - tests/src/Factory/Api/Twitter/DirectMessageTest.php
Merge pull request #12697 from MrPetovan/bug/deprecated
[friendica.git] / tests / src / Factory / Api / Twitter / DirectMessageTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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\Factory\Api\Twitter;
23
24 use Friendica\DI;
25 use Friendica\Factory\Api\Twitter\DirectMessage;
26 use Friendica\Test\FixtureTest;
27 use Friendica\Test\src\Module\Api\ApiTest;
28
29 class DirectMessageTest extends FixtureTest
30 {
31         /**
32          * Test the api_format_messages() function.
33          *
34          * @return void
35          */
36         public function testApiFormatMessages()
37         {
38                 $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
39                 $ids = DI::dba()->selectToArray('mail', ['id']);
40                 $id  = $ids[0]['id'];
41
42                 $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
43                         ->createFromMailId($id, ApiTest::SELF_USER['id'])
44                         ->toArray();
45
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']);
52         }
53
54         /**
55          * Test the api_format_messages() function with HTML.
56          *
57          * @return void
58          */
59         public function testApiFormatMessagesWithHtmlText()
60         {
61                 $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
62                 $ids = DI::dba()->selectToArray('mail', ['id']);
63                 $id  = $ids[0]['id'];
64
65                 $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
66                         ->createFromMailId($id, ApiTest::SELF_USER['id'], 'html')
67                         ->toArray();
68
69                 self::assertEquals('item_title', $directMessage['title']);
70                 self::assertEquals('<strong>item_body</strong>', $directMessage['text']);
71         }
72
73         /**
74          * Test the api_format_messages() function with plain text.
75          *
76          * @return void
77          */
78         public function testApiFormatMessagesWithPlainText()
79         {
80                 $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
81                 $ids = DI::dba()->selectToArray('mail', ['id']);
82                 $id  = $ids[0]['id'];
83
84                 $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
85                         ->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain')
86                         ->toArray();
87
88                 self::assertEquals('item_title', $directMessage['title']);
89                 self::assertEquals('item_body', $directMessage['text']);
90         }
91
92         /**
93          * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
94          *
95          * @return void
96          */
97         public function testApiFormatMessagesWithoutUserObjects()
98         {
99                 self::markTestIncomplete('Needs processing of "getUserObjects" first');
100
101                 /*
102                  $this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
103                 $ids = DI::dba()->selectToArray('mail', ['id']);
104                 $id  = $ids[0]['id'];
105
106                 $directMessage = (new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser()))
107                         ->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain', $$GETUSEROBJECTS$$)
108                         ->toArray();
109
110                 self::assertTrue(!isset($directMessage['sender']));
111                 self::assertTrue(!isset($directMessage['recipient']));
112                 */
113         }
114 }