1
0

OCSResponseTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2015 Bernhard Posselt <dev@bernhard-posselt.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Test\AppFramework\Http;
  23. use OCP\AppFramework\Http\OCSResponse;
  24. class OCSResponseTest extends \Test\TestCase {
  25. public function testHeadersJSON() {
  26. $response = new OCSResponse('json', 1, 2, 3);
  27. $type = $response->getHeaders()['Content-Type'];
  28. $this->assertEquals('application/json; charset=utf-8', $type);
  29. }
  30. public function testHeadersXML() {
  31. $response = new OCSResponse('xml', 1, 2, 3);
  32. $type = $response->getHeaders()['Content-Type'];
  33. $this->assertEquals('application/xml; charset=utf-8', $type);
  34. }
  35. public function testRender() {
  36. $response = new OCSResponse(
  37. 'xml', 2, 'message', ['test' => 'hi'], 3, 4
  38. );
  39. $out = $response->render();
  40. $expected = "<?xml version=\"1.0\"?>\n" .
  41. "<ocs>\n" .
  42. " <meta>\n" .
  43. " <status>failure</status>\n" .
  44. " <statuscode>2</statuscode>\n" .
  45. " <message>message</message>\n" .
  46. " <totalitems>3</totalitems>\n" .
  47. " <itemsperpage>4</itemsperpage>\n" .
  48. " </meta>\n" .
  49. " <data>\n" .
  50. " <test>hi</test>\n" .
  51. " </data>\n" .
  52. "</ocs>\n";
  53. $this->assertEquals($expected, $out);
  54. }
  55. }