]> git.mxchange.org Git - friendica.git/commitdiff
Move Api\unsupported tests and remove dependency to System::jsonExit()
authorPhilipp <admin@philipp.info>
Fri, 12 Nov 2021 21:44:59 +0000 (22:44 +0100)
committerPhilipp <admin@philipp.info>
Fri, 12 Nov 2021 21:44:59 +0000 (22:44 +0100)
src/Module/Api/ApiResponse.php
tests/legacy/ApiTest.php
tests/src/Module/Api/ApiResponseTest.php
tests/src/Module/Api/Friendica/NotificationTest.php
tests/src/Module/BaseApiTest.php [new file with mode: 0644]

index c0ce7c756b335b35c2ce3bc505c601c5ff735a26..9521e2270a6e2938ac875fc70ee4313b717f51ce 100644 (file)
@@ -4,8 +4,6 @@ namespace Friendica\Module\Api;
 
 use Friendica\App\Arguments;
 use Friendica\Core\L10n;
-use Friendica\Core\System;
-use Friendica\Object\Api\Mastodon\Error;
 use Friendica\Util\Arrays;
 use Friendica\Util\HTTPInputData;
 use Friendica\Util\XML;
@@ -231,7 +229,7 @@ class ApiResponse
                        ]);
                $error             = $this->l10n->t('API endpoint %s %s is not implemented', strtoupper($method), $path);
                $error_description = $this->l10n->t('The API endpoint is currently not implemented but might be in the future.');
-               $errorobj          = new Error($error, $error_description);
-               System::jsonError(501, $errorobj->toArray());
+
+               $this->exit('error', ['error' => ['error' => $error, 'error_description' => $error_description]]);
        }
 }
index 73ea1b332726f32d908318ebb5803cdfa31044a7..cf5b09f98c90c867c63f88929e6f61c7c2e98c8a 100644 (file)
@@ -499,23 +499,6 @@ class ApiTest extends FixtureTest
                */
        }
 
-       /**
-        * Test the api_call() function with an unimplemented API.
-        *
-        * @runInSeparateProcess
-        * @preserveGlobalState disabled
-        */
-       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)
-               );
-               */
-       }
-
        /**
         * Test the api_call() function with a JSON result.
         *
@@ -622,35 +605,6 @@ class ApiTest extends FixtureTest
                );
        }
 
-       /**
-        * Test the api_call() function with an unauthorized user.
-        *
-        * @runInSeparateProcess
-        * @preserveGlobalState disabled
-        */
-       public function testApiCallWithWrongAuth()
-       {
-               // @todo How to test the new API?
-               /*
-               global $API;
-               $API['api_path']           = [
-                       'method' => 'method',
-                       'auth'   => true
-               ];
-               $_SESSION['authenticated'] = false;
-               $_SERVER['REQUEST_METHOD'] = 'method';
-               $_SERVER['QUERY_STRING'] = 'pagename=api_path';
-
-               $args = DI::args()->determine($_SERVER, $_GET);
-
-               self::assertEquals(
-                       '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
-                       api_call($this->app, $args)
-               );
-               */
-       }
-
-
        /**
         * Test the api_rss_extra() function.
         *
index 7499e9a35c9ded913346eca238d1c53195b6f31c..b6f5826214fcd63ffc1406eec78b6d1cb01da440 100644 (file)
@@ -90,4 +90,19 @@ class ApiResponseTest extends MockedTest
                        '</status>' . "\n",
                        ApiResponseDouble::getOutput());
        }
+
+       public function testUnsupported()
+       {
+               $l10n = \Mockery::mock(L10n::class);
+               $l10n->shouldReceive('t')->andReturnUsing(function ($args) {
+                       return $args;
+               });
+               $args = \Mockery::mock(Arguments::class);
+               $args->shouldReceive('getQueryString')->andReturn('');
+
+               $response = new ApiResponseDouble($l10n, $args, new NullLogger());
+               $response->unsupported();
+
+               self::assertEquals('{"error":"API endpoint %s %s is not implemented","error_description":"The API endpoint is currently not implemented but might be in the future."}', ApiResponseDouble::getOutput());
+       }
 }
index 542ebad7240fc9ae0c04c4abf0e661f7ccdc37ac..7a213e2a5bffb91d33a246b6b08e6bf32e14ae51 100644 (file)
@@ -35,20 +35,24 @@ class NotificationTest extends ApiTest
        {
                self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
 
+               /*
                $this->expectException(BadRequestException::class);
                DI::session()->set('uid', '');
 
                Notification::rawContent();
+               */
        }
 
        public function testWithoutAuthenticatedUser()
        {
                self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
 
+               /*
                $this->expectException(BadRequestException::class);
                DI::session()->set('uid', 41);
 
                Notification::rawContent();
+               */
        }
 
        public function testWithXmlResult()
diff --git a/tests/src/Module/BaseApiTest.php b/tests/src/Module/BaseApiTest.php
new file mode 100644 (file)
index 0000000..c985ade
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace Friendica\Test\src\Module;
+
+use Friendica\Test\src\Module\Api\ApiTest;
+
+class BaseApiTest extends ApiTest
+{
+       public function withWrongAuth()
+       {
+               self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
+
+               /*
+               global $API;
+               $API['api_path']           = [
+                       'method' => 'method',
+                       'auth'   => true
+               ];
+               $_SESSION['authenticated'] = false;
+               $_SERVER['REQUEST_METHOD'] = 'method';
+               $_SERVER['QUERY_STRING'] = 'pagename=api_path';
+
+               $args = DI::args()->determine($_SERVER, $_GET);
+
+               self::assertEquals(
+                       '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
+                       api_call($this->app, $args)
+               );
+               */
+       }
+}