]> git.mxchange.org Git - friendica.git/blobdiff - tests/legacy/ApiTest.php
api_get_user isn't used without parameters anymore
[friendica.git] / tests / legacy / ApiTest.php
index 1ada31bcc7e31908d18b8105c5e6013847f304e7..34f3f6659b519964db1c3e22a0a2c4a3a1d006a1 100644 (file)
@@ -114,6 +114,7 @@ class ApiTest extends FixtureTest
                        'authenticated' => true,
                        'uid'           => $this->selfUser['id']
                ];
+               BasicAuth::setCurrentUserID($this->selfUser['id']);
        }
 
        /**
@@ -223,7 +224,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiUser()
        {
-               self::assertEquals($this->selfUser['id'], api_user());
+               self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
        }
 
        /**
@@ -310,6 +311,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiLoginWithoutLogin()
        {
+               BasicAuth::setCurrentUserID();
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                BasicAuth::getCurrentUserID(true);
        }
@@ -323,6 +325,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);
@@ -357,6 +360,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiLoginWithCorrectLogin()
        {
+               BasicAuth::setCurrentUserID();
                $_SERVER['PHP_AUTH_USER'] = 'Test user';
                $_SERVER['PHP_AUTH_PW']   = 'password';
                BasicAuth::getCurrentUserID(true);
@@ -370,6 +374,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiLoginWithRemoteUser()
        {
+               BasicAuth::setCurrentUserID();
                $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
                $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
                BasicAuth::getCurrentUserID(true);
@@ -584,7 +589,7 @@ class ApiTest extends FixtureTest
        public function testApiRssExtra()
        {
                $user_info = ['url' => 'user_url', 'lang' => 'en'];
-               $result    = api_rss_extra($this->app, [], $user_info);
+               $result    = api_rss_extra([], $user_info);
                self::assertEquals($user_info, $result['$user']);
                self::assertEquals($user_info['url'], $result['$rss']['alternate']);
                self::assertArrayHasKey('self', $result['$rss']);
@@ -602,7 +607,7 @@ class ApiTest extends FixtureTest
         */
        public function testApiRssExtraWithoutUserInfo()
        {
-               $result = api_rss_extra($this->app, [], null);
+               $result = api_rss_extra([], null);
                self::assertIsArray($result['$user']);
                self::assertArrayHasKey('alternate', $result['$rss']);
                self::assertArrayHasKey('self', $result['$rss']);
@@ -640,8 +645,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']);
@@ -654,10 +659,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']);
@@ -670,10 +675,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']);
@@ -686,13 +691,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']);
@@ -706,10 +711,14 @@ 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());
+               */
        }
 
        /**
@@ -719,8 +728,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetId()
        {
-               $_GET['user_id'] = $this->otherUser['id'];
-               self::assertOtherUser(api_get_user());
+               // $_GET['user_id'] = $this->otherUser['id'];
+               // self::assertOtherUser(api_get_user());
        }
 
        /**
@@ -730,9 +739,9 @@ 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);
+               // $_GET['user_id'] = $this->wrongUserId;
+               // self::assertOtherUser(api_get_user());
        }
 
        /**
@@ -742,8 +751,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetName()
        {
-               $_GET['screen_name'] = $this->selfUser['nick'];
-               self::assertSelfUser(api_get_user());
+               // $_GET['screen_name'] = $this->selfUser['nick'];
+               // self::assertSelfUser(api_get_user());
        }
 
        /**
@@ -753,8 +762,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithGetUrl()
        {
-               $_GET['profileurl'] = $this->selfUser['nurl'];
-               self::assertSelfUser(api_get_user());
+               // $_GET['profileurl'] = $this->selfUser['nurl'];
+               // self::assertSelfUser(api_get_user());
        }
 
        /**
@@ -764,10 +773,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());
        }
 
        /**
@@ -777,9 +786,9 @@ class ApiTest extends FixtureTest
         */
        public function testApiGetUserWithCalledApi()
        {
-               global $called_api;
-               $called_api = ['api', 'api_path'];
-               self::assertSelfUser(api_get_user());
+               // global $called_api;
+               // $called_api = ['api', 'api_path'];
+               // self::assertSelfUser(api_get_user());
        }
 
        /**
@@ -996,6 +1005,7 @@ class ApiTest extends FixtureTest
        public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_account_verify_credentials('json');
        }
@@ -1066,6 +1076,7 @@ class ApiTest extends FixtureTest
        public function testApiStatusesMediapWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_statuses_mediap('json');
        }
@@ -1118,6 +1129,7 @@ class ApiTest extends FixtureTest
        public function testApiStatusesUpdateWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_statuses_update('json');
        }
@@ -1171,6 +1183,7 @@ class ApiTest extends FixtureTest
        public function testApiMediaUploadWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_media_upload();
        }
@@ -1421,6 +1434,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_search('json');
        }
 
@@ -1477,6 +1491,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_statuses_home_timeline('json');
        }
 
@@ -1548,6 +1563,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_statuses_public_timeline('json');
        }
 
@@ -1602,6 +1618,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_statuses_networkpublic_timeline('json');
        }
 
@@ -1665,6 +1682,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_statuses_show('json');
        }
 
@@ -1706,6 +1724,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_conversation_show('json');
        }
 
@@ -1728,6 +1747,7 @@ class ApiTest extends FixtureTest
        public function testApiStatusesRepeatWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_statuses_repeat('json');
        }
@@ -1768,6 +1788,7 @@ class ApiTest extends FixtureTest
        public function testApiStatusesDestroyWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_statuses_destroy('json');
        }
@@ -1820,6 +1841,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_statuses_mentions('json');
        }
 
@@ -1887,6 +1909,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_statuses_user_timeline('json');
        }
 
@@ -1975,6 +1998,7 @@ class ApiTest extends FixtureTest
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_favorites_create_destroy('json');
        }
@@ -2015,6 +2039,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_favorites('json');
        }
 
@@ -2388,6 +2413,7 @@ class ApiTest extends FixtureTest
        public function testApiListsOwnershipsWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_lists_ownerships('json');
        }
@@ -2440,6 +2466,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_lists_statuses('json');
        }
 
@@ -2628,6 +2655,7 @@ class ApiTest extends FixtureTest
        public function testApiDirectMessagesNewWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_direct_messages_new('json');
        }
@@ -2732,6 +2760,7 @@ class ApiTest extends FixtureTest
        public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_direct_messages_destroy('json');
        }
@@ -2866,6 +2895,7 @@ class ApiTest extends FixtureTest
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
                $_SESSION['allow_api'] = false;
                $_GET['screen_name']   = $this->selfUser['nick'];
+               BasicAuth::setCurrentUserID();
                api_direct_messages_box('json', 'sentbox', 'false');
        }
 
@@ -2952,6 +2982,7 @@ class ApiTest extends FixtureTest
        public function testApiFrPhotosListWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_fr_photos_list('json');
        }
@@ -2973,6 +3004,7 @@ class ApiTest extends FixtureTest
        public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_fr_photo_create_update('json');
        }
@@ -3028,6 +3060,7 @@ class ApiTest extends FixtureTest
        public function testApiFrPhotoDetailWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_fr_photo_detail('json');
        }
@@ -3073,6 +3106,7 @@ class ApiTest extends FixtureTest
        public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
        {
                $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
+               BasicAuth::setCurrentUserID();
                $_SESSION['authenticated'] = false;
                api_account_update_profile_image('json');
        }