]> git.mxchange.org Git - friendica.git/blob - tests/src/Module/Api/Twitter/Statuses/UserTimelineTest.php
Merge pull request #11141 from urbalazs/language-names
[friendica.git] / tests / src / Module / Api / Twitter / Statuses / UserTimelineTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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\Module\Api\Twitter\Statuses;
23
24 use Friendica\App\Router;
25 use Friendica\Capabilities\ICanCreateResponses;
26 use Friendica\DI;
27 use Friendica\Module\Api\Twitter\Statuses\UserTimeline;
28 use Friendica\Test\src\Module\Api\ApiTest;
29
30 class UserTimelineTest extends ApiTest
31 {
32         /**
33          * Test the api_statuses_user_timeline() function.
34          *
35          * @return void
36          */
37         public function testApiStatusesUserTimeline()
38         {
39                 $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
40                         ->run([
41                                 'user_id'         => 42,
42                                 'max_id'          => 10,
43                                 'exclude_replies' => true,
44                                 'conversation_id' => 7,
45                         ]);
46
47                 $json = $this->toJson($response);
48
49                 self::assertIsArray($json);
50                 self::assertNotEmpty($json);
51                 foreach ($json as $status) {
52                         self::assertIsString($status->text);
53                         self::assertIsInt($status->id);
54                 }
55         }
56
57         /**
58          * Test the api_statuses_user_timeline() function with a negative page parameter.
59          *
60          * @return void
61          */
62         public function testApiStatusesUserTimelineWithNegativePage()
63         {
64                 $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), []))
65                         ->run([
66                                 'user_id' => 42,
67                                 'page'    => -2,
68                         ]);
69
70                 $json = $this->toJson($response);
71
72                 self::assertIsArray($json);
73                 self::assertNotEmpty($json);
74                 foreach ($json as $status) {
75                         self::assertIsString($status->text);
76                         self::assertIsInt($status->id);
77                 }
78         }
79
80         /**
81          * Test the api_statuses_user_timeline() function with an RSS result.
82          *
83          * @return void
84          */
85         public function testApiStatusesUserTimelineWithRss()
86         {
87                 $response = (new UserTimeline(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), [], [
88                         'extension' => ICanCreateResponses::TYPE_RSS
89                 ]))->run();
90
91                 self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
92
93                 self::assertXml((string)$response->getBody(), 'statuses');
94         }
95
96         /**
97          * Test the api_statuses_user_timeline() function with an unallowed user.
98          *
99          * @return void
100          */
101         public function testApiStatusesUserTimelineWithUnallowedUser()
102         {
103                 self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
104
105                 // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
106                 // BasicAuth::setCurrentUserID();
107                 // api_statuses_user_timeline('json');
108         }
109 }