diff options
Diffstat (limited to 'apps/provisioning_api/tests/Controller/AppsControllerTest.php')
-rw-r--r-- | apps/provisioning_api/tests/Controller/AppsControllerTest.php | 88 |
1 files changed, 40 insertions, 48 deletions
diff --git a/apps/provisioning_api/tests/Controller/AppsControllerTest.php b/apps/provisioning_api/tests/Controller/AppsControllerTest.php index 187247b9f66..f95daeae7d3 100644 --- a/apps/provisioning_api/tests/Controller/AppsControllerTest.php +++ b/apps/provisioning_api/tests/Controller/AppsControllerTest.php @@ -1,36 +1,23 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Tom Needham <tom@owncloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\Provisioning_API\Tests\Controller; +use OC\Installer; use OCA\Provisioning_API\Controller\AppsController; +use OCA\Provisioning_API\Tests\TestCase; use OCP\App\IAppManager; +use OCP\AppFramework\OCS\OCSException; +use OCP\IAppConfig; +use OCP\IGroupManager; use OCP\IRequest; use OCP\IUserSession; +use OCP\Server; +use PHPUnit\Framework\MockObject\MockObject; /** * Class AppsTest @@ -39,47 +26,52 @@ use OCP\IUserSession; * * @package OCA\Provisioning_API\Tests */ -class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase { - /** @var IAppManager */ - private $appManager; - /** @var AppsController */ - private $api; - /** @var IUserSession */ - private $userSession; +class AppsControllerTest extends TestCase { + private IAppManager $appManager; + private IAppConfig&MockObject $appConfig; + private Installer&MockObject $installer; + private AppsController $api; + private IUserSession $userSession; protected function setUp(): void { parent::setUp(); - $this->appManager = \OC::$server->getAppManager(); - $this->groupManager = \OC::$server->getGroupManager(); - $this->userSession = \OC::$server->getUserSession(); + $this->appManager = Server::get(IAppManager::class); + $this->groupManager = Server::get(IGroupManager::class); + $this->userSession = Server::get(IUserSession::class); + $this->appConfig = $this->createMock(IAppConfig::class); + $this->installer = $this->createMock(Installer::class); - $request = $this->getMockBuilder(IRequest::class) - ->disableOriginalConstructor() - ->getMock(); + $request = $this->createMock(IRequest::class); $this->api = new AppsController( 'provisioning_api', $request, - $this->appManager + $this->appManager, + $this->installer, + $this->appConfig, ); } - public function testGetAppInfo() { + protected function tearDown(): void { + $this->userSession->setUser(null); + } + + public function testGetAppInfo(): void { $result = $this->api->getAppInfo('provisioning_api'); $expected = $this->appManager->getAppInfo('provisioning_api'); $this->assertEquals($expected, $result->getData()); } - - public function testGetAppInfoOnBadAppID() { - $this->expectException(\OCP\AppFramework\OCS\OCSException::class); + + public function testGetAppInfoOnBadAppID(): void { + $this->expectException(OCSException::class); $this->expectExceptionCode(998); $this->api->getAppInfo('not_provisioning_api'); } - public function testGetApps() { + public function testGetApps(): void { $user = $this->generateUsers(); $this->groupManager->get('admin')->addUser($user); $this->userSession->setUser($user); @@ -90,13 +82,13 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase { $this->assertEquals(count((new \OC_App())->listAllApps()), count($data['apps'])); } - public function testGetAppsEnabled() { + public function testGetAppsEnabled(): void { $result = $this->api->getApps('enabled'); $data = $result->getData(); $this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps'])); } - public function testGetAppsDisabled() { + public function testGetAppsDisabled(): void { $result = $this->api->getApps('disabled'); $data = $result->getData(); $apps = (new \OC_App)->listAllApps(); @@ -108,9 +100,9 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase { $this->assertEquals(count($disabled), count($data['apps'])); } - - public function testGetAppsInvalidFilter() { - $this->expectException(\OCP\AppFramework\OCS\OCSException::class); + + public function testGetAppsInvalidFilter(): void { + $this->expectException(OCSException::class); $this->expectExceptionCode(101); $this->api->getApps('foo'); |