1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?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.
*/
namespace Test;
use OCP\IRequest;
class APITest extends \Test\TestCase {
// Helps build a response variable
/**
* @param string $message
*/
public function buildResponse($shipped, $data, $code, $message = null) {
$resp = new \OC\OCS\Result($data, $code, $message);
$resp->addHeader('KEY', 'VALUE');
return [
'shipped' => $shipped,
'response' => $resp,
'app' => $this->getUniqueID('testapp_'),
];
}
// Validate details of the result
/**
* @param \OC\OCS\Result $result
*/
public function checkResult($result, $success) {
// Check response is of correct type
$this->assertInstanceOf(\OC\OCS\Result::class, $result);
// Check if it succeeded
/** @var $result \OC\OCS\Result */
$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]));
}
}
|