Refactor json request test to add additional tests

This commit is contained in:
Zach Borboa
2015-01-17 01:45:52 -08:00
parent f6b626d83d
commit ec8b7825aa
+30 -21
View File
@@ -644,31 +644,40 @@ class CurlTest extends PHPUnit_Framework_TestCase
public function testJSONRequest()
{
$data = array('key' => 'value');
$expected_response = '{"key":"value"}';
foreach (
array(
array(
array(
'key' => 'value',
),
'{"key":"value"}',
),
) as $test) {
list($data, $expected_response) = $test;
$test = new Test();
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
$test = new Test();
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
foreach (array(
'Content-Type',
'content-type',
'CONTENT-TYPE') as $key) {
foreach (array(
'APPLICATION/JSON',
'APPLICATION/JSON; CHARSET=UTF-8',
'APPLICATION/JSON;CHARSET=UTF-8',
'application/json',
'application/json; charset=utf-8',
'application/json;charset=UTF-8',
) as $value) {
$test = new Test();
$test->curl->setHeader($key, $value);
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
'Content-Type',
'content-type',
'CONTENT-TYPE') as $key) {
foreach (array(
'APPLICATION/JSON',
'APPLICATION/JSON; CHARSET=UTF-8',
'APPLICATION/JSON;CHARSET=UTF-8',
'application/json',
'application/json; charset=utf-8',
'application/json;charset=UTF-8',
) as $value) {
$test = new Test();
$test->curl->setHeader($key, $value);
$this->assertEquals($expected_response, $test->server('post_json', 'POST', json_encode($data)));
$test = new Test();
$test->curl->setHeader($key, $value);
$this->assertEquals($expected_response, $test->server('post_json', 'POST', $data));
$test = new Test();
$test->curl->setHeader($key, $value);
$this->assertEquals($expected_response, $test->server('post_json', 'POST', $data));
}
}
}
}