From 5481a9b84a1e3500b36583cb4c300ea0491bbdcd Mon Sep 17 00:00:00 2001 From: noveens Date: Wed, 8 Mar 2017 15:43:47 +0530 Subject: [PATCH 1/3] checking if app exists in the FileStream now Signed-off-by: Morris Jobke --- lib/private/App/AppManager.php | 4 ++++ tests/lib/App/ManagerTest.php | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 6b819ef7ac..cc2e9203a2 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; @@ -212,6 +213,9 @@ class AppManager implements IAppManager { * @param string $appId */ 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..7945073726 100644 --- a/tests/lib/App/ManagerTest.php +++ b/tests/lib/App/ManagerTest.php @@ -116,16 +116,30 @@ 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')); } + /** + * @expectedException \Exception + */ + public function testNotEnableIfNotInstalled() { + $this->manager->enableApp('some_random_name_which_i_hope_is_not_an_app'); + $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), From 50b0a4b1810b921cab5fbd514219f5d26e406c6e Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 20 Mar 2017 02:47:32 -0600 Subject: [PATCH 2/3] Improve the test case Signed-off-by: Morris Jobke --- tests/lib/App/ManagerTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/lib/App/ManagerTest.php b/tests/lib/App/ManagerTest.php index 7945073726..8b23168938 100644 --- a/tests/lib/App/ManagerTest.php +++ b/tests/lib/App/ManagerTest.php @@ -130,11 +130,14 @@ class ManagerTest extends TestCase { $this->assertEquals('no', $this->appConfig->getValue('files_trashbin', 'enabled', 'no')); } - /** - * @expectedException \Exception - */ public function testNotEnableIfNotInstalled() { - $this->manager->enableApp('some_random_name_which_i_hope_is_not_an_app'); + 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' )); From 20c80cba6f4d5f0d56de0842eb9f93534845df4d Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 20 Mar 2017 10:13:57 +0100 Subject: [PATCH 3/3] Add exception to PHPDoc Signed-off-by: Lukas Reschke --- lib/private/App/AppManager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index cc2e9203a2..6c1f5ba694 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -211,6 +211,7 @@ 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) {