. * */ namespace OC\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; //require_once(__DIR__ . "/../classloader.php"); class JSONResponseTest extends \PHPUnit_Framework_TestCase { /** * @var JSONResponse */ private $json; protected function setUp() { $this->json = new JSONResponse(); } public function testHeader() { $headers = $this->json->getHeaders(); $this->assertEquals('application/json; charset=utf-8', $headers['Content-type']); } public function testSetData() { $params = array('hi', 'yo'); $this->json->setData($params); $this->assertEquals(array('hi', 'yo'), $this->json->getData()); } public function testSetRender() { $params = array('test' => 'hi'); $this->json->setData($params); $expected = '{"test":"hi"}'; $this->assertEquals($expected, $this->json->render()); } public function testRender() { $params = array('test' => 'hi'); $this->json->setData($params); $expected = '{"test":"hi"}'; $this->assertEquals($expected, $this->json->render()); } public function testShouldHaveXContentHeaderByDefault() { $headers = $this->json->getHeaders(); $this->assertEquals('nosniff', $headers['X-Content-Type-Options']); } public function testConstructorAllowsToSetData() { $data = array('hi'); $code = 300; $response = new JSONResponse($data, $code); $expected = '["hi"]'; $this->assertEquals($expected, $response->render()); $this->assertEquals($code, $response->getStatus()); } }