]> git.mxchange.org Git - friendica.git/blob - tests/src/Factory/Api/Twitter/StatusTest.php
Add more special chars at tests
[friendica.git] / tests / src / Factory / Api / Twitter / StatusTest.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\Friendica\Activities;
26 use Friendica\Factory\Api\Twitter\Attachment;
27 use Friendica\Factory\Api\Twitter\Hashtag;
28 use Friendica\Factory\Api\Twitter\Media;
29 use Friendica\Factory\Api\Twitter\Mention;
30 use Friendica\Factory\Api\Twitter\Status;
31 use Friendica\Factory\Api\Twitter\Url;
32 use Friendica\Test\FixtureTest;
33 use Friendica\Test\src\Module\Api\ApiTest;
34
35 class StatusTest extends FixtureTest
36 {
37         protected $statusFactory;
38
39         protected function setUp(): void
40         {
41                 parent::setUp();
42
43                 $this->statusFactory = new Status(
44                         DI::logger(),
45                         DI::dba(),
46                         DI::twitterUser(),
47                         new Hashtag(DI::logger()),
48                         new Media(DI::logger(), DI::baseUrl()),
49                         new Url(DI::logger()),
50                         new Mention(DI::logger(), DI::baseUrl()),
51                         new Activities(DI::logger(), DI::twitterUser()),
52                         new Attachment(DI::logger()), DI::contentItem());
53         }
54
55         /**
56          * Test the api_convert_item() function.
57          *
58          * @return void
59          */
60         public function testApiConvertItem()
61         {
62                 $status = $this->statusFactory
63                         ->createFromItemId(13, ApiTest::SELF_USER['id'])
64                         ->toArray();
65
66                 self::assertStringStartsWith('item_title', $status['text']);
67                 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $status['friendica_html']);
68         }
69
70         /**
71          * Test the api_convert_item() function with an empty item body.
72          *
73          * @return void
74          */
75         public function testApiConvertItemWithoutBody()
76         {
77                 self::markTestIncomplete('Needs a dataset first');
78
79                 /*
80                 $result = api_convert_item(
81                         [
82                                 'network' => 'feed',
83                                 'title'   => 'item_title',
84                                 'uri-id'  => -1,
85                                 'body'    => '',
86                                 'plink'   => 'item_plink'
87                         ]
88                 );
89                 self::assertEquals("item_title", $result['text']);
90                 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
91                 */
92         }
93
94         /**
95          * Test the api_convert_item() function with the title in the body.
96          *
97          * @return void
98          */
99         public function testApiConvertItemWithTitleInBody()
100         {
101                 self::markTestIncomplete('Needs a dataset first');
102
103                 /*
104                 $result = api_convert_item(
105                         [
106                                 'title'  => 'item_title',
107                                 'body'   => 'item_title item_body',
108                                 'uri-id' => 1,
109                         ]
110                 );
111                 self::assertEquals('item_title item_body', $result['text']);
112                 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
113                 */
114         }
115
116         /**
117          * Test the api_get_entitities() function.
118          *
119          * @return void
120          */
121         public function testApiGetEntititiesWithIncludeEntities()
122         {
123                 $status = $this->statusFactory
124                         ->createFromItemId(13, ApiTest::SELF_USER['id'], true)
125                         ->toArray();
126
127                 self::assertIsArray($status['entities']);
128                 self::assertIsArray($status['extended_entities']);
129                 self::assertIsArray($status['entities']['hashtags']);
130                 self::assertIsArray($status['entities']['media']);
131                 self::assertIsArray($status['entities']['urls']);
132                 self::assertIsArray($status['entities']['user_mentions']);
133         }
134
135         /**
136          * Test the api_format_items() function.
137          */
138         public function testApiFormatItems()
139         {
140                 $posts = DI::dba()->selectToArray('post-view', ['uri-id']);
141                 foreach ($posts as $item) {
142                         $status = $this->statusFactory
143                                 ->createFromUriId($item['uri-id'], ApiTest::SELF_USER['id'])
144                                 ->toArray();
145
146                         self::assertIsInt($status['id']);
147                         self::assertIsString($status['text']);
148                 }
149         }
150 }