mirror of
https://github.com/friendica/friendica
synced 2024-11-18 04:23:41 +00:00
Merge branch 'http-input-data' of github.com:annando/friendica into http-input-data
This commit is contained in:
commit
436d5b4759
3 changed files with 42 additions and 6 deletions
|
@ -29,7 +29,7 @@ class HTTPInputData
|
|||
{
|
||||
public static function process()
|
||||
{
|
||||
$content_parts = explode(';', $_SERVER['CONTENT_TYPE'] ?? 'application/x-www-form-urlencoded');
|
||||
$content_parts = explode(';', static::getContentType());
|
||||
|
||||
$boundary = '';
|
||||
$encoding = '';
|
||||
|
@ -263,6 +263,7 @@ class HTTPInputData
|
|||
/**
|
||||
* Returns the current PHP input stream
|
||||
* Mainly used for test doubling
|
||||
*
|
||||
* @return false|resource
|
||||
*/
|
||||
protected static function getPhpInputStream()
|
||||
|
@ -273,10 +274,22 @@ class HTTPInputData
|
|||
/**
|
||||
* Returns the content of the current PHP input
|
||||
* Mainly used for test doubling
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
protected static function getPhpInputContent()
|
||||
{
|
||||
return file_get_contents('php://input');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content type string of the current call
|
||||
* Mainly used for test doubling
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
protected static function getContentType()
|
||||
{
|
||||
return $_SERVER['CONTENT_TYPE'] ?? 'application/x-www-form-urlencoded';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,9 +33,12 @@ class HTTPInputDataDouble extends HTTPInputData
|
|||
protected static $injectedStream = false;
|
||||
/** @var false|string */
|
||||
protected static $injectedContent = false;
|
||||
/** @var false|string */
|
||||
protected static $injectedContentType = false;
|
||||
|
||||
/**
|
||||
* injects the PHP input stream for a test
|
||||
*
|
||||
* @param false|resource $stream
|
||||
*/
|
||||
public static function setPhpInputStream($stream)
|
||||
|
@ -45,6 +48,7 @@ class HTTPInputDataDouble extends HTTPInputData
|
|||
|
||||
/**
|
||||
* injects the PHP input content for a test
|
||||
*
|
||||
* @param false|string $content
|
||||
*/
|
||||
public static function setPhpInputContent($content)
|
||||
|
@ -52,6 +56,16 @@ class HTTPInputDataDouble extends HTTPInputData
|
|||
self::$injectedContent = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* injects the PHP input content type for a test
|
||||
*
|
||||
* @param false|string $contentType
|
||||
*/
|
||||
public static function setPhpInputContentType($contentType)
|
||||
{
|
||||
self::$injectedContentType = $contentType;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
protected static function getPhpInputStream()
|
||||
{
|
||||
|
@ -63,4 +77,10 @@ class HTTPInputDataDouble extends HTTPInputData
|
|||
{
|
||||
return static::$injectedContent;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
protected static function getContentType()
|
||||
{
|
||||
return static::$injectedContentType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
@ -91,16 +93,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);
|
||||
|
|
Loading…
Reference in a new issue