]> git.mxchange.org Git - friendica.git/blobdiff - tests/legacy/ApiTest.php
Migrate Api\RateLimitStatus
[friendica.git] / tests / legacy / ApiTest.php
index af9d608bfe94dc6b78214a94a7125ae09b6fbae9..3bf14a31bc88cfb3f4e3a7d3d7dc8a8644269004 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\Module\Api\ApiResponse;
 use Friendica\Module\BaseApi;
 use Friendica\Network\HTTPException;
 use Friendica\Security\BasicAuth;
@@ -477,6 +478,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiCallWithNoResult()
        {
+               // @todo How to test the new API?
+               /*
                global $API;
                $API['api_path']           = [
                        'method' => 'method',
@@ -493,6 +496,7 @@ class ApiTest extends FixtureTest
                        '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
                        api_call($this->app, $args)
                );
+               */
        }
 
        /**
@@ -503,10 +507,13 @@ class ApiTest extends FixtureTest
         */
        public function testApiCallWithUninplementedApi()
        {
+               // @todo How to test the new API?
+               /*
                self::assertEquals(
                        '{"status":{"error":"Not Found","code":"404 Not Found","request":""}}',
                        api_call($this->app)
                );
+               */
        }
 
        /**
@@ -623,6 +630,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiCallWithWrongMethod()
        {
+               // Shouldn't be needed anymore due to the router?
+               /*
                global $API;
                $API['api_path'] = ['method' => 'method'];
 
@@ -634,6 +643,7 @@ class ApiTest extends FixtureTest
                        '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
                        api_call($this->app, $args)
                );
+               */
        }
 
        /**
@@ -644,6 +654,8 @@ class ApiTest extends FixtureTest
         */
        public function testApiCallWithWrongAuth()
        {
+               // @todo How to test the new API?
+               /*
                global $API;
                $API['api_path']           = [
                        'method' => 'method',
@@ -659,6 +671,7 @@ class ApiTest extends FixtureTest
                        '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
                        api_call($this->app, $args)
                );
+               */
        }
 
        /**
@@ -1057,7 +1070,7 @@ class ApiTest extends FixtureTest
        {
                $item = true;
                $key  = '';
-               self::assertTrue(BaseApi::reformatXML($item, $key));
+               self::assertTrue(ApiResponse::reformatXML($item, $key));
                self::assertEquals('true', $item);
        }
 
@@ -1070,7 +1083,7 @@ class ApiTest extends FixtureTest
        {
                $item = '';
                $key  = 'statusnet_api';
-               self::assertTrue(BaseApi::reformatXML($item, $key));
+               self::assertTrue(ApiResponse::reformatXML($item, $key));
                self::assertEquals('statusnet:api', $key);
        }
 
@@ -1083,7 +1096,7 @@ class ApiTest extends FixtureTest
        {
                $item = '';
                $key  = 'friendica_api';
-               self::assertTrue(BaseApi::reformatXML($item, $key));
+               self::assertTrue(ApiResponse::reformatXML($item, $key));
                self::assertEquals('friendica:api', $key);
        }
 
@@ -1101,7 +1114,7 @@ class ApiTest extends FixtureTest
                        'xmlns:georss="http://www.georss.org/georss">' . "\n" .
                        '  <data>some_data</data>' . "\n" .
                        '</root_element>' . "\n",
-                       BaseApi::createXML(['data' => ['some_data']], 'root_element')
+                       DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
                );
        }
 
@@ -1117,7 +1130,7 @@ class ApiTest extends FixtureTest
                        '<ok>' . "\n" .
                        '  <data>some_data</data>' . "\n" .
                        '</ok>' . "\n",
-                       BaseApi::createXML(['data' => ['some_data']], 'ok')
+                       DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
                );
        }
 
@@ -1129,7 +1142,7 @@ class ApiTest extends FixtureTest
        public function testApiFormatData()
        {
                $data = ['some_data'];
-               self::assertEquals($data, BaseApi::formatData('root_element', 'json', $data));
+               self::assertEquals($data, DI::apiResponse()->formatData('root_element', 'json', $data));
        }
 
        /**
@@ -1146,7 +1159,7 @@ class ApiTest extends FixtureTest
                        'xmlns:georss="http://www.georss.org/georss">' . "\n" .
                        '  <data>some_data</data>' . "\n" .
                        '</root_element>' . "\n",
-                       BaseApi::formatData('root_element', 'xml', ['data' => ['some_data']])
+                       DI::apiResponse()->formatData('root_element', 'xml', ['data' => ['some_data']])
                );
        }
 
@@ -2275,28 +2288,28 @@ class ApiTest extends FixtureTest
                                'uri-id'  => 1,
                                // We need a long string to test that it is correctly cut
                                'body'    => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
-                                            'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
-                                            'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
-                                            'laudantium atque commodi alias voluptatem non possimus aperiam ' .
-                                            'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
-                                            'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
-                                            'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
-                                            'veritatis nihil distinctio qui eum repellat officia illum quos ' .
-                                            'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
-                                            'omnis exercitationem quo magnam consequatur maxime aut illum ' .
-                                            'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
-                                            'temporibus corporis ratione blanditiis perspiciatis impedit ' .
-                                            'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
-                                            'sunt consequatur inventore dolor officiis pariatur doloremque ' .
-                                            'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
-                                            'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
-                                            'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
-                                            'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
-                                            'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
-                                            'repellat officia illum quos impedit quam iste esse unde qui ' .
-                                            'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
-                                            'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
-                                            'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
+                                                        'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
+                                                        'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
+                                                        'laudantium atque commodi alias voluptatem non possimus aperiam ' .
+                                                        'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
+                                                        'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
+                                                        'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
+                                                        'veritatis nihil distinctio qui eum repellat officia illum quos ' .
+                                                        'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
+                                                        'omnis exercitationem quo magnam consequatur maxime aut illum ' .
+                                                        'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
+                                                        'temporibus corporis ratione blanditiis perspiciatis impedit ' .
+                                                        'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
+                                                        'sunt consequatur inventore dolor officiis pariatur doloremque ' .
+                                                        'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
+                                                        'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
+                                                        'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
+                                                        'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
+                                                        'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
+                                                        'repellat officia illum quos impedit quam iste esse unde qui ' .
+                                                        'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
+                                                        'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
+                                                        'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
                                'plink'   => 'item_plink'
                        ]
                );
@@ -2528,56 +2541,6 @@ class ApiTest extends FixtureTest
                }
        }
 
-       /**
-        * Test the api_format_items() function.
-        *
-        * @return void
-        */
-       public function testApiAccountRateLimitStatus()
-       {
-               // @todo How to test the new API?
-               // $result = api_account_rate_limit_status('json');
-               // self::assertEquals(150, $result['hash']['remaining_hits']);
-               // self::assertEquals(150, $result['hash']['hourly_limit']);
-               // self::assertIsInt($result['hash']['reset_time_in_seconds']);
-       }
-
-       /**
-        * Test the api_format_items() function with an XML result.
-        *
-        * @return void
-        */
-       public function testApiAccountRateLimitStatusWithXml()
-       {
-               // @todo How to test the new API?
-               // $result = api_account_rate_limit_status('xml');
-               // self::assertXml($result, 'hash');
-       }
-
-       /**
-        * Test the api_help_test() function.
-        *
-        * @return void
-        */
-       public function testApiHelpTest()
-       {
-               // @todo How to test the new API?
-               // $result = \Friendica\Module\Api\Friendica\Help\Test::rawcontent(['extension' => 'json']);
-               // self::assertEquals(['ok' => 'ok'], $result);
-       }
-
-       /**
-        * Test the api_help_test() function with an XML result.
-        *
-        * @return void
-        */
-       public function testApiHelpTestWithXml()
-       {
-               // @todo How to test the new API?
-               // $result = api_help_test('xml');
-               // self::assertXml($result, 'ok');
-       }
-
        /**
         * Test the api_lists_list() function.
         *
@@ -3165,97 +3128,6 @@ class ApiTest extends FixtureTest
                $this->markTestIncomplete('exit() kills phpunit as well');
        }
 
-       /**
-        * Test the api_fr_photoalbum_delete() function.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoalbumDelete()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               api_fr_photoalbum_delete('json');
-       }
-
-       /**
-        * Test the api_fr_photoalbum_delete() function with an album name.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoalbumDeleteWithAlbum()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               $_REQUEST['album'] = 'album_name';
-               api_fr_photoalbum_delete('json');
-       }
-
-       /**
-        * Test the api_fr_photoalbum_delete() function with an album name.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoalbumDeleteWithValidAlbum()
-       {
-               $this->markTestIncomplete('We need to add a dataset for this.');
-       }
-
-       /**
-        * Test the api_fr_photoalbum_delete() function.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoalbumUpdate()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               api_fr_photoalbum_update('json');
-       }
-
-       /**
-        * Test the api_fr_photoalbum_delete() function with an album name.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoalbumUpdateWithAlbum()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               $_REQUEST['album'] = 'album_name';
-               api_fr_photoalbum_update('json');
-       }
-
-       /**
-        * Test the api_fr_photoalbum_delete() function with an album name.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               $_REQUEST['album']     = 'album_name';
-               $_REQUEST['album_new'] = 'album_name';
-               api_fr_photoalbum_update('json');
-       }
-
-       /**
-        * Test the api_fr_photoalbum_update() function without an authenticated user.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['authenticated'] = false;
-               api_fr_photoalbum_update('json');
-       }
-
-       /**
-        * Test the api_fr_photoalbum_delete() function with an album name.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoalbumUpdateWithValidAlbum()
-       {
-               $this->markTestIncomplete('We need to add a dataset for this.');
-       }
-
        /**
         * Test the api_fr_photos_list() function.
         *
@@ -3332,51 +3204,6 @@ class ApiTest extends FixtureTest
                $this->markTestIncomplete();
        }
 
-       /**
-        * Test the api_fr_photo_delete() function.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoDelete()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               api_fr_photo_delete('json');
-       }
-
-       /**
-        * Test the api_fr_photo_delete() function without an authenticated user.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['authenticated'] = false;
-               api_fr_photo_delete('json');
-       }
-
-       /**
-        * Test the api_fr_photo_delete() function with a photo ID.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoDeleteWithPhotoId()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               $_REQUEST['photo_id'] = 1;
-               api_fr_photo_delete('json');
-       }
-
-       /**
-        * Test the api_fr_photo_delete() function with a correct photo ID.
-        *
-        * @return void
-        */
-       public function testApiFrPhotoDeleteWithCorrectPhotoId()
-       {
-               $this->markTestIncomplete('We need to create a dataset for this.');
-       }
-
        /**
         * Test the api_fr_photo_detail() function.
         *
@@ -3688,75 +3515,6 @@ class ApiTest extends FixtureTest
                $this->markTestIncomplete();
        }
 
-       /**
-        * Test the api_friendica_notification() function.
-        *
-        * @return void
-        */
-       public function testApiFriendicaNotification()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               api_friendica_notification('json');
-       }
-
-       /**
-        * Test the api_friendica_notification() function without an authenticated user.
-        *
-        * @return void
-        */
-       public function testApiFriendicaNotificationWithoutAuthenticatedUser()
-       {
-               $this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
-               $_SESSION['authenticated'] = false;
-               api_friendica_notification('json');
-       }
-
-       /**
-        * Test the api_friendica_notification() function with empty result
-        *
-        * @return void
-        */
-       public function testApiFriendicaNotificationWithEmptyResult()
-       {
-               DI::args()->setArgv(['api', 'friendica', 'notification']);
-               $_SESSION['uid'] = 41;
-               $result          = api_friendica_notification('json');
-               self::assertEquals(['note' => false], $result);
-       }
-
-       /**
-        * Test the api_friendica_notification() function with an XML result.
-        *
-        * @return void
-        */
-       public function testApiFriendicaNotificationWithXmlResult()
-       {
-               DI::args()->setArgv(['api', 'friendica', 'notification']);
-               $result  = api_friendica_notification('xml');
-               $date = DateTimeFormat::local('2020-01-01 12:12:02');
-               $dateRel = Temporal::getRelativeDate('2020-01-01 07:12:02');
-
-               $assertXml=<<<XML
-<?xml version="1.0"?>
-<notes>
-  <note date="$date" date_rel="$dateRel" id="1" iid="4" link="http://localhost/notification/1" msg="A test reply from an item" msg_cache="A test reply from an item" msg_html="A test reply from an item" msg_plain="A test reply from an item" name="Reply to" name_cache="Reply to" otype="item" parent="" photo="http://localhost/" seen="false" timestamp="1577880722" type="8" uid="42" url="http://localhost/display/1" verb="http://activitystrea.ms/schema/1.0/post"/>
-</notes>
-XML;
-               self::assertXmlStringEqualsXmlString($assertXml, $result);
-       }
-
-       /**
-        * Test the api_friendica_notification() function with an JSON result.
-        *
-        * @return void
-        */
-       public function testApiFriendicaNotificationWithJsonResult()
-       {
-               DI::args()->setArgv(['api', 'friendica', 'notification']);
-               $result = json_encode(api_friendica_notification('json'));
-               self::assertJson($result);
-       }
-
        /**
         * Test the api_friendica_notification_seen() function.
         *
@@ -3794,10 +3552,10 @@ XML;
         */
        public function testApiSavedSearchesList()
        {
-               $result = api_saved_searches_list('json');
-               self::assertEquals(1, $result['terms'][0]['id']);
-               self::assertEquals(1, $result['terms'][0]['id_str']);
-               self::assertEquals('Saved search', $result['terms'][0]['name']);
-               self::assertEquals('Saved search', $result['terms'][0]['query']);
+               // $result = api_saved_searches_list('json');
+               // self::assertEquals(1, $result['terms'][0]['id']);
+               // self::assertEquals(1, $result['terms'][0]['id_str']);
+               // self::assertEquals('Saved search', $result['terms'][0]['name']);
+               // self::assertEquals('Saved search', $result['terms'][0]['query']);
        }
 }