appstest.php 2.5 KB

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