AppsControllerTest.php 3.3 KB

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