]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Util/HTTPInputDataTest.php
Merge branch '2021.06-rc' of https://github.com/friendica/friendica into 2021.06...
[friendica.git] / tests / src / Util / HTTPInputDataTest.php
index 19e87e438a5802e5f335f0699cf50374ad169489..5e8fd228fd0b8fddd6c3ad88d923969f6b96a1f1 100644 (file)
@@ -27,6 +27,7 @@ use Friendica\Util\HTTPInputData;
 
 /**
  * Testing HTTPInputData
+ *
  * @see        HTTPInputData
  */
 class HTTPInputDataTest extends MockedTest
@@ -35,6 +36,7 @@ class HTTPInputDataTest extends MockedTest
         * Returns the data stream for the unit test
         * Each array element of the first hierarchy represents one test run
         * Each array element of the second hierarchy represents the parameters, passed to the test function
+        *
         * @return array[]
         */
        public function dataStream()
@@ -62,6 +64,42 @@ class HTTPInputDataTest extends MockedTest
                                        'files' => []
                                ]
                        ],
+                       'multipart-file' => [
+                               'contenttype' => 'multipart/form-data;boundary=6d4d5a40-651a-4468-a62e-5a6ca2bf350d;charset=utf8',
+                               'input'       => file_get_contents(__DIR__ . '/../../datasets/http/multipart-file.httpinput'),
+                               'expected'    => [
+                                       'variables' => [
+                                               'display_name'      => 'Vorname Nachname',
+                                               'note'              => 'About me',
+                                               'fields_attributes' => [
+                                                       0 => [
+                                                               'name'  => 'variable 1',
+                                                               'value' => 'value 1',
+                                                       ],
+                                                       1 => [
+                                                               'name'  => 'variable 2',
+                                                               'value' => 'value 2',
+                                                       ]
+                                               ]
+                                       ],
+                                       'files' => [
+                                               'avatar' => [
+                                                       'name'     => '8ZUCS34Y5XNH',
+                                                       'type'     => 'image/png',
+                                                       'tmp_name' => '8ZUCS34Y5XNH',
+                                                       'error'    => 0,
+                                                       'size'     => 349330
+                                               ],
+                                               'header' => [
+                                                       'name'     => 'V2B6Z1IICGPM',
+                                                       'type'     => 'image/png',
+                                                       'tmp_name' => 'V2B6Z1IICGPM',
+                                                       'error'    => 0,
+                                                       'size'     => 1323635
+                                               ]
+                                       ]
+                               ]
+                       ],
                        'form-urlencoded' => [
                                'contenttype' => 'application/x-www-form-urlencoded;charset=utf8',
                                'input'       => file_get_contents(__DIR__ . '/../../datasets/http/form-urlencoded.httpinput'),
@@ -78,7 +116,7 @@ class HTTPInputDataTest extends MockedTest
                                'expected'    => [
                                        'variables' => [
                                                'media_ids'    => [],
-                                               'sensitive'    => false, 
+                                               'sensitive'    => false,
                                                'status'       => 'Test Status',
                                                'visibility'   => 'private',
                                                'spoiler_text' => 'Title'
@@ -91,16 +129,17 @@ class HTTPInputDataTest extends MockedTest
 
        /**
         * Tests the HTTPInputData::process() method
-        * @see HTTPInputData::process()
-        * @param string $contenttype The content typer of the transmitted data
+        *
+        * @param string $contentType The content typer of the transmitted data
         * @param string $input       The input, we got from the data stream
         * @param array  $expected    The expected output
+        *
         * @dataProvider dataStream
+        * @see HTTPInputData::process()
         */
-       public function testHttpInput(string $contenttype, string $input, array $expected)
+       public function testHttpInput(string $contentType, string $input, array $expected)
        {
-               $_SERVER['CONTENT_TYPE'] = $contenttype;
-
+               HTTPInputDataDouble::setPhpInputContentType($contentType);
                HTTPInputDataDouble::setPhpInputContent($input);
                $stream = fopen('php://memory', 'r+');
                fwrite($stream, $input);