]> git.mxchange.org Git - friendica.git/commitdiff
Fix Twitter statuses list & reenable tests
authorPhilipp <admin@philipp.info>
Sat, 4 Dec 2021 22:57:52 +0000 (23:57 +0100)
committerPhilipp <admin@philipp.info>
Sun, 5 Dec 2021 19:34:01 +0000 (20:34 +0100)
src/Module/Api/Twitter/Lists/Statuses.php
tests/datasets/api.fixture.php
tests/src/Module/Api/Twitter/Lists/StatusesTest.php

index d647e4a271c09dc764b4f2fce7111d0c32b3082a..9763e4575d9dc761f6b5b5f6016d3be030795a53 100644 (file)
@@ -40,23 +40,23 @@ class Statuses extends BaseApi
                BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
                $uid = BaseApi::getCurrentUserID();
 
-               if (empty($_REQUEST['list_id'])) {
+               if (empty($request['list_id'])) {
                        throw new BadRequestException('list_id not specified');
                }
 
                // params
-               $count           = $_REQUEST['count']    ?? 20;
-               $page            = $_REQUEST['page']     ?? 1;
-               $since_id        = $_REQUEST['since_id'] ?? 0;
-               $max_id          = $_REQUEST['max_id']   ?? 0;
-               $exclude_replies = (!empty($_REQUEST['exclude_replies']) ? 1 : 0);
-               $conversation_id = $_REQUEST['conversation_id'] ?? 0;
+               $count           = $request['count']    ?? 20;
+               $page            = $request['page']     ?? 1;
+               $since_id        = $request['since_id'] ?? 0;
+               $max_id          = $request['max_id']   ?? 0;
+               $exclude_replies = (!empty($request['exclude_replies']) ? 1 : 0);
+               $conversation_id = $request['conversation_id'] ?? 0;
 
                $start = max(0, ($page - 1) * $count);
 
-               $groups    = DBA::selectToArray('group_member', ['contact-id'], ['gid' => 1]);
+               $groups    = DBA::selectToArray('group_member', ['contact-id'], ['gid' => $request['list_id']]);
                $gids      = array_column($groups, 'contact-id');
-               $condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'group-id' => $gids];
+               $condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'contact-id' => $gids];
                $condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]);
 
                if ($max_id > 0) {
@@ -75,7 +75,7 @@ class Statuses extends BaseApi
                $params   = ['order' => ['id' => true], 'limit' => [$start, $count]];
                $statuses = Post::selectForUser($uid, [], $condition, $params);
 
-               $include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
+               $include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true');
 
                $items = [];
                while ($status = DBA::fetch($statuses)) {
index 014692ccd155f987499d49071a32b9f2b5818533..e85313ca617a844a28475be1b80329b375a8db67 100644 (file)
@@ -827,6 +827,13 @@ return [
                        'name'    => 'Private list',
                ],
        ],
+       'group_member' => [
+               [
+                       'id' => 1,
+                       'gid' => 1,
+                       'contact-id' => 42,
+               ],
+       ],
        'search' => [
                [
                        'id'   => 1,
index 8dcb9d33133beb8d993ac5b350fd9ff7c0dbc2a8..5d989b71e74ef856cd078852ff64c4bd549123a9 100644 (file)
@@ -2,6 +2,10 @@
 
 namespace Friendica\Test\src\Module\Api\Twitter\Lists;
 
+use Friendica\App\Router;
+use Friendica\DI;
+use Friendica\Module\Api\Twitter\Lists\Statuses;
+use Friendica\Network\HTTPException\BadRequestException;
 use Friendica\Test\src\Module\Api\ApiTest;
 
 class StatusesTest extends ApiTest
@@ -13,37 +17,41 @@ class StatusesTest extends ApiTest
         */
        public function testApiListsStatuses()
        {
-               // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               // api_lists_statuses('json');
+               $this->expectException(BadRequestException::class);
+
+               $lists = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
+               $lists->run();
        }
 
        /**
         * Test the api_lists_statuses() function with a list ID.
-        * @doesNotPerformAssertions
         */
        public function testApiListsStatusesWithListId()
        {
-               /*
-               $_REQUEST['list_id'] = 1;
-               $_REQUEST['page']    = -1;
-               $_REQUEST['max_id']  = 10;
-               $result              = api_lists_statuses('json');
-               foreach ($result['status'] as $status) {
-                       self::assertStatus($status);
+               $lists    = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
+               $response = $lists->run(['list_id' => 1, 'page' => -1, 'max_id' => 10]);
+
+               $body = (string)$response->getBody();
+
+               self::assertJson($body);
+
+               $json = json_decode($body);
+
+               foreach ($json as $status) {
+                       self::assertIsString($status->text);
+                       self::assertIsInt($status->id);
                }
-               */
        }
 
        /**
         * Test the api_lists_statuses() function with a list ID and a RSS result.
-        *
-        * @return void
         */
        public function testApiListsStatusesWithListIdAndRss()
        {
-               // $_REQUEST['list_id'] = 1;
-               // $result              = api_lists_statuses('rss');
-               // self::assertXml($result, 'statuses');
+               $lists    = new Statuses(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET], ['extension' => 'rss']);
+               $response = $lists->run(['list_id' => 1]);
+
+               self::assertXml((string)$response->getBody());
        }
 
        /**
@@ -53,6 +61,8 @@ class StatusesTest extends ApiTest
         */
        public function testApiListsStatusesWithUnallowedUser()
        {
+               self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
+
                // $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                // BasicAuth::setCurrentUserID();
                // api_lists_statuses('json');