diff options
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r-- | apps/provisioning_api/appinfo/routes.php | 4 | ||||
-rw-r--r-- | apps/provisioning_api/lib/apps.php | 21 | ||||
-rw-r--r-- | apps/provisioning_api/tests/appstest.php | 17 |
3 files changed, 29 insertions, 13 deletions
diff --git a/apps/provisioning_api/appinfo/routes.php b/apps/provisioning_api/appinfo/routes.php index e656445abe5..2ee3a185dae 100644 --- a/apps/provisioning_api/appinfo/routes.php +++ b/apps/provisioning_api/appinfo/routes.php @@ -56,7 +56,9 @@ API::register('delete', '/cloud/groups/{groupid}', [$groups, 'deleteGroup'], 'pr API::register('get', '/cloud/groups/{groupid}/subadmins', [$groups, 'getSubAdminsOfGroup'], 'provisioning_api', API::ADMIN_AUTH); // Apps -$apps = new \OCA\Provisioning_API\Apps(); +$apps = new \OCA\Provisioning_API\Apps( + \OC::$server->getAppManager() +); API::register('get', '/cloud/apps', [$apps, 'getApps'], 'provisioning_api', API::ADMIN_AUTH); API::register('get', '/cloud/apps/{appid}', [$apps, 'getAppInfo'], 'provisioning_api', API::ADMIN_AUTH); API::register('post', '/cloud/apps/{appid}', [$apps, 'enable'], 'provisioning_api', API::ADMIN_AUTH); diff --git a/apps/provisioning_api/lib/apps.php b/apps/provisioning_api/lib/apps.php index 22713865c1e..168f6f3cad8 100644 --- a/apps/provisioning_api/lib/apps.php +++ b/apps/provisioning_api/lib/apps.php @@ -28,7 +28,14 @@ use \OC_App; class Apps { - public static function getApps($parameters){ + /** @var \OCP\App\IAppManager */ + private $appManager; + + public function __construct(\OCP\App\IAppManager $appManager) { + $this->appManager = $appManager; + } + + public function getApps($parameters){ $apps = OC_App::listAllApps(); $list = array(); foreach($apps as $app) { @@ -55,9 +62,9 @@ class Apps { } } - public static function getAppInfo($parameters){ + public function getAppInfo($parameters){ $app = $parameters['appid']; - $info = OC_App::getAppInfo($app); + $info = \OCP\App::getAppInfo($app); if(!is_null($info)) { return new OC_OCS_Result(OC_App::getAppInfo($app)); } else { @@ -65,15 +72,15 @@ class Apps { } } - public static function enable($parameters){ + public function enable($parameters){ $app = $parameters['appid']; - OC_App::enable($app); + $this->appManager->enableApp($app); return new OC_OCS_Result(null, 100); } - public static function disable($parameters){ + public function disable($parameters){ $app = $parameters['appid']; - OC_App::disable($app); + $this->appManager->disableApp($app); return new OC_OCS_Result(null, 100); } diff --git a/apps/provisioning_api/tests/appstest.php b/apps/provisioning_api/tests/appstest.php index c4298f017fc..2a623098444 100644 --- a/apps/provisioning_api/tests/appstest.php +++ b/apps/provisioning_api/tests/appstest.php @@ -25,8 +25,15 @@ namespace OCA\Provisioning_API\Tests; class AppsTest extends TestCase { + + public function setup() { + parent::setup(); + $this->appManager = \OC::$server->getAppManager(); + $this->api = new \OCA\Provisioning_API\Apps($this->appManager); + } + public function testGetAppInfo() { - $result = \OCA\provisioning_API\Apps::getAppInfo(array('appid' => 'provisioning_api')); + $result = $this->api->getAppInfo(['appid' => 'provisioning_api']); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); @@ -34,7 +41,7 @@ class AppsTest extends TestCase { public function testGetAppInfoOnBadAppID() { - $result = \OCA\provisioning_API\Apps::getAppInfo(array('appid' => 'not_provisioning_api')); + $result = $this->api->getAppInfo(['appid' => 'not_provisioning_api']); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertFalse($result->succeeded()); $this->assertEquals(\OCP\API::RESPOND_NOT_FOUND, $result->getStatusCode()); @@ -47,7 +54,7 @@ class AppsTest extends TestCase { \OC_Group::addToGroup($user, 'admin'); self::loginAsUser($user); - $result = \OCA\provisioning_API\Apps::getApps(array()); + $result = $this->api->getApps([]); $this->assertTrue($result->succeeded()); $data = $result->getData(); @@ -58,7 +65,7 @@ class AppsTest extends TestCase { public function testGetAppsEnabled() { $_GET['filter'] = 'enabled'; - $result = \OCA\provisioning_API\Apps::getApps(array('filter' => 'enabled')); + $result = $this->api->getApps(['filter' => 'enabled']); $this->assertTrue($result->succeeded()); $data = $result->getData(); $this->assertEquals(count(\OC_App::getEnabledApps()), count($data['apps'])); @@ -68,7 +75,7 @@ class AppsTest extends TestCase { public function testGetAppsDisabled() { $_GET['filter'] = 'disabled'; - $result = \OCA\provisioning_API\Apps::getApps(array('filter' => 'disabled')); + $result = $this->api->getApps(['filter' => 'disabled']); $this->assertTrue($result->succeeded()); $data = $result->getData(); $apps = \OC_App::listAllApps(); |