nextcloud/tests/lib/APITest.php

87 lines
1.7 KiB
PHP
Raw Normal View History

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;
use OCP\IRequest;
2016-05-19 10:27:21 +03:00
class APITest extends \Test\TestCase {
2013-11-14 04:40:09 +04:00
// Helps build a response variable
/**
* @param string $message
*/
function buildResponse($shipped, $data, $code, $message=null) {
$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,
'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
/**
* @param \OC\OCS\Result $result
*/
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
$this->assertInstanceOf(\OC\OCS\Result::class, $result);
2013-11-14 18:37:30 +04:00
// Check if it succeeded
/** @var $result \OC\OCS\Result */
2013-11-14 04:40:09 +04:00
$this->assertEquals($success, $result->succeeded());
}
/**
* @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) {
$request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
$request
->expects($this->once())
->method('getScriptName')
->willReturn($scriptName);
$this->assertEquals($expected, $this->invokePrivate(new \OC_API, 'isV2', [$request]));
}
2013-11-14 04:40:09 +04:00
}