2014-12-22 08:54:50 -05:00
|
|
|
<?php
|
2024-06-02 09:26:54 -04:00
|
|
|
|
2014-12-22 08:54:50 -05:00
|
|
|
/**
|
2024-06-02 09:26:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-12-22 08:54:50 -05:00
|
|
|
*/
|
2016-08-12 04:27:08 -04:00
|
|
|
namespace OCA\Provisioning_API\Tests\Controller;
|
2016-05-11 13:38:49 -04:00
|
|
|
|
2016-08-12 04:27:08 -04:00
|
|
|
use OCA\Provisioning_API\Controller\AppsController;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\Provisioning_API\Tests\TestCase;
|
2015-11-20 05:27:11 -05:00
|
|
|
use OCP\App\IAppManager;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCP\AppFramework\OCS\OCSException;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\IGroupManager;
|
2017-10-24 09:26:53 -04:00
|
|
|
use OCP\IRequest;
|
2015-11-20 05:27:11 -05:00
|
|
|
use OCP\IUserSession;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\Server;
|
2014-12-22 08:54:50 -05:00
|
|
|
|
2015-11-20 05:27:11 -05:00
|
|
|
/**
|
|
|
|
|
* Class AppsTest
|
|
|
|
|
*
|
|
|
|
|
* @group DB
|
|
|
|
|
*
|
|
|
|
|
* @package OCA\Provisioning_API\Tests
|
|
|
|
|
*/
|
2024-10-10 06:40:31 -04:00
|
|
|
class AppsControllerTest extends TestCase {
|
2015-11-20 05:27:11 -05:00
|
|
|
/** @var IAppManager */
|
|
|
|
|
private $appManager;
|
2016-08-12 04:27:08 -04:00
|
|
|
/** @var AppsController */
|
2015-11-20 05:27:11 -05:00
|
|
|
private $api;
|
|
|
|
|
/** @var IUserSession */
|
|
|
|
|
private $userSession;
|
|
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2016-05-11 13:38:49 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->appManager = Server::get(IAppManager::class);
|
|
|
|
|
$this->groupManager = Server::get(IGroupManager::class);
|
|
|
|
|
$this->userSession = Server::get(IUserSession::class);
|
2016-05-11 13:38:49 -04:00
|
|
|
|
2017-10-24 09:26:53 -04:00
|
|
|
$request = $this->getMockBuilder(IRequest::class)
|
2016-08-12 04:27:08 -04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$this->api = new AppsController(
|
|
|
|
|
'provisioning_api',
|
|
|
|
|
$request,
|
2016-10-27 11:41:15 -04:00
|
|
|
$this->appManager
|
2016-08-12 04:27:08 -04:00
|
|
|
);
|
2015-07-25 15:14:43 -04:00
|
|
|
}
|
|
|
|
|
|
2024-07-16 08:39:58 -04:00
|
|
|
protected function tearDown(): void {
|
|
|
|
|
$this->userSession->setUser(null);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testGetAppInfo(): void {
|
2016-08-12 04:27:08 -04:00
|
|
|
$result = $this->api->getAppInfo('provisioning_api');
|
2022-05-12 11:08:54 -04:00
|
|
|
$expected = $this->appManager->getAppInfo('provisioning_api');
|
2016-08-12 04:27:08 -04:00
|
|
|
$this->assertEquals($expected, $result->getData());
|
2014-12-22 08:54:50 -05:00
|
|
|
}
|
|
|
|
|
|
2024-07-16 08:39:58 -04:00
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testGetAppInfoOnBadAppID(): void {
|
2024-10-10 06:40:31 -04:00
|
|
|
$this->expectException(OCSException::class);
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectExceptionCode(998);
|
|
|
|
|
|
2016-08-12 04:27:08 -04:00
|
|
|
$this->api->getAppInfo('not_provisioning_api');
|
2014-12-22 08:54:50 -05:00
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testGetApps(): void {
|
2014-12-22 08:54:50 -05:00
|
|
|
$user = $this->generateUsers();
|
2015-07-25 16:37:14 -04:00
|
|
|
$this->groupManager->get('admin')->addUser($user);
|
|
|
|
|
$this->userSession->setUser($user);
|
2014-12-22 08:54:50 -05:00
|
|
|
|
2016-08-12 04:27:08 -04:00
|
|
|
$result = $this->api->getApps();
|
2014-12-22 08:54:50 -05:00
|
|
|
|
|
|
|
|
$data = $result->getData();
|
2016-10-27 11:41:15 -04:00
|
|
|
$this->assertEquals(count((new \OC_App())->listAllApps()), count($data['apps']));
|
2014-12-22 08:54:50 -05:00
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testGetAppsEnabled(): void {
|
2016-08-12 04:27:08 -04:00
|
|
|
$result = $this->api->getApps('enabled');
|
2014-12-22 08:54:50 -05:00
|
|
|
$data = $result->getData();
|
|
|
|
|
$this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps']));
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testGetAppsDisabled(): void {
|
2016-08-12 04:27:08 -04:00
|
|
|
$result = $this->api->getApps('disabled');
|
2014-12-22 08:54:50 -05:00
|
|
|
$data = $result->getData();
|
2016-10-27 11:41:15 -04:00
|
|
|
$apps = (new \OC_App)->listAllApps();
|
2020-10-05 09:12:57 -04:00
|
|
|
$list = [];
|
2020-04-10 08:19:56 -04:00
|
|
|
foreach ($apps as $app) {
|
2014-12-22 08:54:50 -05:00
|
|
|
$list[] = $app['id'];
|
|
|
|
|
}
|
|
|
|
|
$disabled = array_diff($list, \OC_App::getEnabledApps());
|
|
|
|
|
$this->assertEquals(count($disabled), count($data['apps']));
|
2015-08-11 06:47:57 -04:00
|
|
|
}
|
2014-12-22 08:54:50 -05:00
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testGetAppsInvalidFilter(): void {
|
2024-10-10 06:40:31 -04:00
|
|
|
$this->expectException(OCSException::class);
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
|
2016-08-12 04:27:08 -04:00
|
|
|
$this->api->getApps('foo');
|
2014-12-22 08:54:50 -05:00
|
|
|
}
|
|
|
|
|
}
|