Reenable Twitter/Create&Destory tests
authorPhilipp <admin@philipp.info>
Thu, 9 Dec 2021 21:30:35 +0000 (22:30 +0100)
committerPhilipp <admin@philipp.info>
Thu, 9 Dec 2021 21:45:52 +0000 (22:45 +0100)
tests/datasets/api.fixture.php
tests/legacy/ApiTest.php
tests/src/Module/Api/Twitter/Favorites/CreateTest.php [new file with mode: 0644]
tests/src/Module/Api/Twitter/Favorites/DestroyTest.php [new file with mode: 0644]

index a8705696f2c131847ec0a29bb3928435d0189051..fa201f7b0ea3f5e2dcfdd7e8b4194e2aab54e9cc 100644 (file)
@@ -69,7 +69,8 @@ return [
                        'username' => 'Test user',
                        'nickname' => 'selfcontact',
                        'verified' => 1,
-                       'password' => '$2y$10$DLRNTRmJgKe1cSrFJ5Jb0edCqvXlA9sh/RHdSnfxjbR.04yZRm4Qm',
+                       'prvkey'   => "-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDVqxF9kIgtgRL0+q+jTi578FA1r1+crEmlYc0pdxcbmmrhjuRc\nrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/KHVks7eQ4yr4MxTRlsxo5qf2o\nnbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjsQPX240vGNXIkfLiAWwIDAQAB\nAoGBAIwuiPIdggqAtWQ+mD8HCx5LQwSFw6/xpPu5F7ZNqL52aAsGCbL3o2QoIG4c\na1qf9Ot16BNgNBqxQF3hzRTkBMrKYlmNTUkwJXun/zjQJq2JvOlcrSuXlIucUjs4\nXekVN25aYPHrX9m2FEIUwZTb4UYXbR80KbIDI53BkQ6EwSbpAkEA7aO49CR2Hf1Y\n1d2GaUI/Z0wvbj//+t0Kg0bPt16ca8KVjEQQA5ylsDaiw510jDz9NBQxSOk6If23\nUeRixc1RDQJBAOYtN4YnPM1Zfp6IxXlqMCc+xUWRTPEPFt+WpG+v79koNamAeA6o\nZzTl92hl58IqSdbgojeE2zXWQRvlimFMLQcCQQCV6jND0byyLqFcSeQBg0l8YROK\n+dUC7W80YfeoNod3c8nkMwvnO2tLPyxvO2XLEq6prBNra7bAus5rWyj0oBIBAkEA\n1EvUMFm0TLpEfLgtWuTD8Q6GKLnxO0ztjd+FXrXpBGN/ywyArxRHzJRmctW6wmz6\nmcOqGobhIHCysKYv0bnOtQJAc2M5RwlASHH4jGJzXgt3nboyiJfufM0RV9iry3ho\nCXQRWAONKoLqnsfC6qNP8OzY8FMJcwmPWj7Q/6z6yLBFTA==\n-----END RSA PRIVATE KEY-----",
+                       'pubkey'   => "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVqxF9kIgtgRL0+q+jTi578FA1\nr1+crEmlYc0pdxcbmmrhjuRcrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/K\nHVks7eQ4yr4MxTRlsxo5qf2onbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjs\nQPX240vGNXIkfLiAWwIDAQAB\n-----END PUBLIC KEY-----",                   'password' => '$2y$10$DLRNTRmJgKe1cSrFJ5Jb0edCqvXlA9sh/RHdSnfxjbR.04yZRm4Qm',
                        'theme'    => 'frio',
                ],
        ],
