diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 6b819ef7ac..6c1f5ba694 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -32,6 +32,7 @@ namespace OC\App; use OCP\App\AppPathNotFoundException; +use OC_App; use OCP\App\IAppManager; use OCP\App\ManagerEvent; use OCP\IAppConfig; @@ -210,8 +211,12 @@ class AppManager implements IAppManager { * Enable an app for every user * * @param string $appId + * @throws \Exception */ public function enableApp($appId) { + if(OC_App::getAppPath($appId) === false) { + throw new \Exception("$appId can't be enabled since it is not installed."); + } $this->installedAppsCache[$appId] = 'yes'; $this->appConfig->setValue($appId, 'enabled', 'yes'); $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( diff --git a/tests/lib/App/ManagerTest.php b/tests/lib/App/ManagerTest.php index e38f72b3d9..8b23168938 100644 --- a/tests/lib/App/ManagerTest.php +++ b/tests/lib/App/ManagerTest.php @@ -116,16 +116,33 @@ class ManagerTest extends TestCase { public function testEnableApp() { $this->expectClearCache(); - $this->manager->enableApp('test'); - $this->assertEquals('yes', $this->appConfig->getValue('test', 'enabled', 'no')); + // making sure "files_trashbin" is disabled + if ($this->manager->isEnabledForUser('files_trashbin')) { + $this->manager->disableApp('files_trashbin'); + } + $this->manager->enableApp('files_trashbin'); + $this->assertEquals('yes', $this->appConfig->getValue('files_trashbin', 'enabled', 'no')); } public function testDisableApp() { $this->expectClearCache(); - $this->manager->disableApp('test'); - $this->assertEquals('no', $this->appConfig->getValue('test', 'enabled', 'no')); + $this->manager->disableApp('files_trashbin'); + $this->assertEquals('no', $this->appConfig->getValue('files_trashbin', 'enabled', 'no')); } + public function testNotEnableIfNotInstalled() { + try { + $this->manager->enableApp('some_random_name_which_i_hope_is_not_an_app'); + $this->assertFalse(true, 'If this line is reached the expected exception is not thrown.'); + } catch (\Exception $e) { + // excpetion is expected + $this->assertEquals("some_random_name_which_i_hope_is_not_an_app can't be enabled since it is not installed.", $e->getMessage()); + } + $this->assertEquals('no', $this->appConfig->getValue( + 'some_random_name_which_i_hope_is_not_an_app', 'enabled', 'no' + )); + } + public function testEnableAppForGroups() { $groups = array( new Group('group1', array(), null),