diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2017-03-20 20:10:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-20 20:10:05 +0300 |
commit | 03a92eaf74ea3898f67a12e3c19216683abb44d8 (patch) | |
tree | 533fa317e6b1ef57a4a3f391b84e9778268b2312 /tests/lib | |
parent | be9ae45a4b8ced2173d1322a2d78a670e706e878 (diff) | |
parent | 5795482282bed45c678b26799da83e4da4ae2978 (diff) |
Merge pull request #3957 from nextcloud/downstream-27307
Follow up to #3949 (app exists on enable)
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/App/AppManagerTest.php (renamed from tests/lib/App/ManagerTest.php) | 103 |
1 files changed, 50 insertions, 53 deletions
diff --git a/tests/lib/App/ManagerTest.php b/tests/lib/App/AppManagerTest.php index 8b23168938c..bfb2893955f 100644 --- a/tests/lib/App/ManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -9,25 +9,33 @@ namespace Test\App; +use OC\App\AppManager; use OC\Group\Group; use OC\User\User; use OCP\App\AppPathNotFoundException; +use OCP\App\IAppManager; +use OCP\ICache; +use OCP\ICacheFactory; +use OCP\IGroupManager; +use OCP\IUserSession; +use OCP\IAppConfig; +use OCP\IConfig; +use OCP\IURLGenerator; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; /** - * Class Manager + * Class AppManagerTest * * @package Test\App */ -class ManagerTest extends TestCase { +class AppManagerTest extends TestCase { /** - * @return \OCP\IAppConfig | \PHPUnit_Framework_MockObject_MockObject + * @return IAppConfig|\PHPUnit_Framework_MockObject_MockObject */ protected function getAppConfig() { $appConfig = array(); - $config = $this->getMockBuilder('\OCP\IAppConfig') - ->disableOriginalConstructor() - ->getMock(); + $config = $this->createMock(IAppConfig::class); $config->expects($this->any()) ->method('getValue') @@ -49,9 +57,9 @@ class ManagerTest extends TestCase { return $appConfig[$app]; } else { $values = array(); - foreach ($appConfig as $app => $appData) { + foreach ($appConfig as $appid => $appData) { if (isset($appData[$key])) { - $values[$app] = $appData[$key]; + $values[$appid] = $appData[$key]; } } return $values; @@ -61,51 +69,41 @@ class ManagerTest extends TestCase { return $config; } - /** @var \OCP\IUserSession */ + /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $userSession; - /** @var \OCP\IGroupManager */ + /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ protected $groupManager; - /** @var \OCP\IAppConfig */ + /** @var IAppConfig|\PHPUnit_Framework_MockObject_MockObject */ protected $appConfig; - /** @var \OCP\ICache */ + /** @var ICache|\PHPUnit_Framework_MockObject_MockObject */ protected $cache; - /** @var \OCP\ICacheFactory */ + /** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */ protected $cacheFactory; - /** @var \OCP\App\IAppManager */ - protected $manager; - - /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ + /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $eventDispatcher; + /** @var IAppManager */ + protected $manager; + protected function setUp() { parent::setUp(); - $this->userSession = $this->getMockBuilder('\OCP\IUserSession') - ->disableOriginalConstructor() - ->getMock(); - $this->groupManager = $this->getMockBuilder('\OCP\IGroupManager') - ->disableOriginalConstructor() - ->getMock(); + $this->userSession = $this->createMock(IUserSession::class); + $this->groupManager = $this->createMock(IGroupManager::class); $this->appConfig = $this->getAppConfig(); - $this->cacheFactory = $this->getMockBuilder('\OCP\ICacheFactory') - ->disableOriginalConstructor() - ->getMock(); - $this->cache = $this->getMockBuilder('\OCP\ICache') - ->disableOriginalConstructor() - ->getMock(); - $this->eventDispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcherInterface') - ->disableOriginalConstructor() - ->getMock(); + $this->cacheFactory = $this->createMock(ICacheFactory::class); + $this->cache = $this->createMock(ICache::class); + $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->cacheFactory->expects($this->any()) ->method('create') ->with('settings') ->willReturn($this->cache); - $this->manager = new \OC\App\AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher); + $this->manager = new AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher); } protected function expectClearCache() { @@ -134,10 +132,11 @@ class ManagerTest extends TestCase { 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()); + } catch (AppPathNotFoundException $e) { + // Exception is expected + $this->assertEquals('Could not find path for some_random_name_which_i_hope_is_not_an_app', $e->getMessage()); } + $this->assertEquals('no', $this->appConfig->getValue( 'some_random_name_which_i_hope_is_not_an_app', 'enabled', 'no' )); @@ -177,8 +176,8 @@ class ManagerTest extends TestCase { ); $this->expectClearCache(); - /** @var \OC\App\AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ - $manager = $this->getMockBuilder('OC\App\AppManager') + /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ + $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([ $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher ]) @@ -220,8 +219,8 @@ class ManagerTest extends TestCase { new Group('group2', array(), null) ); - /** @var \OC\App\AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ - $manager = $this->getMockBuilder('OC\App\AppManager') + /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ + $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([ $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher ]) @@ -256,12 +255,8 @@ class ManagerTest extends TestCase { } private function newUser($uid) { - $config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $urlgenerator = $this->getMockBuilder('\OCP\IURLGenerator') - ->disableOriginalConstructor() - ->getMock(); + $config = $this->createMock(IConfig::class); + $urlgenerator = $this->createMock(IURLGenerator::class); return new User($uid, null, null, $config, $urlgenerator); } @@ -311,7 +306,7 @@ class ManagerTest extends TestCase { public function testIsEnabledForUserLoggedOut() { $this->appConfig->setValue('test', 'enabled', '["foo"]'); - $this->assertFalse($this->manager->IsEnabledForUser('test')); + $this->assertFalse($this->manager->isEnabledForUser('test')); } public function testIsEnabledForUserLoggedIn() { @@ -373,7 +368,8 @@ class ManagerTest extends TestCase { } public function testGetAppsNeedingUpgrade() { - $this->manager = $this->getMockBuilder('\OC\App\AppManager') + /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ + $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher]) ->setMethods(['getAppInfo']) ->getMock(); @@ -393,7 +389,7 @@ class ManagerTest extends TestCase { 'workflowengine' => ['id' => 'workflowengine'], ]; - $this->manager->expects($this->any()) + $manager->expects($this->any()) ->method('getAppInfo') ->will($this->returnCallback( function($appId) use ($appInfos) { @@ -410,7 +406,7 @@ class ManagerTest extends TestCase { $this->appConfig->setValue('test4', 'enabled', 'yes'); $this->appConfig->setValue('test4', 'installed_version', '2.4.0'); - $apps = $this->manager->getAppsNeedingUpgrade('8.2.0'); + $apps = $manager->getAppsNeedingUpgrade('8.2.0'); $this->assertCount(2, $apps); $this->assertEquals('test1', $apps[0]['id']); @@ -418,7 +414,8 @@ class ManagerTest extends TestCase { } public function testGetIncompatibleApps() { - $this->manager = $this->getMockBuilder('\OC\App\AppManager') + /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ + $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher]) ->setMethods(['getAppInfo']) ->getMock(); @@ -437,7 +434,7 @@ class ManagerTest extends TestCase { 'workflowengine' => ['id' => 'workflowengine'], ]; - $this->manager->expects($this->any()) + $manager->expects($this->any()) ->method('getAppInfo') ->will($this->returnCallback( function($appId) use ($appInfos) { @@ -449,7 +446,7 @@ class ManagerTest extends TestCase { $this->appConfig->setValue('test2', 'enabled', 'yes'); $this->appConfig->setValue('test3', 'enabled', 'yes'); - $apps = $this->manager->getIncompatibleApps('8.2.0'); + $apps = $manager->getIncompatibleApps('8.2.0'); $this->assertCount(2, $apps); $this->assertEquals('test1', $apps[0]['id']); |