1
0

AppsControllerTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Tom Needham <tom@owncloud.com>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OCA\Provisioning_API\Tests\Controller;
  29. use OCA\Provisioning_API\Controller\AppsController;
  30. use OCP\App\IAppManager;
  31. use OCP\IRequest;
  32. use OCP\IUserSession;
  33. /**
  34. * Class AppsTest
  35. *
  36. * @group DB
  37. *
  38. * @package OCA\Provisioning_API\Tests
  39. */
  40. class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
  41. /** @var IAppManager */
  42. private $appManager;
  43. /** @var AppsController */
  44. private $api;
  45. /** @var IUserSession */
  46. private $userSession;
  47. protected function setUp(): void {
  48. parent::setUp();
  49. $this->appManager = \OC::$server->getAppManager();
  50. $this->groupManager = \OC::$server->getGroupManager();
  51. $this->userSession = \OC::$server->getUserSession();
  52. $request = $this->getMockBuilder(IRequest::class)
  53. ->disableOriginalConstructor()
  54. ->getMock();
  55. $this->api = new AppsController(
  56. 'provisioning_api',
  57. $request,
  58. $this->appManager
  59. );
  60. }
  61. public function testGetAppInfo() {
  62. $result = $this->api->getAppInfo('provisioning_api');
  63. $expected = $this->appManager->getAppInfo('provisioning_api');
  64. $this->assertEquals($expected, $result->getData());
  65. }
  66. public function testGetAppInfoOnBadAppID() {
  67. $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
  68. $this->expectExceptionCode(998);
  69. $this->api->getAppInfo('not_provisioning_api');
  70. }
  71. public function testGetApps() {
  72. $user = $this->generateUsers();
  73. $this->groupManager->get('admin')->addUser($user);
  74. $this->userSession->setUser($user);
  75. $result = $this->api->getApps();
  76. $data = $result->getData();
  77. $this->assertEquals(count((new \OC_App())->listAllApps()), count($data['apps']));
  78. }
  79. public function testGetAppsEnabled() {
  80. $result = $this->api->getApps('enabled');
  81. $data = $result->getData();
  82. $this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps']));
  83. }
  84. public function testGetAppsDisabled() {
  85. $result = $this->api->getApps('disabled');
  86. $data = $result->getData();
  87. $apps = (new \OC_App)->listAllApps();
  88. $list = [];
  89. foreach ($apps as $app) {
  90. $list[] = $app['id'];
  91. }
  92. $disabled = array_diff($list, \OC_App::getEnabledApps());
  93. $this->assertEquals(count($disabled), count($data['apps']));
  94. }
  95. public function testGetAppsInvalidFilter() {
  96. $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
  97. $this->expectExceptionCode(101);
  98. $this->api->getApps('foo');
  99. }
  100. }