]> git.mxchange.org Git - friendica.git/commitdiff
Reenable Twitter/Media Post tests
authorPhilipp <admin@philipp.info>
Thu, 9 Dec 2021 21:08:31 +0000 (22:08 +0100)
committerPhilipp <admin@philipp.info>
Thu, 9 Dec 2021 21:08:31 +0000 (22:08 +0100)
src/Module/Api/Twitter/Statuses/Update.php
tests/legacy/ApiTest.php
tests/src/Module/Api/ApiTest.php
tests/src/Module/Api/Twitter/Media/UploadTest.php
tests/src/Module/Api/Twitter/Statuses/UpdateTest.php [new file with mode: 0644]

index 18cb932f80bc74966bd4355bc59dc6c943149be0..381af155f02bde6211111474c72129819fa55d07 100644 (file)
@@ -44,7 +44,7 @@ use HTMLPurifier_Config;
  */
 class Update extends BaseApi
 {
-       public function post(array $request = [], array $post = [])
+       public function post(array $request = [])
        {
                self::checkAllowedScope(self::SCOPE_WRITE);
                $uid = self::getCurrentUserID();
@@ -101,10 +101,10 @@ class Update extends BaseApi
                        $item['coord'] = sprintf("%s %s", $request['lat'], $request['long']);
                }
 
-               $item['allow_cid'] = $owner['allow_cid'];
-               $item['allow_gid'] = $owner['allow_gid'];
-               $item['deny_cid']  = $owner['deny_cid'];
-               $item['deny_gid']  = $owner['deny_gid'];
+               $item['allow_cid'] = $owner['allow_cid'] ?? '';
+               $item['allow_gid'] = $owner['allow_gid'] ?? '';
+               $item['deny_cid']  = $owner['deny_cid'] ?? '';
+               $item['deny_gid']  = $owner['deny_gid'] ?? '';
 
                if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
                        $item['private'] = Item::PRIVATE;
@@ -127,8 +127,8 @@ class Update extends BaseApi
                        $item['object-type'] = Activity\ObjectType::NOTE;
                }
 
-               if (!empty($_REQUEST['media_ids'])) {
-                       $ids = explode(',', $_REQUEST['media_ids']);
+               if (!empty($request['media_ids'])) {
+                       $ids = explode(',', $request['media_ids']);
                } elseif (!empty($_FILES['media'])) {
                        // upload the image if we have one
                        $picture = Photo::upload($uid, $_FILES['media']);
index fea2bd5f1bf4b07bc5baaec89dca5091ebc759a5..c7b2337dd9ca4da15b345913e6bb54f3f22e20fb 100644 (file)
@@ -835,97 +835,6 @@ class ApiTest extends FixtureTest
                // api_statuses_mediap('json');
        }
 
-       /**
-        * Test the api_statuses_update() function.
-        *
-        * @return void
-        */
-       public function testApiStatusesUpdate()
-       {
-               /*
-               $_REQUEST['status']                = 'Status content #friendica';
-               $_REQUEST['in_reply_to_status_id'] = -1;
-               $_REQUEST['lat']                   = 48;
-               $_REQUEST['long']                  = 7;
-               $_FILES                            = [
-                       'media' => [
-                               'id'       => 666,
-                               'size'     => 666,
-                               'width'    => 666,
-                               'height'   => 666,
-                               'tmp_name' => $this->getTempImage(),
-                               'name'     => 'spacer.png',
-                               'type'     => 'image/png'
-                       ]
-               ];
-
-               $result = api_statuses_update('json');
-               self::assertStatus($result['status']);
-               */
-       }
-
-       /**
-        * Test the api_statuses_update() function with an HTML status.
-        *
-        * @return void
-        */
-       public function testApiStatusesUpdateWithHtml()
-       {
-               /*
-               $_REQUEST['htmlstatus'] = '<b>Status content</b>';
-
-               $result = api_statuses_update('json');
-               self::assertStatus($result['status']);
-               */
-       }
-
-       /**
-        * Test the api_statuses_update() function without an authenticated user.
-        *
-        * @return void
-        */
-       public function testApiStatusesUpdateWithoutAuthenticatedUser()
-       {
-               /*
-               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
-               BasicAuth::setCurrentUserID();
-               $_SESSION['authenticated'] = false;
-               api_statuses_update('json');
-               */
-       }
-
-       /**
-        * Test the api_statuses_update() function with a parent status.
-        *
-        * @return void
-        */
-       public function testApiStatusesUpdateWithParent()
-       {
-               $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
-       }
-
-       /**
-        * Test the api_statuses_update() function with a media_ids parameter.
-        *
-        * @return void
-        */
-       public function testApiStatusesUpdateWithMediaIds()
-       {
-               $this->markTestIncomplete();
-       }
-
-       /**
-        * Test the api_statuses_update() function with the throttle limit reached.
-        *
-        * @return void
-        */
-       public function testApiStatusesUpdateWithDayThrottleReached()
-       {
-               $this->markTestIncomplete();
-       }
-
-
-
        /**
         * Test the api_statuses_repeat() function.
         *
index 9820061e0396a3729d53eec9faa223df206fc215..91c7f21a02665997557421c1a4ac7980343e0262 100644 (file)
@@ -126,6 +126,25 @@ abstract class ApiTest extends FixtureTest
                // We could probably do more checks here.
        }
 
+       /**
+        * Get the path to a temporary empty PNG image.
+        *
+        * @return string Path
+        */
+       protected function getTempImage()
+       {
+               $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
+               file_put_contents(
+                       $tmpFile,
+                       base64_decode(
+                       // Empty 1x1 px PNG image
+                               'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
+                       )
+               );
+
+               return $tmpFile;
+       }
+
        /**
         * Transforms a response into a JSON class
         *
index 5b0ce1186bd65f70e3be28d4d981ed37c180af01..4b0ffada12010ffeb4b19026ed692e81de726111 100644 (file)
@@ -80,23 +80,4 @@ class UploadTest extends ApiTest
                self::assertEquals(1, $media->image->h);
                self::assertNotEmpty($media->image->friendica_preview_url);
        }
-
-       /**
-        * Get the path to a temporary empty PNG image.
-        *
-        * @return string Path
-        */
-       private function getTempImage()
-       {
-               $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
-               file_put_contents(
-                       $tmpFile,
-                       base64_decode(
-                       // Empty 1x1 px PNG image
-                               'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
-                       )
-               );
-
-               return $tmpFile;
-       }
 }