@@ -137,6 +138,8 @@ return [
                        'nurl'     => 'http://localhost/profile/selfcontact',
                        'url'      => 'http://localhost/profile/selfcontact',
                        'about'    => 'User used in tests',
+                       'prvkey'   => "-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDVqxF9kIgtgRL0+q+jTi578FA1r1+crEmlYc0pdxcbmmrhjuRc\nrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/KHVks7eQ4yr4MxTRlsxo5qf2o\nnbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjsQPX240vGNXIkfLiAWwIDAQAB\nAoGBAIwuiPIdggqAtWQ+mD8HCx5LQwSFw6/xpPu5F7ZNqL52aAsGCbL3o2QoIG4c\na1qf9Ot16BNgNBqxQF3hzRTkBMrKYlmNTUkwJXun/zjQJq2JvOlcrSuXlIucUjs4\nXekVN25aYPHrX9m2FEIUwZTb4UYXbR80KbIDI53BkQ6EwSbpAkEA7aO49CR2Hf1Y\n1d2GaUI/Z0wvbj//+t0Kg0bPt16ca8KVjEQQA5ylsDaiw510jDz9NBQxSOk6If23\nUeRixc1RDQJBAOYtN4YnPM1Zfp6IxXlqMCc+xUWRTPEPFt+WpG+v79koNamAeA6o\nZzTl92hl58IqSdbgojeE2zXWQRvlimFMLQcCQQCV6jND0byyLqFcSeQBg0l8YROK\n+dUC7W80YfeoNod3c8nkMwvnO2tLPyxvO2XLEq6prBNra7bAus5rWyj0oBIBAkEA\n1EvUMFm0TLpEfLgtWuTD8Q6GKLnxO0ztjd+FXrXpBGN/ywyArxRHzJRmctW6wmz6\nmcOqGobhIHCysKYv0bnOtQJAc2M5RwlASHH4jGJzXgt3nboyiJfufM0RV9iry3ho\nCXQRWAONKoLqnsfC6qNP8OzY8FMJcwmPWj7Q/6z6yLBFTA==\n-----END RSA PRIVATE KEY-----",
+                       'pubkey'   => "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVqxF9kIgtgRL0+q+jTi578FA1\nr1+crEmlYc0pdxcbmmrhjuRcrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/K\nHVks7eQ4yr4MxTRlsxo5qf2onbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjs\nQPX240vGNXIkfLiAWwIDAQAB\n-----END PUBLIC KEY-----",
                        'pending'  => 0,
                        'blocked'  => 0,
                        'rel'      => Contact::FOLLOWER,
@@ -259,7 +262,7 @@ return [
                        "header"           => null,
                        "addr"             => "selfcontact@localhost",
                        "alias"            => null,
-                       "pubkey"           => "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzLquDFnFxNYZZFQNbA9f\nkgtUJpC+MPrhxhEsjxme1ivvE4itdPnCueBHifknUkwfmqormyeqr4TdoVbNuKRg\nj2QRBdtaGbUJLQVdbiTKFOmJIYMtV05WIIHEhUW84fwIXmF+6u3kbOw+sIjWY3OW\nwC/2+54HiYS2n8cddfwoZBim6Na8yyQI8pQSKqJ+I4gDfkGuoVex0svNPEv9liLE\nykpQ3PuoeLJV2Wex0Cy6FYPgcfH6xvvUVxh6e8w0w22jC3DJInfDrmbw5H7aUbf+\nMMwV3TVI6/CqTO0cLEOZUjsUwdm6lIV0O0fTsrkjU9G0bc0sLJl7n9i9ICDOKOMf\nCLaK2Pj2sVbpkzXJoufLUDf0oSftdVvN9jR9WYxRdnwsyF8N/xVTw8AsyHhkXawR\n3YDgi6i2uZj5kvG7GPBf7EPZ/MpbGhEZB+/GQuZuyhLdgFDSi/uX8STBmn1jI/zY\nTLZ8JCwMzFKAXAtYaBPklZBbcRyz9O1893MsAXO8d6ODTOkD324gAjRUtuOMscYc\nWV98NZIUSbqQrznmMoJn1fiMNVgx+UXOPkiZuDxnrr1T3vynKnl5LXmadx2YeoAf\nxPeCoDb0eJtCDLcsTZ9qlztaEaohPV+H3HBSpdItea7LgAbccILHPssk9tUgmHVl\na5yV8uFenhKKQ9g93Pt63LsCAwEAAQ==\n-----END PUBLIC KEY-----",
+                       "pubkey"           => "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVqxF9kIgtgRL0+q+jTi578FA1\nr1+crEmlYc0pdxcbmmrhjuRcrK1gX3r0mnP25fkHzG+6CAjgbDBRFM1/RXBCyp/K\nHVks7eQ4yr4MxTRlsxo5qf2onbyNzM7Q+LZhFhe/yIoGN/fuEjlqBE98IfPOrUjs\nQPX240vGNXIkfLiAWwIDAQAB\n-----END PUBLIC KEY-----",
                        "subscribe"        => "/follow?url={uri}",
                        "baseurl"          => null,
                        "gsid"             => null,
index c7b2337dd9ca4da15b345913e6bb54f3f22e20fb..2deca42d6ce72918aeea23e525c53169acc4cef8 100644 (file)
@@ -876,100 +876,6 @@ class ApiTest extends FixtureTest
                // self::assertStatus($result['status']);
        }
 
-       /**
-        * Test the api_favorites_create_destroy() function.
-        *
-        * @return void
-        */
-       public function testApiFavoritesCreateDestroy()
-       {
-               // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               // DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
-               // api_favorites_create_destroy('json');
-       }
-
-       /**
-        * Test the api_favorites_create_destroy() function with an invalid ID.
-        *
-        * @return void
-        */
-       public function testApiFavoritesCreateDestroyWithInvalidId()
-       {
-               // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               // DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
-               // api_favorites_create_destroy('json');
-       }
-
-       /**
-        * Test the api_favorites_create_destroy() function with an invalid action.
-        *
-        * @return void
-        */
-       public function testApiFavoritesCreateDestroyWithInvalidAction()
-       {
-               // $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
-               // DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
-               // $_REQUEST['id'] = 1;
-               // api_favorites_create_destroy('json');
-       }
-
-       /**
-        * Test the api_favorites_create_destroy() function with the create action.
-        *
-        * @return void
-        */
-       public function testApiFavoritesCreateDestroyWithCreateAction()
-       {
-               // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
-               // $_REQUEST['id'] = 3;
-               // $result         = api_favorites_create_destroy('json');
-               // self::assertStatus($result['status']);
-       }
-
-       /**
-        * Test the api_favorites_create_destroy() function with the create action and an RSS result.
-        *
-        * @return void
-        */
-       public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
-       {
-               // DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
-               // $_REQUEST['id'] = 3;
-               // $result         = api_favorites_create_destroy('rss');
-               // self::assertXml($result, 'status');
-       }
-
-       /**
-        * Test the api_favorites_create_destroy() function with the destroy action.
-        *
-        * @return void
-        */
-       public function testApiFavoritesCreateDestroyWithDestroyAction()
-       {
-               // DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
-               // $_REQUEST['id'] = 3;
-               // $result         = api_favorites_create_destroy('json');
-               // self::assertStatus($result['status']);
-       }
-
-       /**
-        * Test the api_favorites_create_destroy() function without an authenticated user.
-        *
-        * @return void
-        */
-       public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
-       {
-               /*
-               $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');
-               */
-       }
-
-
-
        /**
         * Test the api_format_messages() function.
         *
diff --git a/tests/src/Module/Api/Twitter/Favorites/CreateTest.php b/tests/src/Module/Api/Twitter/Favorites/CreateTest.php
new file mode 100644 (file)
index 0000000..d4d9b49
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+
+namespace Friendica\Test\src\Module\Api\Twitter\Favorites;
+
+use Friendica\App\Router;
+use Friendica\Capabilities\ICanCreateResponses;
+use Friendica\DI;
+use Friendica\Module\Api\Twitter\Favorites\Create;
+use Friendica\Network\HTTPException\BadRequestException;
+use Friendica\Test\src\Module\Api\ApiTest;
+
+class CreateTest extends ApiTest
+{
+       /**
+        * Test the api_favorites_create_destroy() function with an invalid ID.
+        *
+        * @return void
+        */
+       public function testApiFavoritesCreateDestroyWithInvalidId()
+       {
+               $this->expectException(BadRequestException::class);
+
+               $create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
+               $create->run();
+       }
+
+       /**
+        * Test the api_favorites_create_destroy() function with the create action.
+        *
+        * @return void
+        */
+       public function testApiFavoritesCreateDestroyWithCreateAction()
+       {
+               $create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
+               $response = $create->run(['id' => 3]);
+
+               $json = $this->toJson($response);
+
+               self::assertStatus($json);
+       }
+
+       /**
+        * Test the api_favorites_create_destroy() function with the create action and an RSS result.
+        *
+        * @return void
+        */
+       public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
+       {
+               $create = new Create(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST], ['extension' => ICanCreateResponses::TYPE_RSS]);
+               $response = $create->run(['id' => 3]);
+
+               self::assertEquals(ICanCreateResponses::TYPE_RSS, $response->getHeaderLine(ICanCreateResponses::X_HEADER));
+
+               self::assertXml((string)$response->getBody(), 'statuses');
+       }
+
+       /**
+        * Test the api_favorites_create_destroy() function without an authenticated user.
+        *
+        * @return void
+        */
+       public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
+       {
+               self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks');
+
+               /*
+               $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');
+               */
+       }
+}
diff --git a/tests/src/Module/Api/Twitter/Favorites/DestroyTest.php b/tests/src/Module/Api/Twitter/Favorites/DestroyTest.php
new file mode 100644 (file)
index 0000000..3d8ce8a
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+namespace Friendica\Test\src\Module\Api\Twitter\Favorites;
+
+use Friendica\App\Router;
+use Friendica\DI;
+use Friendica\Module\Api\Twitter\Favorites\Destroy;
+use Friendica\Network\HTTPException\BadRequestException;
+use Friendica\Test\src\Module\Api\ApiTest;
+
+class DestroyTest extends ApiTest
+{
+       /**
+        * Test the api_favorites_create_destroy() function with an invalid ID.
+        *
+        * @return void
+        */
+       public function testApiFavoritesCreateDestroyWithInvalidId()
+       {
+               $this->expectException(BadRequestException::class);
+
+               $destroy = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
+               $destroy->run();
+       }
+
+       /**
+        * Test the api_favorites_create_destroy() function with the destroy action.
+        *
+        * @return void
+        */
+       public function testApiFavoritesCreateDestroyWithDestroyAction()
+       {
+               $destroy  = new Destroy(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
+               $response = $destroy->run(['id' => 3]);
+
+               $json = $this->toJson($response);
+
+               self::assertStatus($json);
+       }
+
+       /**
+        * Test the api_favorites_create_destroy() function without an authenticated user.
+        *
+        * @return void
+        */
+       public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
+       {
+               self::markTestIncomplete('Needs refactoring of Lists - replace filter_input() with $request parameter checks');
+
+               /*
+               $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');
+               */
+       }
+}