appstest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Tom Needham <tom@owncloud.com>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Provisioning_API\Tests;
  24. class AppsTest extends TestCase {
  25. public function testGetAppInfo() {
  26. $result = \OCA\provisioning_API\Apps::getAppInfo(array('appid' => 'provisioning_api'));
  27. $this->assertInstanceOf('OC_OCS_Result', $result);
  28. $this->assertTrue($result->succeeded());
  29. }
  30. public function testGetAppInfoOnBadAppID() {
  31. $result = \OCA\provisioning_API\Apps::getAppInfo(array('appid' => 'not_provisioning_api'));
  32. $this->assertInstanceOf('OC_OCS_Result', $result);
  33. $this->assertFalse($result->succeeded());
  34. $this->assertEquals(\OC_API::RESPOND_NOT_FOUND, $result->getStatusCode());
  35. }
  36. public function testGetApps() {
  37. $user = $this->generateUsers();
  38. \OC_Group::addToGroup($user, 'admin');
  39. \OC_User::setUserId($user);
  40. $result = \OCA\provisioning_API\Apps::getApps(array());
  41. $this->assertTrue($result->succeeded());
  42. $data = $result->getData();
  43. $this->assertEquals(count(\OC_App::listAllApps()), count($data['apps']));
  44. }
  45. public function testGetAppsEnabled() {
  46. $_GET['filter'] = 'enabled';
  47. $result = \OCA\provisioning_API\Apps::getApps(array('filter' => 'enabled'));
  48. $this->assertTrue($result->succeeded());
  49. $data = $result->getData();
  50. $this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps']));
  51. }
  52. public function testGetAppsDisabled() {
  53. $_GET['filter'] = 'disabled';
  54. $result = \OCA\provisioning_API\Apps::getApps(array('filter' => 'disabled'));
  55. $this->assertTrue($result->succeeded());
  56. $data = $result->getData();
  57. $apps = \OC_App::listAllApps();
  58. $list = array();
  59. foreach($apps as $app) {
  60. $list[] = $app['id'];
  61. }
  62. $disabled = array_diff($list, \OC_App::getEnabledApps());
  63. $this->assertEquals(count($disabled), count($data['apps']));
  64. }
  65. }