diff --git a/tests/src/Module/Api/Twitter/Statuses/UpdateTest.php b/tests/src/Module/Api/Twitter/Statuses/UpdateTest.php
new file mode 100644 (file)
index 0000000..efa6f18
--- /dev/null
@@ -0,0 +1,109 @@
+<?php
+
+namespace Friendica\Test\src\Module\Api\Twitter\Statuses;
+
+use Friendica\App\Router;
+use Friendica\DI;
+use Friendica\Module\Api\Twitter\Statuses\Update;
+use Friendica\Test\src\Module\Api\ApiTest;
+
+class UpdateTest extends ApiTest
+{
+       /**
+        * Test the api_statuses_update() function.
+        *
+        * @return void
+        */
+       public function testApiStatusesUpdate()
+       {
+               $_FILES = [
+                       'media' => [
+                               'id'       => 666,
+                               'size'     => 666,
+                               'width'    => 666,
+                               'height'   => 666,
+                               'tmp_name' => $this->getTempImage(),
+                               'name'     => 'spacer.png',
+                               'type'     => 'image/png'
+                       ]
+               ];
+
+               $show     = new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
+               $response = $show->run([
+                       'status'                => 'Status content #friendica',
+                       'in_reply_to_status_id' => 0,
+                       'lat'                   => 48,
+                       'long'                  => 7,
+               ]);
+
+               $json = $this->toJson($response);
+
+               self::assertStatus($json);
+               self::assertContains('Status content #friendica', $json->text);
+               self::assertContains('Status content #', $json->statusnet_html);
+       }
+
+       /**
+        * Test the api_statuses_update() function with an HTML status.
+        *
+        * @return void
+        */
+       public function testApiStatusesUpdateWithHtml()
+       {
+               $show     = new Update(DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::POST]);
+               $response = $show->run([
+                       'htmlstatus' => '<b>Status content</b>',
+               ]);
+
+               $json = $this->toJson($response);
+
+               self::assertStatus($json);
+       }
+
+       /**
+        * Test the api_statuses_update() function without an authenticated user.
+        *
+        * @return void
+        */
+       public function testApiStatusesUpdateWithoutAuthenticatedUser()
+       {
+               self::markTestIncomplete('Needs BasicAuth as dynamic method for overriding first');
+
+               /*
+               $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
+               BasicAuth::setCurrentUserID();
+               $_SESSION['authenticated'] = false;
+               api_statuses_update('json');
+               */
+       }
+
+       /**
+        * Test the api_statuses_update() function with a parent status.
+        *
+        * @return void
+        */
+       public function testApiStatusesUpdateWithParent()
+       {
+               $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
+       }
+
+       /**
+        * Test the api_statuses_update() function with a media_ids parameter.
+        *
+        * @return void
+        */
+       public function testApiStatusesUpdateWithMediaIds()
+       {
+               $this->markTestIncomplete();
+       }
+
+       /**
+        * Test the api_statuses_update() function with the throttle limit reached.
+        *
+        * @return void
+        */
+       public function testApiStatusesUpdateWithDayThrottleReached()
+       {
+               $this->markTestIncomplete();
+       }
+}