2019-09-05 13:55:24 +03:00
|
|
|
<?php declare(strict_types=1);
|
2014-11-07 16:26:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\App;
|
|
|
|
|
2017-03-20 12:21:08 +03:00
|
|
|
use OC\App\AppManager;
|
2018-01-17 23:10:40 +03:00
|
|
|
use OC\AppConfig;
|
2016-11-17 14:30:52 +03:00
|
|
|
use OCP\App\AppPathNotFoundException;
|
2017-03-20 12:21:08 +03:00
|
|
|
use OCP\App\IAppManager;
|
|
|
|
use OCP\ICache;
|
|
|
|
use OCP\ICacheFactory;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IConfig;
|
2019-02-22 15:07:26 +03:00
|
|
|
use OCP\IGroup;
|
2017-03-20 12:21:08 +03:00
|
|
|
use OCP\IGroupManager;
|
2019-07-15 23:19:11 +03:00
|
|
|
use OCP\ILogger;
|
2019-02-22 15:07:26 +03:00
|
|
|
use OCP\IUser;
|
2017-03-20 12:21:08 +03:00
|
|
|
use OCP\IUserSession;
|
2019-09-05 13:55:24 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2017-03-20 12:21:08 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2015-12-17 19:29:17 +03:00
|
|
|
use Test\TestCase;
|
2014-11-07 16:26:12 +03:00
|
|
|
|
2016-01-14 17:23:07 +03:00
|
|
|
/**
|
2017-03-20 12:21:08 +03:00
|
|
|
* Class AppManagerTest
|
2016-01-14 17:23:07 +03:00
|
|
|
*
|
|
|
|
* @package Test\App
|
|
|
|
*/
|
2017-03-20 12:21:08 +03:00
|
|
|
class AppManagerTest extends TestCase {
|
2014-11-07 16:26:12 +03:00
|
|
|
/**
|
2019-09-05 13:55:24 +03:00
|
|
|
* @return AppConfig|MockObject
|
2014-11-07 16:26:12 +03:00
|
|
|
*/
|
|
|
|
protected function getAppConfig() {
|
|
|
|
$appConfig = array();
|
2018-01-17 23:10:40 +03:00
|
|
|
$config = $this->createMock(AppConfig::class);
|
2014-11-07 16:26:12 +03:00
|
|
|
|
|
|
|
$config->expects($this->any())
|
|
|
|
->method('getValue')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($app, $key, $default) use (&$appConfig) {
|
2014-11-07 16:26:12 +03:00
|
|
|
return (isset($appConfig[$app]) and isset($appConfig[$app][$key])) ? $appConfig[$app][$key] : $default;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-11-07 16:26:12 +03:00
|
|
|
$config->expects($this->any())
|
|
|
|
->method('setValue')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($app, $key, $value) use (&$appConfig) {
|
2014-11-07 16:26:12 +03:00
|
|
|
if (!isset($appConfig[$app])) {
|
|
|
|
$appConfig[$app] = array();
|
|
|
|
}
|
|
|
|
$appConfig[$app][$key] = $value;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-11-07 16:26:12 +03:00
|
|
|
$config->expects($this->any())
|
|
|
|
->method('getValues')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($app, $key) use (&$appConfig) {
|
2014-11-07 16:26:12 +03:00
|
|
|
if ($app) {
|
|
|
|
return $appConfig[$app];
|
|
|
|
} else {
|
|
|
|
$values = array();
|
2017-03-20 12:21:08 +03:00
|
|
|
foreach ($appConfig as $appid => $appData) {
|
2014-11-07 16:26:12 +03:00
|
|
|
if (isset($appData[$key])) {
|
2017-03-20 12:21:08 +03:00
|
|
|
$values[$appid] = $appData[$key];
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $values;
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-11-07 16:26:12 +03:00
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var IUserSession|MockObject */
|
2015-04-01 18:19:44 +03:00
|
|
|
protected $userSession;
|
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var IConfig|MockObject */
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
/** @var IGroupManager|MockObject */
|
2015-04-01 18:19:44 +03:00
|
|
|
protected $groupManager;
|
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var AppConfig|MockObject */
|
2015-04-01 18:19:44 +03:00
|
|
|
protected $appConfig;
|
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var ICache|MockObject */
|
2015-04-01 18:19:44 +03:00
|
|
|
protected $cache;
|
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var ICacheFactory|MockObject */
|
2015-04-01 18:19:44 +03:00
|
|
|
protected $cacheFactory;
|
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var EventDispatcherInterface|MockObject */
|
2016-02-09 04:51:12 +03:00
|
|
|
protected $eventDispatcher;
|
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var ILogger|MockObject */
|
2019-07-15 23:19:11 +03:00
|
|
|
protected $logger;
|
|
|
|
|
2017-03-20 12:21:08 +03:00
|
|
|
/** @var IAppManager */
|
|
|
|
protected $manager;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2015-04-01 18:19:44 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-03-20 13:14:14 +03:00
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2019-09-05 13:55:24 +03:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig = $this->getAppConfig();
|
2017-03-20 13:14:14 +03:00
|
|
|
$this->cacheFactory = $this->createMock(ICacheFactory::class);
|
|
|
|
$this->cache = $this->createMock(ICache::class);
|
|
|
|
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
|
2019-07-15 23:19:11 +03:00
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->cacheFactory->expects($this->any())
|
2017-12-18 23:06:52 +03:00
|
|
|
->method('createDistributed')
|
2015-04-01 18:19:44 +03:00
|
|
|
->with('settings')
|
|
|
|
->willReturn($this->cache);
|
2019-09-05 13:55:24 +03:00
|
|
|
$this->manager = new AppManager(
|
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->appConfig,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger
|
|
|
|
);
|
2015-04-01 18:19:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function expectClearCache() {
|
|
|
|
$this->cache->expects($this->once())
|
|
|
|
->method('clear')
|
|
|
|
->with('listApps');
|
|
|
|
}
|
|
|
|
|
2014-11-07 16:26:12 +03:00
|
|
|
public function testEnableApp() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->expectClearCache();
|
2017-03-08 13:13:47 +03:00
|
|
|
// 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'));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisableApp() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->expectClearCache();
|
2017-03-08 13:13:47 +03:00
|
|
|
$this->manager->disableApp('files_trashbin');
|
|
|
|
$this->assertEquals('no', $this->appConfig->getValue('files_trashbin', 'enabled', 'no'));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 13:13:47 +03:00
|
|
|
public function testNotEnableIfNotInstalled() {
|
2017-03-20 11:47:32 +03:00
|
|
|
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.');
|
2017-03-20 12:02:05 +03:00
|
|
|
} 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());
|
2017-03-20 11:47:32 +03:00
|
|
|
}
|
2017-03-20 12:02:05 +03:00
|
|
|
|
2017-03-08 13:13:47 +03:00
|
|
|
$this->assertEquals('no', $this->appConfig->getValue(
|
|
|
|
'some_random_name_which_i_hope_is_not_an_app', 'enabled', 'no'
|
|
|
|
));
|
2017-05-20 21:58:36 +03:00
|
|
|
}
|
2017-03-08 13:13:47 +03:00
|
|
|
|
2014-11-07 16:26:12 +03:00
|
|
|
public function testEnableAppForGroups() {
|
2019-02-22 15:07:26 +03:00
|
|
|
$group1 = $this->createMock(IGroup::class);
|
|
|
|
$group1->method('getGID')
|
|
|
|
->willReturn('group1');
|
|
|
|
$group2 = $this->createMock(IGroup::class);
|
|
|
|
$group2->method('getGID')
|
|
|
|
->willReturn('group2');
|
|
|
|
|
|
|
|
$groups = [$group1, $group2];
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->expectClearCache();
|
2019-01-27 00:31:45 +03:00
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2019-01-27 00:31:45 +03:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
|
|
|
->setConstructorArgs([
|
2019-09-05 13:55:24 +03:00
|
|
|
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
|
2019-01-27 00:31:45 +03:00
|
|
|
])
|
|
|
|
->setMethods([
|
|
|
|
'getAppPath',
|
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$manager->expects($this->exactly(2))
|
|
|
|
->method('getAppPath')
|
|
|
|
->with('test')
|
|
|
|
->willReturn('apps/test');
|
|
|
|
|
|
|
|
$manager->enableAppForGroups('test', $groups);
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no'));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
2016-01-14 17:23:07 +03:00
|
|
|
public function dataEnableAppForGroupsAllowedTypes() {
|
|
|
|
return [
|
|
|
|
[[]],
|
|
|
|
[[
|
|
|
|
'types' => [],
|
|
|
|
]],
|
|
|
|
[[
|
|
|
|
'types' => ['nickvergessen'],
|
|
|
|
]],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataEnableAppForGroupsAllowedTypes
|
|
|
|
*
|
|
|
|
* @param array $appInfo
|
|
|
|
*/
|
|
|
|
public function testEnableAppForGroupsAllowedTypes(array $appInfo) {
|
2019-02-22 15:07:26 +03:00
|
|
|
$group1 = $this->createMock(IGroup::class);
|
|
|
|
$group1->method('getGID')
|
|
|
|
->willReturn('group1');
|
|
|
|
$group2 = $this->createMock(IGroup::class);
|
|
|
|
$group2->method('getGID')
|
|
|
|
->willReturn('group2');
|
|
|
|
|
|
|
|
$groups = [$group1, $group2];
|
2016-01-14 17:23:07 +03:00
|
|
|
$this->expectClearCache();
|
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2017-03-20 12:21:08 +03:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
2016-01-14 17:23:07 +03:00
|
|
|
->setConstructorArgs([
|
2019-09-05 13:55:24 +03:00
|
|
|
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
|
2016-01-14 17:23:07 +03:00
|
|
|
])
|
|
|
|
->setMethods([
|
2019-01-27 00:31:45 +03:00
|
|
|
'getAppPath',
|
|
|
|
'getAppInfo',
|
2016-01-14 17:23:07 +03:00
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
2019-01-27 00:31:45 +03:00
|
|
|
$manager->expects($this->once())
|
|
|
|
->method('getAppPath')
|
|
|
|
->with('test')
|
|
|
|
->willReturn(null);
|
|
|
|
|
2016-01-14 17:23:07 +03:00
|
|
|
$manager->expects($this->once())
|
|
|
|
->method('getAppInfo')
|
|
|
|
->with('test')
|
|
|
|
->willReturn($appInfo);
|
|
|
|
|
|
|
|
$manager->enableAppForGroups('test', $groups);
|
|
|
|
$this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataEnableAppForGroupsForbiddenTypes() {
|
|
|
|
return [
|
|
|
|
['filesystem'],
|
|
|
|
['prelogin'],
|
|
|
|
['authentication'],
|
|
|
|
['logging'],
|
|
|
|
['prevent_group_restriction'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataEnableAppForGroupsForbiddenTypes
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function testEnableAppForGroupsForbiddenTypes($type) {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('test can\'t be enabled for groups.');
|
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
$group1 = $this->createMock(IGroup::class);
|
|
|
|
$group1->method('getGID')
|
|
|
|
->willReturn('group1');
|
|
|
|
$group2 = $this->createMock(IGroup::class);
|
|
|
|
$group2->method('getGID')
|
|
|
|
->willReturn('group2');
|
|
|
|
|
|
|
|
$groups = [$group1, $group2];
|
2016-01-14 17:23:07 +03:00
|
|
|
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2017-03-20 12:21:08 +03:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
2016-01-14 17:23:07 +03:00
|
|
|
->setConstructorArgs([
|
2019-09-05 13:55:24 +03:00
|
|
|
$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
|
2016-01-14 17:23:07 +03:00
|
|
|
])
|
|
|
|
->setMethods([
|
2019-01-27 00:31:45 +03:00
|
|
|
'getAppPath',
|
|
|
|
'getAppInfo',
|
2016-01-14 17:23:07 +03:00
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
2019-01-27 00:31:45 +03:00
|
|
|
$manager->expects($this->once())
|
|
|
|
->method('getAppPath')
|
|
|
|
->with('test')
|
|
|
|
->willReturn(null);
|
|
|
|
|
2016-01-14 17:23:07 +03:00
|
|
|
$manager->expects($this->once())
|
|
|
|
->method('getAppInfo')
|
|
|
|
->with('test')
|
|
|
|
->willReturn([
|
|
|
|
'types' => [$type],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$manager->enableAppForGroups('test', $groups);
|
|
|
|
}
|
|
|
|
|
2014-11-07 16:26:12 +03:00
|
|
|
public function testIsInstalledEnabled() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', 'yes');
|
|
|
|
$this->assertTrue($this->manager->isInstalled('test'));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsInstalledDisabled() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', 'no');
|
|
|
|
$this->assertFalse($this->manager->isInstalled('test'));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsInstalledEnabledForGroups() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
|
|
|
$this->assertTrue($this->manager->isInstalled('test'));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
2016-07-14 14:49:18 +03:00
|
|
|
private function newUser($uid) {
|
2019-02-22 15:07:26 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$user->method('getUID')
|
|
|
|
->willReturn($uid);
|
2016-07-14 14:49:18 +03:00
|
|
|
|
2019-02-22 15:07:26 +03:00
|
|
|
return $user;
|
2016-07-14 14:49:18 +03:00
|
|
|
}
|
|
|
|
|
2014-11-07 16:26:12 +03:00
|
|
|
public function testIsEnabledForUserEnabled() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', 'yes');
|
2016-07-14 14:49:18 +03:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->assertTrue($this->manager->isEnabledForUser('test', $user));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsEnabledForUserDisabled() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', 'no');
|
2016-07-14 14:49:18 +03:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->assertFalse($this->manager->isEnabledForUser('test', $user));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
2016-11-17 14:30:52 +03:00
|
|
|
public function testGetAppPath() {
|
|
|
|
$this->assertEquals(\OC::$SERVERROOT . '/apps/files', $this->manager->getAppPath('files'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAppPathFail() {
|
|
|
|
$this->expectException(AppPathNotFoundException::class);
|
|
|
|
$this->manager->getAppPath('testnotexisting');
|
|
|
|
}
|
|
|
|
|
2014-11-07 16:26:12 +03:00
|
|
|
public function testIsEnabledForUserEnabledForGroup() {
|
2016-07-14 14:49:18 +03:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-11-07 16:26:12 +03:00
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(array('foo', 'bar'));
|
2014-11-07 16:26:12 +03:00
|
|
|
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
|
|
|
$this->assertTrue($this->manager->isEnabledForUser('test', $user));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsEnabledForUserDisabledForGroup() {
|
2016-07-14 14:49:18 +03:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-11-07 16:26:12 +03:00
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(array('bar'));
|
2014-11-07 16:26:12 +03:00
|
|
|
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
|
|
|
$this->assertFalse($this->manager->isEnabledForUser('test', $user));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsEnabledForUserLoggedOut() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
2017-03-20 12:21:08 +03:00
|
|
|
$this->assertFalse($this->manager->isEnabledForUser('test'));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsEnabledForUserLoggedIn() {
|
2016-07-14 14:49:18 +03:00
|
|
|
$user = $this->newUser('user1');
|
2014-11-07 16:26:12 +03:00
|
|
|
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->userSession->expects($this->once())
|
2014-11-07 16:26:12 +03:00
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-11-07 16:26:12 +03:00
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(array('foo', 'bar'));
|
2014-11-07 16:26:12 +03:00
|
|
|
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
|
|
|
$this->assertTrue($this->manager->isEnabledForUser('test'));
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|
2015-02-02 16:47:29 +03:00
|
|
|
|
|
|
|
public function testGetInstalledApps() {
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test1', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test2', 'enabled', 'no');
|
|
|
|
$this->appConfig->setValue('test3', 'enabled', '["foo"]');
|
2016-09-19 20:43:47 +03:00
|
|
|
$apps = [
|
2018-06-29 11:46:09 +03:00
|
|
|
'cloud_federation_api',
|
2016-09-19 20:43:47 +03:00
|
|
|
'dav',
|
|
|
|
'federatedfilesharing',
|
|
|
|
'files',
|
2016-11-17 14:14:13 +03:00
|
|
|
'lookup_server_connector',
|
2017-05-20 21:58:36 +03:00
|
|
|
'oauth2',
|
2016-09-19 20:43:47 +03:00
|
|
|
'provisioning_api',
|
2019-09-17 17:33:27 +03:00
|
|
|
'settings',
|
2016-09-19 20:43:47 +03:00
|
|
|
'test1',
|
|
|
|
'test3',
|
|
|
|
'twofactor_backupcodes',
|
2019-12-10 17:08:19 +03:00
|
|
|
'viewer',
|
2016-09-19 20:43:47 +03:00
|
|
|
'workflowengine',
|
|
|
|
];
|
2016-09-02 13:53:44 +03:00
|
|
|
$this->assertEquals($apps, $this->manager->getInstalledApps());
|
2015-02-02 16:47:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAppsForUser() {
|
2016-07-14 14:49:18 +03:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->groupManager->expects($this->any())
|
2015-02-02 16:47:29 +03:00
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(array('foo', 'bar'));
|
2015-02-02 16:47:29 +03:00
|
|
|
|
2015-04-01 18:19:44 +03:00
|
|
|
$this->appConfig->setValue('test1', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test2', 'enabled', 'no');
|
|
|
|
$this->appConfig->setValue('test3', 'enabled', '["foo"]');
|
|
|
|
$this->appConfig->setValue('test4', 'enabled', '["asd"]');
|
2016-09-02 13:53:44 +03:00
|
|
|
$enabled = [
|
2018-06-29 11:46:09 +03:00
|
|
|
'cloud_federation_api',
|
2016-09-02 13:53:44 +03:00
|
|
|
'dav',
|
|
|
|
'federatedfilesharing',
|
|
|
|
'files',
|
2016-11-17 14:14:13 +03:00
|
|
|
'lookup_server_connector',
|
2017-05-20 21:58:36 +03:00
|
|
|
'oauth2',
|
2016-09-19 20:43:47 +03:00
|
|
|
'provisioning_api',
|
2019-09-17 17:33:27 +03:00
|
|
|
'settings',
|
2016-09-02 13:53:44 +03:00
|
|
|
'test1',
|
|
|
|
'test3',
|
|
|
|
'twofactor_backupcodes',
|
2019-12-10 17:08:19 +03:00
|
|
|
'viewer',
|
2017-05-20 21:58:36 +03:00
|
|
|
'workflowengine',
|
2016-09-02 13:53:44 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($enabled, $this->manager->getEnabledAppsForUser($user));
|
2015-02-02 16:47:29 +03:00
|
|
|
}
|
2015-07-07 13:12:54 +03:00
|
|
|
|
|
|
|
public function testGetAppsNeedingUpgrade() {
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2017-03-20 12:21:08 +03:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
2019-09-05 13:55:24 +03:00
|
|
|
->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger])
|
2015-07-07 13:12:54 +03:00
|
|
|
->setMethods(['getAppInfo'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$appInfos = [
|
2018-06-29 11:46:09 +03:00
|
|
|
'cloud_federation_api' => ['id' => 'cloud_federation_api'],
|
2015-11-23 15:13:26 +03:00
|
|
|
'dav' => ['id' => 'dav'],
|
|
|
|
'files' => ['id' => 'files'],
|
2016-02-04 14:07:25 +03:00
|
|
|
'federatedfilesharing' => ['id' => 'federatedfilesharing'],
|
2016-09-19 20:43:47 +03:00
|
|
|
'provisioning_api' => ['id' => 'provisioning_api'],
|
2016-11-17 14:14:13 +03:00
|
|
|
'lookup_server_connector' => ['id' => 'lookup_server_connector'],
|
2015-08-20 12:14:30 +03:00
|
|
|
'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '9.0.0'],
|
2015-07-07 13:12:54 +03:00
|
|
|
'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'],
|
|
|
|
'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'],
|
2015-08-20 12:14:30 +03:00
|
|
|
'test4' => ['id' => 'test4', 'version' => '3.0.0', 'requiremin' => '8.1.0'],
|
2015-07-07 13:12:54 +03:00
|
|
|
'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'],
|
2019-09-17 17:33:27 +03:00
|
|
|
'settings' => ['id' => 'settings'],
|
2016-09-02 13:53:44 +03:00
|
|
|
'twofactor_backupcodes' => ['id' => 'twofactor_backupcodes'],
|
2019-12-10 17:08:19 +03:00
|
|
|
'viewer' => ['id' => 'viewer'],
|
2016-07-26 12:16:34 +03:00
|
|
|
'workflowengine' => ['id' => 'workflowengine'],
|
2017-05-20 21:58:36 +03:00
|
|
|
'oauth2' => ['id' => 'oauth2'],
|
2015-07-07 13:12:54 +03:00
|
|
|
];
|
|
|
|
|
2017-03-20 12:21:08 +03:00
|
|
|
$manager->expects($this->any())
|
2015-07-07 13:12:54 +03:00
|
|
|
->method('getAppInfo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(
|
2015-07-07 13:12:54 +03:00
|
|
|
function($appId) use ($appInfos) {
|
|
|
|
return $appInfos[$appId];
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
);
|
2015-07-07 13:12:54 +03:00
|
|
|
|
|
|
|
$this->appConfig->setValue('test1', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test1', 'installed_version', '1.0.0');
|
|
|
|
$this->appConfig->setValue('test2', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test2', 'installed_version', '1.0.0');
|
|
|
|
$this->appConfig->setValue('test3', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test3', 'installed_version', '1.0.0');
|
2015-08-20 12:14:30 +03:00
|
|
|
$this->appConfig->setValue('test4', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test4', 'installed_version', '2.4.0');
|
2015-07-07 13:12:54 +03:00
|
|
|
|
2017-03-20 12:21:08 +03:00
|
|
|
$apps = $manager->getAppsNeedingUpgrade('8.2.0');
|
2015-07-07 13:12:54 +03:00
|
|
|
|
|
|
|
$this->assertCount(2, $apps);
|
|
|
|
$this->assertEquals('test1', $apps[0]['id']);
|
2015-08-20 12:14:30 +03:00
|
|
|
$this->assertEquals('test4', $apps[1]['id']);
|
2015-07-07 13:12:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIncompatibleApps() {
|
2019-09-05 13:55:24 +03:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2017-03-20 12:21:08 +03:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
2019-09-05 13:55:24 +03:00
|
|
|
->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger])
|
2015-07-07 13:12:54 +03:00
|
|
|
->setMethods(['getAppInfo'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$appInfos = [
|
2018-06-29 11:46:09 +03:00
|
|
|
'cloud_federation_api' => ['id' => 'cloud_federation_api'],
|
2015-11-23 15:13:26 +03:00
|
|
|
'dav' => ['id' => 'dav'],
|
|
|
|
'files' => ['id' => 'files'],
|
2016-02-04 14:07:25 +03:00
|
|
|
'federatedfilesharing' => ['id' => 'federatedfilesharing'],
|
2016-09-19 20:43:47 +03:00
|
|
|
'provisioning_api' => ['id' => 'provisioning_api'],
|
2016-11-17 14:14:13 +03:00
|
|
|
'lookup_server_connector' => ['id' => 'lookup_server_connector'],
|
2015-07-07 13:12:54 +03:00
|
|
|
'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '8.0.0'],
|
|
|
|
'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'],
|
|
|
|
'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'],
|
2019-09-17 17:33:27 +03:00
|
|
|
'settings' => ['id' => 'settings'],
|
2015-07-07 13:12:54 +03:00
|
|
|
'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'],
|
2016-09-02 13:53:44 +03:00
|
|
|
'twofactor_backupcodes' => ['id' => 'twofactor_backupcodes'],
|
2016-07-26 12:16:34 +03:00
|
|
|
'workflowengine' => ['id' => 'workflowengine'],
|
2017-05-20 21:58:36 +03:00
|
|
|
'oauth2' => ['id' => 'oauth2'],
|
2019-12-10 17:08:19 +03:00
|
|
|
'viewer' => ['id' => 'viewer'],
|
2015-07-07 13:12:54 +03:00
|
|
|
];
|
|
|
|
|
2017-03-20 12:21:08 +03:00
|
|
|
$manager->expects($this->any())
|
2015-07-07 13:12:54 +03:00
|
|
|
->method('getAppInfo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(
|
2015-07-07 13:12:54 +03:00
|
|
|
function($appId) use ($appInfos) {
|
|
|
|
return $appInfos[$appId];
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
);
|
2015-07-07 13:12:54 +03:00
|
|
|
|
|
|
|
$this->appConfig->setValue('test1', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test2', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test3', 'enabled', 'yes');
|
|
|
|
|
2017-03-20 12:21:08 +03:00
|
|
|
$apps = $manager->getIncompatibleApps('8.2.0');
|
2015-07-07 13:12:54 +03:00
|
|
|
|
|
|
|
$this->assertCount(2, $apps);
|
|
|
|
$this->assertEquals('test1', $apps[0]['id']);
|
|
|
|
$this->assertEquals('test3', $apps[1]['id']);
|
|
|
|
}
|
2019-06-25 16:20:06 +03:00
|
|
|
|
|
|
|
public function testGetEnabledAppsForGroup() {
|
|
|
|
$group = $this->createMock(IGroup::class);
|
|
|
|
$group->expects($this->any())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('foo');
|
2019-06-25 16:20:06 +03:00
|
|
|
|
|
|
|
$this->appConfig->setValue('test1', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test2', 'enabled', 'no');
|
|
|
|
$this->appConfig->setValue('test3', 'enabled', '["foo"]');
|
|
|
|
$this->appConfig->setValue('test4', 'enabled', '["asd"]');
|
|
|
|
$enabled = [
|
|
|
|
'cloud_federation_api',
|
|
|
|
'dav',
|
|
|
|
'federatedfilesharing',
|
|
|
|
'files',
|
|
|
|
'lookup_server_connector',
|
|
|
|
'oauth2',
|
|
|
|
'provisioning_api',
|
2019-09-17 17:33:27 +03:00
|
|
|
'settings',
|
2019-06-25 16:20:06 +03:00
|
|
|
'test1',
|
|
|
|
'test3',
|
|
|
|
'twofactor_backupcodes',
|
2019-12-10 17:08:19 +03:00
|
|
|
'viewer',
|
2019-06-25 16:20:06 +03:00
|
|
|
'workflowengine',
|
|
|
|
];
|
|
|
|
$this->assertEquals($enabled, $this->manager->getEnabledAppsForGroup($group));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAppRestriction() {
|
|
|
|
$this->appConfig->setValue('test1', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test2', 'enabled', 'no');
|
|
|
|
$this->appConfig->setValue('test3', 'enabled', '["foo"]');
|
|
|
|
|
|
|
|
$this->assertEquals([], $this->manager->getAppRestriction('test1'));
|
|
|
|
$this->assertEquals([], $this->manager->getAppRestriction('test2'));
|
|
|
|
$this->assertEquals(['foo'], $this->manager->getAppRestriction('test3'));
|
|
|
|
}
|
2014-11-07 16:26:12 +03:00
|
|
|
}
|