]> git.mxchange.org Git - friendica.git/blobdiff - tests/legacy/ApiTest.php
Tests
[friendica.git] / tests / legacy / ApiTest.php
index 550bc54c27d25d297d709083ba93fd4ff9691b44..c8f0ae914245a6bc07b2da70a1489d2147df9364 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\Protocol;
 use Friendica\DI;
+use Friendica\Model\Post;
 use Friendica\Module\Api\ApiResponse;
 use Friendica\Module\BaseApi;
 use Friendica\Network\HTTPException;
@@ -110,7 +111,6 @@ class ApiTest extends FixtureTest
 
                // Most API require login so we force the session
                $_SESSION = [
-                       'allow_api'     => true,
                        'authenticated' => true,
                        'uid'           => $this->selfUser['id']
                ];
@@ -147,7 +147,6 @@ class ApiTest extends FixtureTest
        {
                self::assertEquals($this->otherUser['id'], $user['id']);
                self::assertEquals($this->otherUser['id'], $user['id_str']);
-               self::assertEquals(0, $user['self']);
                self::assertEquals($this->otherUser['name'], $user['name']);
                self::assertEquals($this->otherUser['nick'], $user['screen_name']);
                self::assertFalse($user['verified']);
@@ -224,7 +223,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiUser()
        {
-               self::assertEquals($this->selfUser['id'], api_user());
+               self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
        }
 
        /**
@@ -234,8 +233,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiUserWithUnallowedUser()
        {
-               $_SESSION = ['allow_api' => false];
-               self::assertEquals(false, api_user());
+               // self::assertEquals(false, api_user());
        }
 
        /**
@@ -245,7 +243,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiSource()
        {
-               self::assertEquals('api', api_source());
+               self::assertEquals('api', BasicAuth::getCurrentApplicationToken()['name']);
        }
 
        /**
@@ -256,7 +254,7 @@ class ApiTest extends FixtureTest
        public function testApiSourceWithTwidere()
        {
                $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
-               self::assertEquals('Twidere', api_source());
+               self::assertEquals('Twidere', BasicAuth::getCurrentApplicationToken()['name']);
        }
 
        /**
@@ -266,8 +264,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiSourceWithGet()
        {
-               $_GET['source'] = 'source_name';
-               self::assertEquals('source_name', api_source());
+               $_REQUEST['source'] = 'source_name';
+               self::assertEquals('source_name', BasicAuth::getCurrentApplicationToken()['name']);
        }
 
        /**
@@ -277,7 +275,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiDate()
        {
-               self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
+               self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
        }
 
        /**
@@ -311,6 +309,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiLoginWithoutLogin()
        {
+               BasicAuth::setCurrentUserID();
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::getCurrentUserID(true);
        }
@@ -324,6 +323,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiLoginWithBadLogin()
        {
+               BasicAuth::setCurrentUserID();
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                $_SERVER['PHP_AUTH_USER'] = 'user@server';
                BasicAuth::getCurrentUserID(true);
@@ -358,6 +358,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiLoginWithCorrectLogin()
        {
+               BasicAuth::setCurrentUserID();
                $_SERVER['PHP_AUTH_USER'] = 'Test user';
                $_SERVER['PHP_AUTH_PW']   = 'password';
                BasicAuth::getCurrentUserID(true);
@@ -371,42 +372,12 @@ class ApiTest extends FixtureTest
         */
        public function testApiLoginWithRemoteUser()
        {
+               BasicAuth::setCurrentUserID();
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
                BasicAuth::getCurrentUserID(true);
        }
 
-       /**
-        * Test the api_check_method() function.
-        *
-        * @return void
-        */
-       public function testApiCheckMethod()
-       {
-               self::assertFalse(api_check_method('method'));
-       }
-
-       /**
-        * Test the api_check_method() function with a correct method.
-        *
-        * @return void
-        */
-       public function testApiCheckMethodWithCorrectMethod()
-       {
-               $_SERVER['REQUEST_METHOD'] = 'method';
-               self::assertTrue(api_check_method('method'));
-       }
-
-       /**
-        * Test the api_check_method() function with a wildcard.
-        *
-        * @return void
-        */
-       public function testApiCheckMethodWithWildcard()
-       {
-               self::assertTrue(api_check_method('*'));
-       }
-
        /**
         * Test the api_call() function.
         *
@@ -584,6 +555,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiRssExtra()
        {
+               /*
                $user_info = ['url' => 'user_url', 'lang' => 'en'];
                $result    = api_rss_extra([], $user_info);
                self::assertEquals($user_info, $result['$user']);
@@ -594,6 +566,7 @@ class ApiTest extends FixtureTest
                self::assertArrayHasKey('atom_updated', $result['$rss']);
                self::assertArrayHasKey('language', $result['$rss']);
                self::assertArrayHasKey('logo', $result['$rss']);
+               */
        }
 
        /**
@@ -603,6 +576,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiRssExtraWithoutUserInfo()
        {
+               /*
                $result = api_rss_extra([], null);
                self::assertIsArray($result['$user']);
                self::assertArrayHasKey('alternate', $result['$rss']);
@@ -612,26 +586,7 @@ class ApiTest extends FixtureTest
                self::assertArrayHasKey('atom_updated', $result['$rss']);
                self::assertArrayHasKey('language', $result['$rss']);
                self::assertArrayHasKey('logo', $result['$rss']);
-       }
-
-       /**
-        * Test the api_unique_id_to_nurl() function.
-        *
-        * @return void
-        */
-       public function testApiUniqueIdToNurl()
-       {
-               self::assertFalse(api_unique_id_to_nurl($this->wrongUserId));
-       }
-
-       /**
-        * Test the api_unique_id_to_nurl() function with a correct ID.
-        *
-        * @return void
-        */
-       public function testApiUniqueIdToNurlWithCorrectId()
-       {
-               self::assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
+               */
        }
 
        /**
@@ -641,8 +596,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUser()
        {
-               $user = api_get_user();
-               self::assertSelfUser($user);
+               // $user = api_get_user();
+               // self::assertSelfUser($user);
                // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
                // self::assertEquals('6fdbe8', $user['profile_link_color']);
                // self::assertEquals('ededed', $user['profile_background_color']);
@@ -655,10 +610,10 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithFrioSchema()
        {
-               $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
-               $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
-               $user = api_get_user();
-               self::assertSelfUser($user);
+               // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
+               // $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
+               // $user = api_get_user();
+               // self::assertSelfUser($user);
                // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
                // self::assertEquals('6fdbe8', $user['profile_link_color']);
                // self::assertEquals('ededed', $user['profile_background_color']);
@@ -671,10 +626,10 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithEmptyFrioSchema()
        {
-               $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
-               $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
-               $user = api_get_user();
-               self::assertSelfUser($user);
+               // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
+               // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
+               // $user = api_get_user();
+               // self::assertSelfUser($user);
                // self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
                // self::assertEquals('6fdbe8', $user['profile_link_color']);
                // self::assertEquals('ededed', $user['profile_background_color']);
@@ -687,13 +642,13 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithCustomFrioSchema()
        {
-               $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
-               $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
-               $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
-               $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
-               $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
-               $user = api_get_user();
-               self::assertSelfUser($user);
+               // $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
+               // $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
+               // $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
+               // $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
+               // $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
+               // $user = api_get_user();
+               // self::assertSelfUser($user);
                // self::assertEquals('123456', $user['profile_sidebar_fill_color']);
                // self::assertEquals('123456', $user['profile_link_color']);
                // self::assertEquals('123456', $user['profile_background_color']);
@@ -707,11 +662,13 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithoutApiUser()
        {
+               // api_get_user() with empty parameters is not used anymore
+               /*
                $_SERVER['PHP_AUTH_USER'] = 'Test user';
                $_SERVER['PHP_AUTH_PW']   = 'password';
-               $_SESSION['allow_api']    = false;
                BasicAuth::setCurrentUserID();
                self::assertFalse(api_get_user());
+               */
        }
 
        /**
@@ -721,8 +678,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetId()
        {
-               $_GET['user_id'] = $this->otherUser['id'];
-               self::assertOtherUser(api_get_user());
+               // self::assertOtherUser(api_get_user());
        }
 
        /**
@@ -732,9 +688,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithWrongGetId()
        {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               $_GET['user_id'] = $this->wrongUserId;
-               self::assertOtherUser(api_get_user());
+               // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
+               // self::assertOtherUser(api_get_user());
        }
 
        /**
@@ -744,8 +699,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetName()
        {
-               $_GET['screen_name'] = $this->selfUser['nick'];
-               self::assertSelfUser(api_get_user());
+               // self::assertSelfUser(api_get_user());
        }
 
        /**
@@ -755,8 +709,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetUrl()
        {
-               $_GET['profileurl'] = $this->selfUser['nurl'];
-               self::assertSelfUser(api_get_user());
+               // self::assertSelfUser(api_get_user());
        }
 
        /**
@@ -766,10 +719,10 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithNumericCalledApi()
        {
-               global $called_api;
-               $called_api         = ['api_path'];
-               DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
-               self::assertOtherUser(api_get_user());
+               // global $called_api;
+               // $called_api         = ['api_path'];
+               // DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
+               // self::assertOtherUser(api_get_user());
        }
 
        /**
@@ -779,63 +732,9 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithCalledApi()
        {
-               global $called_api;
-               $called_api = ['api', 'api_path'];
-               self::assertSelfUser(api_get_user());
-       }
-
-       /**
-        * Test the api_get_user() function with a valid user.
-        *
-        * @return void
-        */
-       public function testApiGetUserWithCorrectUser()
-       {
-               self::assertOtherUser(api_get_user($this->otherUser['id']));
-       }
-
-       /**
-        * Test the api_get_user() function with a wrong user ID.
-        *
-        * @return void
-        */
-       public function testApiGetUserWithWrongUser()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               self::assertOtherUser(api_get_user($this->wrongUserId));
-       }
-
-       /**
-        * Test the api_get_user() function with a 0 user ID.
-        *
-        * @return void
-        */
-       public function testApiGetUserWithZeroUser()
-       {
-               self::assertSelfUser(api_get_user(0));
-       }
-
-       /**
-        * Test the api_item_get_user() function.
-        *
-        * @return void
-        */
-       public function testApiItemGetUser()
-       {
-               $users = api_item_get_user($this->app, []);
-               self::assertSelfUser($users[0]);
-       }
-
-       /**
-        * Test the api_item_get_user() function with a different item parent.
-        *
-        * @return void
-        */
-       public function testApiItemGetUserWithDifferentParent()
-       {
-               $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
-               self::assertSelfUser($users[0]);
-               self::assertEquals($users[0], $users[1]);
+               // global $called_api;
+               // $called_api = ['api', 'api_path'];
+               // self::assertSelfUser(api_get_user());
        }
 
        /**
@@ -997,7 +896,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_account_verify_credentials('json');
        }
@@ -1067,9 +967,9 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesMediapWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['authenticated'] = false;
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
+               $_SESSION['authenticated'] = false;
                api_statuses_mediap('json');
        }
 
@@ -1120,7 +1020,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesUpdateWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_statuses_update('json');
        }
@@ -1173,7 +1074,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiMediaUploadWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_media_upload();
        }
@@ -1228,8 +1130,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusShowWithJson()
        {
-               $result = api_status_show('json', 1);
-               self::assertStatus($result['status']);
+               // $result = api_status_show('json', 1);
+               // self::assertStatus($result['status']);
        }
 
        /**
@@ -1237,8 +1139,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusShowWithXml()
        {
-               $result = api_status_show('xml', 1);
-               self::assertXml($result, 'statuses');
+               // $result = api_status_show('xml', 1);
+               // self::assertXml($result, 'statuses');
        }
 
        /**
@@ -1246,9 +1148,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetLastStatus()
        {
-               $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
-
-               self::assertNotNull($item);
+               // $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']);
+               // self::assertNotNull($item);
        }
 
        /**
@@ -1264,7 +1165,6 @@ class ApiTest extends FixtureTest
                self::assertEquals('DFRN', $result['user']['location']);
                self::assertEquals($this->selfUser['name'], $result['user']['name']);
                self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
-               self::assertEquals('dfrn', $result['user']['network']);
                self::assertTrue($result['user']['verified']);
        }
 
@@ -1421,9 +1321,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiSearchWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_search('json');
        }
@@ -1478,9 +1376,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesHomeTimelineWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_statuses_home_timeline('json');
        }
@@ -1550,9 +1446,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesPublicTimelineWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_statuses_public_timeline('json');
        }
@@ -1605,9 +1499,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_statuses_networkpublic_timeline('json');
        }
@@ -1669,9 +1561,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesShowWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_statuses_show('json');
        }
@@ -1711,9 +1601,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiConversationShowWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_conversation_show('json');
        }
@@ -1736,7 +1624,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesRepeatWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_statuses_repeat('json');
        }
@@ -1776,7 +1665,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesDestroyWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_statuses_destroy('json');
        }
@@ -1826,9 +1716,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesMentionsWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_statuses_mentions('json');
        }
@@ -1851,10 +1739,12 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesUserTimeline()
        {
+               $_REQUEST['user_id']         = 42;
                $_REQUEST['max_id']          = 10;
                $_REQUEST['exclude_replies'] = true;
-               $_REQUEST['conversation_id'] = 1;
-               $result                      = api_statuses_user_timeline('json');
+               $_REQUEST['conversation_id'] = 7;
+
+               $result = api_statuses_user_timeline('json');
                self::assertNotEmpty($result['status']);
                foreach ($result['status'] as $status) {
                        self::assertStatus($status);
@@ -1868,8 +1758,10 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesUserTimelineWithNegativePage()
        {
-               $_REQUEST['page'] = -2;
-               $result           = api_statuses_user_timeline('json');
+               $_REQUEST['user_id'] = 42;
+               $_REQUEST['page']    = -2;
+
+               $result = api_statuses_user_timeline('json');
                self::assertNotEmpty($result['status']);
                foreach ($result['status'] as $status) {
                        self::assertStatus($status);
@@ -1894,9 +1786,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiStatusesUserTimelineWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_statuses_user_timeline('json');
        }
@@ -1984,8 +1874,9 @@ class ApiTest extends FixtureTest
         */
        public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_favorites_create_destroy('json');
        }
