You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.3 KiB

  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @author Morris Jobke
  7. * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
  8. * @copyright 2013 Morris Jobke morris.jobke@gmail.com
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public
  21. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\AppFramework\Http;
  25. use OCP\AppFramework\Http\JSONResponse;
  26. //require_once(__DIR__ . "/../classloader.php");
  27. class JSONResponseTest extends \PHPUnit_Framework_TestCase {
  28. /**
  29. * @var JSONResponse
  30. */
  31. private $json;
  32. protected function setUp() {
  33. $this->json = new JSONResponse();
  34. }
  35. public function testHeader() {
  36. $headers = $this->json->getHeaders();
  37. $this->assertEquals('application/json; charset=utf-8', $headers['Content-type']);
  38. }
  39. public function testSetData() {
  40. $params = array('hi', 'yo');
  41. $this->json->setData($params);
  42. $this->assertEquals(array('hi', 'yo'), $this->json->getData());
  43. }
  44. public function testSetRender() {
  45. $params = array('test' => 'hi');
  46. $this->json->setData($params);
  47. $expected = '{"test":"hi"}';
  48. $this->assertEquals($expected, $this->json->render());
  49. }
  50. public function testRender() {
  51. $params = array('test' => 'hi');
  52. $this->json->setData($params);
  53. $expected = '{"test":"hi"}';
  54. $this->assertEquals($expected, $this->json->render());
  55. }
  56. public function testShouldHaveXContentHeaderByDefault() {
  57. $headers = $this->json->getHeaders();
  58. $this->assertEquals('nosniff', $headers['X-Content-Type-Options']);
  59. }
  60. public function testConstructorAllowsToSetData() {
  61. $data = array('hi');
  62. $code = 300;
  63. $response = new JSONResponse($data, $code);
  64. $expected = '["hi"]';
  65. $this->assertEquals($expected, $response->render());
  66. $this->assertEquals($code, $response->getStatus());
  67. }
  68. }