. * */ namespace Friendica\Test\src\Util; use Friendica\Test\MockedTest; use Friendica\Test\Util\HTTPInputDataDouble; use Friendica\Util\HTTPInputData; /** * Testing HTTPInputData * @see HTTPInputData */ 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() { return [ 'example' => [ 'contenttype' => 'multipart/form-data;boundary=43395968-f65c-437e-b536-5b33e3e3c7e5;charset=utf8', 'input' => file_get_contents(__DIR__ . '/../../datasets/http/example1.httpinput'), 'expected' => [ 'variables' => [ 'display_name' => 'User Name', 'note' => 'About me', 'locked' => false, 'fields_attributes' => [ 0 => [ 'name' => 'variable 1', 'value' => 'value 1', ], 1 => [ 'name' => 'variable 2', 'value' => 'value 2', ] ] ], 'files' => [] ] ] ]; } /** * Tests the HTTPInputData::process() method * @see HTTPInputData::process() * @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 */ public function testHttpInput(string $contenttype, string $input, array $expected) { $_SERVER['CONTENT_TYPE'] = $contenttype; HTTPInputDataDouble::setPhpInputContent($input); $stream = fopen('php://memory', 'r+'); fwrite($stream, $input); rewind($stream); HTTPInputDataDouble::setPhpInputStream($stream); $output = HTTPInputDataDouble::process(); $this->assertEqualsCanonicalizing($expected, $output); } }