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.

87 lines
2.5 KiB

  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2014 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;
  24. use OCP\AppFramework\Http\DataResponse;
  25. class DataResponseTest extends \Test\TestCase {
  26. /**
  27. * @var DataResponse
  28. */
  29. private $response;
  30. protected function setUp(): void {
  31. parent::setUp();
  32. $this->response = new DataResponse();
  33. }
  34. public function testSetData() {
  35. $params = ['hi', 'yo'];
  36. $this->response->setData($params);
  37. $this->assertEquals(['hi', 'yo'], $this->response->getData());
  38. }
  39. public function testConstructorAllowsToSetData() {
  40. $data = ['hi'];
  41. $code = 300;
  42. $response = new DataResponse($data, $code);
  43. $this->assertEquals($data, $response->getData());
  44. $this->assertEquals($code, $response->getStatus());
  45. }
  46. public function testConstructorAllowsToSetHeaders() {
  47. $data = ['hi'];
  48. $code = 300;
  49. $headers = ['test' => 'something'];
  50. $response = new DataResponse($data, $code, $headers);
  51. $expectedHeaders = [
  52. 'Cache-Control' => 'no-cache, no-store, must-revalidate',
  53. 'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self'",
  54. 'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
  55. ];
  56. $expectedHeaders = array_merge($expectedHeaders, $headers);
  57. $this->assertEquals($data, $response->getData());
  58. $this->assertEquals($code, $response->getStatus());
  59. $this->assertEquals($expectedHeaders, $response->getHeaders());
  60. }
  61. public function testChainability() {
  62. $params = ['hi', 'yo'];
  63. $this->response->setData($params)
  64. ->setStatus(Http::STATUS_NOT_FOUND);
  65. $this->assertEquals(Http::STATUS_NOT_FOUND, $this->response->getStatus());
  66. $this->assertEquals(['hi', 'yo'], $this->response->getData());
  67. }
  68. }