@@ -2023,9 +1914,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiFavoritesWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_favorites('json');
        }
@@ -2108,6 +1997,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiConvertItem()
        {
+               /*
                $result = api_convert_item(
                        [
                                'network' => 'feed',
@@ -2142,6 +2032,7 @@ class ApiTest extends FixtureTest
                );
                self::assertStringStartsWith('item_title', $result['text']);
                self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
+               */
        }
 
        /**
@@ -2151,6 +2042,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiConvertItemWithoutBody()
        {
+               /*
                $result = api_convert_item(
                        [
                                'network' => 'feed',
@@ -2162,6 +2054,7 @@ class ApiTest extends FixtureTest
                );
                self::assertEquals("item_title", $result['text']);
                self::assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
+               */
        }
 
        /**
@@ -2171,6 +2064,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiConvertItemWithTitleInBody()
        {
+               /*
                $result = api_convert_item(
                        [
                                'title'  => 'item_title',
@@ -2180,6 +2074,7 @@ class ApiTest extends FixtureTest
                );
                self::assertEquals('item_title item_body', $result['text']);
                self::assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
+               */
        }
 
        /**
@@ -2189,8 +2084,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetAttachments()
        {
-               $body = 'body';
-               self::assertEmpty(api_get_attachments($body, 0));
+               // $body = 'body';
+               // self::assertEmpty(api_get_attachments($body, 0));
        }
 
        /**
@@ -2200,8 +2095,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetAttachmentsWithImage()
        {
-               $body = '[img]http://via.placeholder.com/1x1.png[/img]';
-               self::assertIsArray(api_get_attachments($body, 0));
+               // $body = '[img]http://via.placeholder.com/1x1.png[/img]';
+               // self::assertIsArray(api_get_attachments($body, 0));
        }
 
        /**
@@ -2211,9 +2106,9 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetAttachmentsWithImageAndAndStatus()
        {
-               $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
-               $body                       = '[img]http://via.placeholder.com/1x1.png[/img]';
-               self::assertIsArray(api_get_attachments($body, 0));
+               // $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
+               // $body                       = '[img]http://via.placeholder.com/1x1.png[/img]';
+               // self::assertIsArray(api_get_attachments($body, 0));
        }
 
        /**
@@ -2223,8 +2118,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetEntitities()
        {
-               $text = 'text';
-               self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
+               // $text = 'text';
+               // self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
        }
 
        /**
@@ -2234,6 +2129,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetEntititiesWithIncludeEntities()
        {
+               /*
                $_REQUEST['include_entities'] = 'true';
                $text                         = 'text';
                $result                       = api_get_entitities($text, 'bbcode', 0);
@@ -2241,6 +2137,7 @@ class ApiTest extends FixtureTest
                self::assertIsArray($result['symbols']);
                self::assertIsArray($result['urls']);
                self::assertIsArray($result['user_mentions']);
+               */
        }
 
        /**
@@ -2250,42 +2147,12 @@ class ApiTest extends FixtureTest
         */
        public function testApiFormatItemsEmbededImages()
        {
+               /*
                self::assertEquals(
                        'text ' . DI::baseUrl() . '/display/item_guid',
                        api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
                );
-       }
-
-       /**
-        * Test the api_contactlink_to_array() function.
-        *
-        * @return void
-        */
-       public function testApiContactlinkToArray()
-       {
-               self::assertEquals(
-                       [
-                               'name' => 'text',
-                               'url'  => '',
-                       ],
-                       api_contactlink_to_array('text')
-               );
-       }
-
-       /**
-        * Test the api_contactlink_to_array() function with an URL.
-        *
-        * @return void
-        */
-       public function testApiContactlinkToArrayWithUrl()
-       {
-               self::assertEquals(
-                       [
-                               'name' => ['link_text'],
-                               'url'  => ['url'],
-                       ],
-                       api_contactlink_to_array('text <a href="url">link_text</a>')
-               );
+               */
        }
 
        /**
@@ -2295,8 +2162,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiFormatItemsActivities()
        {
-               $item   = ['uid' => 0, 'uri' => ''];
-               $result = api_format_items_activities($item);
+               $item   = ['uid' => 0, 'uri-id' => 1];
+               $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']);
                self::assertArrayHasKey('like', $result);
                self::assertArrayHasKey('dislike', $result);
                self::assertArrayHasKey('attendyes', $result);
@@ -2311,8 +2178,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiFormatItemsActivitiesWithXml()
        {
-               $item   = ['uid' => 0, 'uri' => ''];
-               $result = api_format_items_activities($item, 'xml');
+               $item   = ['uid' => 0, 'uri-id' => 1];
+               $result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml');
                self::assertArrayHasKey('friendica:like', $result);
                self::assertArrayHasKey('friendica:dislike', $result);
                self::assertArrayHasKey('friendica:attendyes', $result);
@@ -2326,23 +2193,13 @@ class ApiTest extends FixtureTest
         */
        public function testApiFormatItems()
        {
-               $items  = [
-                       [
-                               'item_network'   => 'item_network',
-                               'source'         => 'web',
-                               'coord'          => '5 7',
-                               'body'           => '',
-                               'verb'           => '',
-                               'author-id'      => 43,
-                               'author-network' => Protocol::DFRN,
-                               'author-link'    => 'http://localhost/profile/othercontact',
-                               'plink'          => '',
-                       ]
-               ];
-               $result = api_format_items($items, ['id' => 0], true);
-               foreach ($result as $status) {
+               /*
+               $items = Post::selectToArray([], ['uid' => 42]);
+               foreach ($items as $item) {
+                       $status = api_format_item($item);
                        self::assertStatus($status);
                }
+               */
        }
 
        /**
@@ -2351,21 +2208,13 @@ class ApiTest extends FixtureTest
         */
        public function testApiFormatItemsWithXml()
        {
-               $items  = [
-                       [
-                               'coord'          => '5 7',
-                               'body'           => '',
-                               'verb'           => '',
-                               'author-id'      => 43,
-                               'author-network' => Protocol::DFRN,
-                               'author-link'    => 'http://localhost/profile/othercontact',
-                               'plink'          => '',
-                       ]
-               ];
-               $result = api_format_items($items, ['id' => 0], true, 'xml');
-               foreach ($result as $status) {
+               /*
+               $items = Post::selectToArray([], ['uid' => 42]);
+               foreach ($items as $item) {
+                       $status = api_format_item($item, 'xml');
                        self::assertStatus($status);
                }
+               */
        }
 
        /**
@@ -2399,7 +2248,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiListsOwnershipsWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_lists_ownerships('json');
        }
@@ -2449,9 +2299,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiListsStatusesWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_lists_statuses('json');
        }
@@ -2640,7 +2488,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiDirectMessagesNewWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_direct_messages_new('json');
        }
@@ -2666,9 +2515,9 @@ class ApiTest extends FixtureTest
        public function testApiDirectMessagesNewWithScreenName()
        {
                $this->app->setLoggedInUserNickname($this->selfUser['nick']);
-               $_POST['text']        = 'message_text';
-               $_POST['screen_name'] = $this->friendUser['nick'];
-               $result               = api_direct_messages_new('json');
+               $_POST['text']    = 'message_text';
+               $_POST['user_id'] = $this->friendUser['id'];
+               $result           = api_direct_messages_new('json');
                self::assertStringContainsString('message_text', $result['direct_message']['text']);
                self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
                self::assertEquals(1, $result['direct_message']['friendica_seen']);
@@ -2682,10 +2531,10 @@ class ApiTest extends FixtureTest
        public function testApiDirectMessagesNewWithTitle()
        {
                $this->app->setLoggedInUserNickname($this->selfUser['nick']);
-               $_POST['text']        = 'message_text';
-               $_POST['screen_name'] = $this->friendUser['nick'];
-               $_REQUEST['title']    = 'message_title';
-               $result               = api_direct_messages_new('json');
+               $_POST['text']     = 'message_text';
+               $_POST['user_id']  = $this->friendUser['id'];
+               $_REQUEST['title'] = 'message_title';
+               $result            = api_direct_messages_new('json');
                self::assertStringContainsString('message_text', $result['direct_message']['text']);
                self::assertStringContainsString('message_title', $result['direct_message']['text']);
                self::assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
@@ -2700,9 +2549,9 @@ class ApiTest extends FixtureTest
        public function testApiDirectMessagesNewWithRss()
        {
                $this->app->setLoggedInUserNickname($this->selfUser['nick']);
-               $_POST['text']        = 'message_text';
-               $_POST['screen_name'] = $this->friendUser['nick'];
-               $result               = api_direct_messages_new('rss');
+               $_POST['text']    = 'message_text';
+               $_POST['user_id'] = $this->friendUser['id'];
+               $result           = api_direct_messages_new('rss');
                self::assertXml($result, 'direct-messages');
        }
 
@@ -2744,7 +2593,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_direct_messages_destroy('json');
        }
@@ -2876,9 +2726,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiDirectMessagesBoxWithUnallowedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['allow_api'] = false;
-               $_GET['screen_name']   = $this->selfUser['nick'];
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::setCurrentUserID();
                api_direct_messages_box('json', 'sentbox', 'false');
        }
@@ -2965,7 +2813,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiFrPhotosListWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_fr_photos_list('json');
        }
@@ -2986,7 +2835,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_fr_photo_create_update('json');
        }
@@ -3041,7 +2891,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiFrPhotoDetailWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_fr_photo_detail('json');
        }
@@ -3086,7 +2937,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
        {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_account_update_profile_image('json');
        }
@@ -3117,7 +2969,6 @@ class ApiTest extends FixtureTest
                self::assertEquals($this->selfUser['id'], $result['user']['cid']);
                self::assertEquals('DFRN', $result['user']['location']);
                self::assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
-               self::assertEquals('dfrn', $result['user']['network']);
                self::assertEquals('new_name', $result['user']['name']);
                self::assertEquals('new_description', $result['user']['description']);
        }
@@ -3129,7 +2980,7 @@ class ApiTest extends FixtureTest
         */
        public function testCheckAclInput()
        {
-               $result = check_acl_input('<aclstring>');
+               $result = check_acl_input('<aclstring>', BaseApi::getCurrentUserID());
                // Where does this result come from?
                self::assertEquals(1, $result);
        }
@@ -3141,7 +2992,7 @@ class ApiTest extends FixtureTest
         */
        public function testCheckAclInputWithEmptyAclString()
        {
-               $result = check_acl_input(' ');
+               $result = check_acl_input(' ', BaseApi::getCurrentUserID());
                self::assertFalse($result);
        }
 
@@ -3185,21 +3036,6 @@ class ApiTest extends FixtureTest
                $this->markTestIncomplete();
        }
 
-       /**
-        * Test the api_in_reply_to() function.
-        *
-        * @return void
-        */
-       public function testApiInReplyTo()
-       {
-               $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
-               self::assertArrayHasKey('status_id', $result);
-               self::assertArrayHasKey('user_id', $result);
-               self::assertArrayHasKey('status_id_str', $result);
-               self::assertArrayHasKey('user_id_str', $result);
-               self::assertArrayHasKey('screen_name', $result);
-       }
-
        /**
         * Test the api_in_reply_to() function with a valid item.
         *
@@ -3222,18 +3058,6 @@ class ApiTest extends FixtureTest
                self::assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
        }
 
-       /**
-        * Test the api_best_nickname() function.
-        *
-        * @return void
-        */
-       public function testApiBestNickname()
-       {
-               $contacts = [];
-               $result   = api_best_nickname($contacts);
-               self::assertNull($result);
-       }
-
        /**
         * Test the api_best_nickname() function with contacts.
         *