2014-10-28 18:34:04 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud - App Framework
|
|
|
|
*
|
|
|
|
* @author Bernhard Posselt
|
|
|
|
* @copyright 2014 Bernhard Posselt <dev@bernhard-posselt.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-18 19:40:34 +03:00
|
|
|
namespace Test\AppFramework\Http;
|
2014-10-28 18:34:04 +03:00
|
|
|
|
|
|
|
use OCP\AppFramework\Http;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2014-10-28 18:34:04 +03:00
|
|
|
|
2014-11-11 01:30:38 +03:00
|
|
|
class DataResponseTest extends \Test\TestCase {
|
2014-10-28 18:34:04 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var DataResponse
|
|
|
|
*/
|
|
|
|
private $response;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-11 01:30:38 +03:00
|
|
|
parent::setUp();
|
2014-10-28 18:34:04 +03:00
|
|
|
$this->response = new DataResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testSetData() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$params = ['hi', 'yo'];
|
2014-10-28 18:34:04 +03:00
|
|
|
$this->response->setData($params);
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals(['hi', 'yo'], $this->response->getData());
|
2014-10-28 18:34:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testConstructorAllowsToSetData() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$data = ['hi'];
|
2014-10-28 18:34:04 +03:00
|
|
|
$code = 300;
|
|
|
|
$response = new DataResponse($data, $code);
|
|
|
|
|
|
|
|
$this->assertEquals($data, $response->getData());
|
|
|
|
$this->assertEquals($code, $response->getStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testConstructorAllowsToSetHeaders() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$data = ['hi'];
|
2014-10-28 18:34:04 +03:00
|
|
|
$code = 300;
|
2020-03-26 11:30:18 +03:00
|
|
|
$headers = ['test' => 'something'];
|
2014-10-28 18:34:04 +03:00
|
|
|
$response = new DataResponse($data, $code, $headers);
|
|
|
|
|
2015-02-09 18:30:01 +03:00
|
|
|
$expectedHeaders = [
|
2017-01-10 12:13:08 +03:00
|
|
|
'Cache-Control' => 'no-cache, no-store, must-revalidate',
|
2019-04-03 19:42:34 +03:00
|
|
|
'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self'",
|
2019-07-27 16:33:55 +03:00
|
|
|
'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
|
2020-06-15 14:50:30 +03:00
|
|
|
'X-Robots-Tag' => 'none',
|
2015-02-09 18:30:01 +03:00
|
|
|
];
|
2014-10-28 18:34:04 +03:00
|
|
|
$expectedHeaders = array_merge($expectedHeaders, $headers);
|
|
|
|
|
|
|
|
$this->assertEquals($data, $response->getData());
|
|
|
|
$this->assertEquals($code, $response->getStatus());
|
|
|
|
$this->assertEquals($expectedHeaders, $response->getHeaders());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testChainability() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$params = ['hi', 'yo'];
|
2014-10-28 18:34:04 +03:00
|
|
|
$this->response->setData($params)
|
|
|
|
->setStatus(Http::STATUS_NOT_FOUND);
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_NOT_FOUND, $this->response->getStatus());
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals(['hi', 'yo'], $this->response->getData());
|
2014-10-28 18:34:04 +03:00
|
|
|
}
|
|
|
|
}
|