AppsControllerTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Provisioning_API\Tests\Controller;
  8. use OCA\Provisioning_API\Controller\AppsController;
  9. use OCP\App\IAppManager;
  10. use OCP\IRequest;
  11. use OCP\IUserSession;
  12. /**
  13. * Class AppsTest
  14. *
  15. * @group DB
  16. *
  17. * @package OCA\Provisioning_API\Tests
  18. */
  19. class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
  20. /** @var IAppManager */
  21. private $appManager;
  22. /** @var AppsController */
  23. private $api;
  24. /** @var IUserSession */
  25. private $userSession;
  26. protected function setUp(): void {
  27. parent::setUp();
  28. $this->appManager = \OC::$server->getAppManager();
  29. $this->groupManager = \OC::$server->getGroupManager();
  30. $this->userSession = \OC::$server->getUserSession();
  31. $request = $this->getMockBuilder(IRequest::class)
  32. ->disableOriginalConstructor()
  33. ->getMock();
  34. $this->api = new AppsController(
  35. 'provisioning_api',
  36. $request,
  37. $this->appManager
  38. );
  39. }
  40. public function testGetAppInfo() {
  41. $result = $this->api->getAppInfo('provisioning_api');
  42. $expected = $this->appManager->getAppInfo('provisioning_api');
  43. $this->assertEquals($expected, $result->getData());
  44. }
  45. public function testGetAppInfoOnBadAppID() {
  46. $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
  47. $this->expectExceptionCode(998);
  48. $this->api->getAppInfo('not_provisioning_api');
  49. }
  50. public function testGetApps() {
  51. $user = $this->generateUsers();
  52. $this->groupManager->get('admin')->addUser($user);
  53. $this->userSession->setUser($user);
  54. $result = $this->api->getApps();
  55. $data = $result->getData();
  56. $this->assertEquals(count((new \OC_App())->listAllApps()), count($data['apps']));
  57. }
  58. public function testGetAppsEnabled() {
  59. $result = $this->api->getApps('enabled');
  60. $data = $result->getData();
  61. $this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps']));
  62. }
  63. public function testGetAppsDisabled() {
  64. $result = $this->api->getApps('disabled');
  65. $data = $result->getData();
  66. $apps = (new \OC_App)->listAllApps();
  67. $list = [];
  68. foreach ($apps as $app) {
  69. $list[] = $app['id'];
  70. }
  71. $disabled = array_diff($list, \OC_App::getEnabledApps());
  72. $this->assertEquals(count($disabled), count($data['apps']));
  73. }
  74. public function testGetAppsInvalidFilter() {
  75. $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
  76. $this->expectExceptionCode(101);
  77. $this->api->getApps('foo');
  78. }
  79. }