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\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;
35 class StatusTest extends FixtureTest
37 protected $statusFactory;
39 protected function setUp(): void
43 $this->statusFactory = new Status(
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());
56 * Test the api_convert_item() function.
60 public function testApiConvertItem()
62 $status = $this->statusFactory
63 ->createFromItemId(13, ApiTest::SELF_USER['id'])
66 self::assertStringStartsWith('item_title', $status['text']);
67 self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $status['friendica_html']);
71 * Test the api_convert_item() function with an empty item body.
75 public function testApiConvertItemWithoutBody()
77 self::markTestIncomplete('Needs a dataset first');
80 $result = api_convert_item(
83 'title' => 'item_title',
86 'plink' => 'item_plink'
89 self::assertEquals("item_title", $result['text']);
90 self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
95 * Test the api_convert_item() function with the title in the body.
99 public function testApiConvertItemWithTitleInBody()
101 self::markTestIncomplete('Needs a dataset first');
104 $result = api_convert_item(
106 'title' => 'item_title',
107 'body' => 'item_title item_body',
111 self::assertEquals('item_title item_body', $result['text']);
112 self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
117 * Test the api_get_entitities() function.
121 public function testApiGetEntititiesWithIncludeEntities()
123 $status = $this->statusFactory
124 ->createFromItemId(13, ApiTest::SELF_USER['id'], true)
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']);
136 * Test the api_format_items() function.
138 public function testApiFormatItems()
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'])
146 self::assertIsInt($status['id']);
147 self::assertIsString($status['text']);