1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Joas Schilling <[email protected]> |
4
|
|
|
* @author Morris Jobke <[email protected]> |
5
|
|
|
* @author Roeland Jago Douma <[email protected]> |
6
|
|
|
* @author Tom Needham <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
9
|
|
|
* @license AGPL-3.0 |
10
|
|
|
* |
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
13
|
|
|
* as published by the Free Software Foundation. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace OCA\Provisioning_API\Tests; |
26
|
|
|
use OC\OCSClient; |
27
|
|
|
use OCA\Provisioning_API\Apps; |
28
|
|
|
use OCP\API; |
29
|
|
|
use OCP\App\IAppManager; |
30
|
|
|
use OCP\IUserSession; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class AppsTest |
34
|
|
|
* |
35
|
|
|
* @group DB |
36
|
|
|
* |
37
|
|
|
* @package OCA\Provisioning_API\Tests |
38
|
|
|
*/ |
39
|
|
|
class AppsTest extends TestCase { |
40
|
|
|
/** @var IAppManager */ |
41
|
|
|
private $appManager; |
42
|
|
|
/** @var Apps */ |
43
|
|
|
private $api; |
44
|
|
|
/** @var IUserSession */ |
45
|
|
|
private $userSession; |
46
|
|
|
/** @var OCSClient */ |
47
|
|
|
private $ocsClient; |
48
|
|
|
|
49
|
|
|
public function setup() { |
50
|
|
|
parent::setup(); |
51
|
|
|
$this->appManager = \OC::$server->getAppManager(); |
52
|
|
|
$this->groupManager = \OC::$server->getGroupManager(); |
53
|
|
|
$this->userSession = \OC::$server->getUserSession(); |
54
|
|
|
$this->ocsClient = $this->getMockBuilder('\OC\OCSClient') |
55
|
|
|
->disableOriginalConstructor()->getMock(); |
56
|
|
|
$this->api = new Apps($this->appManager, $this->ocsClient); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGetAppInfo() { |
60
|
|
|
$result = $this->api->getAppInfo(['appid' => 'provisioning_api']); |
61
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result); |
62
|
|
|
$this->assertTrue($result->succeeded()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public function testGetAppInfoOnBadAppID() { |
66
|
|
|
$result = $this->api->getAppInfo(['appid' => 'not_provisioning_api']); |
67
|
|
|
$this->assertInstanceOf('OC_OCS_Result', $result); |
68
|
|
|
$this->assertFalse($result->succeeded()); |
69
|
|
|
$this->assertEquals(API::RESPOND_NOT_FOUND, $result->getStatusCode()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testGetApps() { |
73
|
|
|
$this->ocsClient |
|
|
|
|
74
|
|
|
->expects($this->any()) |
75
|
|
|
->method($this->anything()) |
76
|
|
|
->will($this->returnValue(null)); |
77
|
|
|
$user = $this->generateUsers(); |
78
|
|
|
$this->groupManager->get('admin')->addUser($user); |
|
|
|
|
79
|
|
|
$this->userSession->setUser($user); |
|
|
|
|
80
|
|
|
|
81
|
|
|
$result = $this->api->getApps([]); |
82
|
|
|
|
83
|
|
|
$this->assertTrue($result->succeeded()); |
84
|
|
|
$data = $result->getData(); |
85
|
|
|
$this->assertEquals(count(\OC_App::listAllApps(false, true, $this->ocsClient)), count($data['apps'])); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testGetAppsEnabled() { |
89
|
|
|
$_GET['filter'] = 'enabled'; |
90
|
|
|
$result = $this->api->getApps(['filter' => 'enabled']); |
91
|
|
|
$this->assertTrue($result->succeeded()); |
92
|
|
|
$data = $result->getData(); |
93
|
|
|
$this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps'])); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testGetAppsDisabled() { |
97
|
|
|
$this->ocsClient |
|
|
|
|
98
|
|
|
->expects($this->any()) |
99
|
|
|
->method($this->anything()) |
100
|
|
|
->will($this->returnValue(null)); |
101
|
|
|
$_GET['filter'] = 'disabled'; |
102
|
|
|
$result = $this->api->getApps(['filter' => 'disabled']); |
103
|
|
|
$this->assertTrue($result->succeeded()); |
104
|
|
|
$data = $result->getData(); |
105
|
|
|
$apps = \OC_App::listAllApps(false, true, $this->ocsClient); |
106
|
|
|
$list = array(); |
107
|
|
|
foreach($apps as $app) { |
108
|
|
|
$list[] = $app['id']; |
109
|
|
|
} |
110
|
|
|
$disabled = array_diff($list, \OC_App::getEnabledApps()); |
111
|
|
|
$this->assertEquals(count($disabled), count($data['apps'])); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testGetAppsInvalidFilter() { |
115
|
|
|
$_GET['filter'] = 'foo'; |
116
|
|
|
$result = $this->api->getApps([]); |
117
|
|
|
$this->assertFalse($result->succeeded()); |
118
|
|
|
$this->assertEquals(101, $result->getStatusCode()); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.