2013-11-14 04:40:09 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Tom Needham <tom@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2016-05-19 10:27:21 +03:00
|
|
|
namespace Test;
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\IRequest;
|
|
|
|
|
2016-05-19 10:27:21 +03:00
|
|
|
class APITest extends \Test\TestCase {
|
2014-01-14 20:11:04 +04:00
|
|
|
|
2013-11-14 04:40:09 +04:00
|
|
|
// Helps build a response variable
|
2014-02-19 12:31:54 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $message
|
|
|
|
*/
|
2014-01-14 20:11:04 +04:00
|
|
|
function buildResponse($shipped, $data, $code, $message=null) {
|
2017-09-21 18:56:00 +03:00
|
|
|
$resp = new \OC\OCS\Result($data, $code, $message);
|
2015-08-10 22:33:50 +03:00
|
|
|
$resp->addHeader('KEY', 'VALUE');
|
|
|
|
return [
|
2013-11-14 04:40:09 +04:00
|
|
|
'shipped' => $shipped,
|
2015-08-10 22:33:50 +03:00
|
|
|
'response' => $resp,
|
2014-12-02 15:51:36 +03:00
|
|
|
'app' => $this->getUniqueID('testapp_'),
|
2015-08-10 22:33:50 +03:00
|
|
|
];
|
2013-11-14 04:40:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate details of the result
|
2014-02-19 12:31:54 +04:00
|
|
|
|
|
|
|
/**
|
2017-09-21 18:56:00 +03:00
|
|
|
* @param \OC\OCS\Result $result
|
2014-02-19 12:31:54 +04:00
|
|
|
*/
|
2013-11-14 18:37:30 +04:00
|
|
|
function checkResult($result, $success) {
|
2013-11-14 04:40:09 +04:00
|
|
|
// Check response is of correct type
|
2017-09-21 18:56:00 +03:00
|
|
|
$this->assertInstanceOf(\OC\OCS\Result::class, $result);
|
2013-11-14 18:37:30 +04:00
|
|
|
// Check if it succeeded
|
2017-09-21 18:56:00 +03:00
|
|
|
/** @var $result \OC\OCS\Result */
|
2013-11-14 04:40:09 +04:00
|
|
|
$this->assertEquals($success, $result->succeeded());
|
|
|
|
}
|
|
|
|
|
2015-10-13 00:39:16 +03:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function versionDataScriptNameProvider() {
|
|
|
|
return [
|
|
|
|
// Valid script name
|
|
|
|
[
|
|
|
|
'/master/ocs/v2.php',
|
|
|
|
true,
|
|
|
|
],
|
|
|
|
|
|
|
|
// Invalid script names
|
|
|
|
[
|
|
|
|
'/master/ocs/v2.php/someInvalidPathName',
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'/master/ocs/v1.php',
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider versionDataScriptNameProvider
|
|
|
|
* @param string $scriptName
|
|
|
|
* @param bool $expected
|
|
|
|
*/
|
|
|
|
public function testIsV2($scriptName, $expected) {
|
2017-10-24 16:26:53 +03:00
|
|
|
$request = $this->getMockBuilder(IRequest::class)
|
2015-10-13 00:39:16 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getScriptName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($scriptName);
|
2015-10-13 00:39:16 +03:00
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->invokePrivate(new \OC_API, 'isV2', [$request]));
|
|
|
|
}
|
2013-11-14 04:40:09 +04:00
|
|
|
}
|