2020-04-09 11:50:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2014-11-07 14:26:12 +01:00
|
|
|
|
|
|
|
/**
|
2024-05-10 15:09:14 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2014-11-07 14:26:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\App;
|
|
|
|
|
2017-03-20 10:21:08 +01:00
|
|
|
use OC\App\AppManager;
|
2018-01-17 21:10:40 +01:00
|
|
|
use OC\AppConfig;
|
2016-11-17 12:30:52 +01:00
|
|
|
use OCP\App\AppPathNotFoundException;
|
2022-12-08 10:55:19 +01:00
|
|
|
use OCP\App\Events\AppDisableEvent;
|
|
|
|
use OCP\App\Events\AppEnableEvent;
|
2017-03-20 10:21:08 +01:00
|
|
|
use OCP\App\IAppManager;
|
2022-12-08 10:55:19 +01:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2017-03-20 10:21:08 +01:00
|
|
|
use OCP\ICache;
|
|
|
|
use OCP\ICacheFactory;
|
2019-11-22 20:52:10 +01:00
|
|
|
use OCP\IConfig;
|
2019-02-22 13:07:26 +01:00
|
|
|
use OCP\IGroup;
|
2017-03-20 10:21:08 +01:00
|
|
|
use OCP\IGroupManager;
|
2024-03-06 11:13:29 +01:00
|
|
|
use OCP\IURLGenerator;
|
2019-02-22 13:07:26 +01:00
|
|
|
use OCP\IUser;
|
2017-03-20 10:21:08 +01:00
|
|
|
use OCP\IUserSession;
|
2025-01-24 12:52:33 +01:00
|
|
|
use OCP\ServerVersion;
|
2019-09-05 12:55:24 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2021-04-19 14:06:34 +02:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-12-17 17:29:17 +01:00
|
|
|
use Test\TestCase;
|
2014-11-07 14:26:12 +01:00
|
|
|
|
2016-01-14 15:23:07 +01:00
|
|
|
/**
|
2017-03-20 10:21:08 +01:00
|
|
|
* Class AppManagerTest
|
2016-01-14 15:23:07 +01:00
|
|
|
*
|
|
|
|
* @package Test\App
|
|
|
|
*/
|
2017-03-20 10:21:08 +01:00
|
|
|
class AppManagerTest extends TestCase {
|
2014-11-07 14:26:12 +01:00
|
|
|
/**
|
2019-09-05 12:55:24 +02:00
|
|
|
* @return AppConfig|MockObject
|
2014-11-07 14:26:12 +01:00
|
|
|
*/
|
|
|
|
protected function getAppConfig() {
|
2020-03-26 09:30:18 +01:00
|
|
|
$appConfig = [];
|
2018-01-17 21:10:40 +01:00
|
|
|
$config = $this->createMock(AppConfig::class);
|
2014-11-07 14:26:12 +01:00
|
|
|
|
|
|
|
$config->expects($this->any())
|
|
|
|
->method('getValue')
|
2020-03-25 22:21:27 +01:00
|
|
|
->willReturnCallback(function ($app, $key, $default) use (&$appConfig) {
|
2014-11-07 14:26:12 +01:00
|
|
|
return (isset($appConfig[$app]) and isset($appConfig[$app][$key])) ? $appConfig[$app][$key] : $default;
|
2020-03-25 22:21:27 +01:00
|
|
|
});
|
2014-11-07 14:26:12 +01:00
|
|
|
$config->expects($this->any())
|
|
|
|
->method('setValue')
|
2020-03-25 22:21:27 +01:00
|
|
|
->willReturnCallback(function ($app, $key, $value) use (&$appConfig) {
|
2014-11-07 14:26:12 +01:00
|
|
|
if (!isset($appConfig[$app])) {
|
2020-03-26 09:30:18 +01:00
|
|
|
$appConfig[$app] = [];
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
$appConfig[$app][$key] = $value;
|
2020-03-25 22:21:27 +01:00
|
|
|
});
|
2014-11-07 14:26:12 +01:00
|
|
|
$config->expects($this->any())
|
|
|
|
->method('getValues')
|
2020-03-25 22:21:27 +01:00
|
|
|
->willReturnCallback(function ($app, $key) use (&$appConfig) {
|
2014-11-07 14:26:12 +01:00
|
|
|
if ($app) {
|
|
|
|
return $appConfig[$app];
|
|
|
|
} else {
|
2020-03-26 09:30:18 +01:00
|
|
|
$values = [];
|
2017-03-20 10:21:08 +01:00
|
|
|
foreach ($appConfig as $appid => $appData) {
|
2014-11-07 14:26:12 +01:00
|
|
|
if (isset($appData[$key])) {
|
2017-03-20 10:21:08 +01:00
|
|
|
$values[$appid] = $appData[$key];
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $values;
|
|
|
|
}
|
2020-03-25 22:21:27 +01:00
|
|
|
});
|
2014-11-07 14:26:12 +01:00
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var IUserSession|MockObject */
|
2015-04-01 17:19:44 +02:00
|
|
|
protected $userSession;
|
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var IConfig|MockObject */
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
/** @var IGroupManager|MockObject */
|
2015-04-01 17:19:44 +02:00
|
|
|
protected $groupManager;
|
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var AppConfig|MockObject */
|
2015-04-01 17:19:44 +02:00
|
|
|
protected $appConfig;
|
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var ICache|MockObject */
|
2015-04-01 17:19:44 +02:00
|
|
|
protected $cache;
|
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var ICacheFactory|MockObject */
|
2015-04-01 17:19:44 +02:00
|
|
|
protected $cacheFactory;
|
|
|
|
|
2022-12-08 10:55:19 +01:00
|
|
|
/** @var IEventDispatcher|MockObject */
|
2016-02-09 02:51:12 +01:00
|
|
|
protected $eventDispatcher;
|
|
|
|
|
2021-04-19 14:06:34 +02:00
|
|
|
/** @var LoggerInterface|MockObject */
|
2019-07-15 22:19:11 +02:00
|
|
|
protected $logger;
|
|
|
|
|
2024-04-22 15:50:06 +02:00
|
|
|
protected IURLGenerator&MockObject $urlGenerator;
|
2024-03-06 11:13:29 +01:00
|
|
|
|
2025-01-24 12:52:33 +01:00
|
|
|
protected ServerVersion&MockObject $serverVersion;
|
|
|
|
|
2017-03-20 10:21:08 +01:00
|
|
|
/** @var IAppManager */
|
|
|
|
protected $manager;
|
|
|
|
|
2019-11-21 16:40:38 +01:00
|
|
|
protected function setUp(): void {
|
2015-04-01 17:19:44 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-03-20 11:14:14 +01:00
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2019-09-05 12:55:24 +02:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig = $this->getAppConfig();
|
2017-03-20 11:14:14 +01:00
|
|
|
$this->cacheFactory = $this->createMock(ICacheFactory::class);
|
|
|
|
$this->cache = $this->createMock(ICache::class);
|
2022-12-08 10:55:19 +01:00
|
|
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
2021-04-19 14:06:34 +02:00
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
2024-03-06 11:13:29 +01:00
|
|
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
2025-01-24 12:52:33 +01:00
|
|
|
$this->serverVersion = $this->createMock(ServerVersion::class);
|
2024-03-06 18:19:24 +01:00
|
|
|
|
|
|
|
$this->overwriteService(AppConfig::class, $this->appConfig);
|
2024-04-22 15:50:06 +02:00
|
|
|
$this->overwriteService(IURLGenerator::class, $this->urlGenerator);
|
2024-03-06 18:19:24 +01:00
|
|
|
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->cacheFactory->expects($this->any())
|
2017-12-18 21:06:52 +01:00
|
|
|
->method('createDistributed')
|
2015-04-01 17:19:44 +02:00
|
|
|
->with('settings')
|
|
|
|
->willReturn($this->cache);
|
2024-03-06 18:19:24 +01:00
|
|
|
|
|
|
|
$this->config
|
|
|
|
->method('getSystemValueBool')
|
|
|
|
->with('installed', false)
|
|
|
|
->willReturn(true);
|
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
$this->manager = new AppManager(
|
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
2024-03-06 11:13:29 +01:00
|
|
|
$this->logger,
|
2025-01-24 12:52:33 +01:00
|
|
|
$this->serverVersion,
|
2019-09-05 12:55:24 +02:00
|
|
|
);
|
2015-04-01 17:19:44 +02:00
|
|
|
}
|
|
|
|
|
2024-03-06 11:13:29 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider dataGetAppIcon
|
|
|
|
*/
|
2024-03-08 01:05:24 +01:00
|
|
|
public function testGetAppIcon($callback, ?bool $dark, ?string $expected): void {
|
2024-03-06 11:13:29 +01:00
|
|
|
$this->urlGenerator->expects($this->atLeastOnce())
|
|
|
|
->method('imagePath')
|
|
|
|
->willReturnCallback($callback);
|
|
|
|
|
2024-03-08 01:05:24 +01:00
|
|
|
if ($dark !== null) {
|
|
|
|
$this->assertEquals($expected, $this->manager->getAppIcon('test', $dark));
|
|
|
|
} else {
|
|
|
|
$this->assertEquals($expected, $this->manager->getAppIcon('test'));
|
|
|
|
}
|
2024-03-06 11:13:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function dataGetAppIcon(): array {
|
|
|
|
$nothing = function ($appId) {
|
|
|
|
$this->assertEquals('test', $appId);
|
|
|
|
throw new \RuntimeException();
|
|
|
|
};
|
|
|
|
|
|
|
|
$createCallback = function ($workingIcons) {
|
|
|
|
return function ($appId, $icon) use ($workingIcons) {
|
|
|
|
$this->assertEquals('test', $appId);
|
|
|
|
if (in_array($icon, $workingIcons)) {
|
|
|
|
return '/path/' . $icon;
|
|
|
|
}
|
|
|
|
throw new \RuntimeException();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return [
|
|
|
|
'does not find anything' => [
|
|
|
|
$nothing,
|
2024-03-08 01:05:24 +01:00
|
|
|
false,
|
|
|
|
null,
|
|
|
|
],
|
|
|
|
'nothing if request dark but only bright available' => [
|
|
|
|
$createCallback(['app.svg']),
|
|
|
|
true,
|
|
|
|
null,
|
|
|
|
],
|
|
|
|
'nothing if request bright but only dark available' => [
|
|
|
|
$createCallback(['app-dark.svg']),
|
|
|
|
false,
|
2024-03-06 11:13:29 +01:00
|
|
|
null,
|
|
|
|
],
|
2024-03-08 01:05:24 +01:00
|
|
|
'bright and only app.svg' => [
|
2024-03-06 11:13:29 +01:00
|
|
|
$createCallback(['app.svg']),
|
2024-03-08 01:05:24 +01:00
|
|
|
false,
|
2024-03-06 11:13:29 +01:00
|
|
|
'/path/app.svg',
|
|
|
|
],
|
2024-03-08 01:05:24 +01:00
|
|
|
'dark and only app-dark.svg' => [
|
2024-03-06 11:13:29 +01:00
|
|
|
$createCallback(['app-dark.svg']),
|
2024-03-08 01:05:24 +01:00
|
|
|
true,
|
2024-03-06 11:13:29 +01:00
|
|
|
'/path/app-dark.svg',
|
|
|
|
],
|
2024-03-08 01:05:24 +01:00
|
|
|
'dark only appname -dark.svg' => [
|
2024-03-06 11:13:29 +01:00
|
|
|
$createCallback(['test-dark.svg']),
|
2024-03-08 01:05:24 +01:00
|
|
|
true,
|
2024-03-06 11:13:29 +01:00
|
|
|
'/path/test-dark.svg',
|
|
|
|
],
|
2024-03-08 01:05:24 +01:00
|
|
|
'bright and only appname.svg' => [
|
2024-03-06 11:13:29 +01:00
|
|
|
$createCallback(['test.svg']),
|
2024-03-08 01:05:24 +01:00
|
|
|
false,
|
2024-03-06 11:13:29 +01:00
|
|
|
'/path/test.svg',
|
|
|
|
],
|
|
|
|
'priotize custom over default' => [
|
|
|
|
$createCallback(['app.svg', 'test.svg']),
|
2024-03-08 01:05:24 +01:00
|
|
|
false,
|
2024-03-06 11:13:29 +01:00
|
|
|
'/path/test.svg',
|
|
|
|
],
|
2024-03-08 01:05:24 +01:00
|
|
|
'defaults to bright' => [
|
|
|
|
$createCallback(['test-dark.svg', 'test.svg']),
|
|
|
|
null,
|
|
|
|
'/path/test.svg',
|
2024-03-06 11:13:29 +01:00
|
|
|
],
|
2024-03-08 01:05:24 +01:00
|
|
|
'no dark icon on default' => [
|
|
|
|
$createCallback(['test-dark.svg', 'test.svg', 'app-dark.svg', 'app.svg']),
|
|
|
|
false,
|
2024-03-06 11:13:29 +01:00
|
|
|
'/path/test.svg',
|
|
|
|
],
|
2024-03-08 01:05:24 +01:00
|
|
|
'no bright icon on dark' => [
|
|
|
|
$createCallback(['test-dark.svg', 'test.svg', 'app-dark.svg', 'app.svg']),
|
|
|
|
true,
|
|
|
|
'/path/test-dark.svg',
|
|
|
|
],
|
2024-03-06 11:13:29 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2014-11-07 14:26:12 +01:00
|
|
|
public function testEnableApp(): void {
|
2017-03-08 15:43:47 +05:30
|
|
|
// making sure "files_trashbin" is disabled
|
|
|
|
if ($this->manager->isEnabledForUser('files_trashbin')) {
|
|
|
|
$this->manager->disableApp('files_trashbin');
|
|
|
|
}
|
2022-12-08 10:55:19 +01:00
|
|
|
$this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('files_trashbin'));
|
2017-03-08 15:43:47 +05:30
|
|
|
$this->manager->enableApp('files_trashbin');
|
|
|
|
$this->assertEquals('yes', $this->appConfig->getValue('files_trashbin', 'enabled', 'no'));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisableApp(): void {
|
2022-12-08 10:55:19 +01:00
|
|
|
$this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppDisableEvent('files_trashbin'));
|
2017-03-08 15:43:47 +05:30
|
|
|
$this->manager->disableApp('files_trashbin');
|
|
|
|
$this->assertEquals('no', $this->appConfig->getValue('files_trashbin', 'enabled', 'no'));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 15:43:47 +05:30
|
|
|
public function testNotEnableIfNotInstalled(): void {
|
2017-03-20 02:47:32 -06: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 10:02:05 +01: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 02:47:32 -06:00
|
|
|
}
|
2017-03-20 10:02:05 +01:00
|
|
|
|
2017-03-08 15:43:47 +05:30
|
|
|
$this->assertEquals('no', $this->appConfig->getValue(
|
|
|
|
'some_random_name_which_i_hope_is_not_an_app', 'enabled', 'no'
|
|
|
|
));
|
2017-05-20 20:58:36 +02:00
|
|
|
}
|
2017-03-08 15:43:47 +05:30
|
|
|
|
2014-11-07 14:26:12 +01:00
|
|
|
public function testEnableAppForGroups(): void {
|
2019-02-22 13:07:26 +01:00
|
|
|
$group1 = $this->createMock(IGroup::class);
|
|
|
|
$group1->method('getGID')
|
|
|
|
->willReturn('group1');
|
|
|
|
$group2 = $this->createMock(IGroup::class);
|
|
|
|
$group2->method('getGID')
|
|
|
|
->willReturn('group2');
|
|
|
|
|
|
|
|
$groups = [$group1, $group2];
|
2019-01-26 22:31:45 +01:00
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2019-01-26 22:31:45 +01:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
|
|
|
->setConstructorArgs([
|
2024-03-06 11:13:29 +01:00
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger,
|
2025-01-24 12:52:33 +01:00
|
|
|
$this->serverVersion,
|
2019-01-26 22:31:45 +01:00
|
|
|
])
|
2024-03-06 11:13:29 +01:00
|
|
|
->onlyMethods([
|
2019-01-26 22:31:45 +01:00
|
|
|
'getAppPath',
|
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$manager->expects($this->exactly(2))
|
|
|
|
->method('getAppPath')
|
|
|
|
->with('test')
|
|
|
|
->willReturn('apps/test');
|
|
|
|
|
2022-12-08 10:55:19 +01:00
|
|
|
$this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2']));
|
|
|
|
|
2019-01-26 22:31:45 +01:00
|
|
|
$manager->enableAppForGroups('test', $groups);
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no'));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
2016-01-14 15:23:07 +01:00
|
|
|
public function dataEnableAppForGroupsAllowedTypes() {
|
|
|
|
return [
|
|
|
|
[[]],
|
|
|
|
[[
|
|
|
|
'types' => [],
|
|
|
|
]],
|
|
|
|
[[
|
|
|
|
'types' => ['nickvergessen'],
|
|
|
|
]],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataEnableAppForGroupsAllowedTypes
|
|
|
|
*
|
|
|
|
* @param array $appInfo
|
|
|
|
*/
|
|
|
|
public function testEnableAppForGroupsAllowedTypes(array $appInfo): void {
|
2019-02-22 13:07:26 +01: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 15:23:07 +01:00
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2017-03-20 10:21:08 +01:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
2016-01-14 15:23:07 +01:00
|
|
|
->setConstructorArgs([
|
2024-03-06 11:13:29 +01:00
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger,
|
2025-01-24 12:52:33 +01:00
|
|
|
$this->serverVersion,
|
2016-01-14 15:23:07 +01:00
|
|
|
])
|
2024-03-06 11:13:29 +01:00
|
|
|
->onlyMethods([
|
2019-01-26 22:31:45 +01:00
|
|
|
'getAppPath',
|
|
|
|
'getAppInfo',
|
2016-01-14 15:23:07 +01:00
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
2019-01-26 22:31:45 +01:00
|
|
|
$manager->expects($this->once())
|
|
|
|
->method('getAppPath')
|
|
|
|
->with('test')
|
2024-09-12 16:17:19 +02:00
|
|
|
->willReturn('');
|
2019-01-26 22:31:45 +01:00
|
|
|
|
2016-01-14 15:23:07 +01:00
|
|
|
$manager->expects($this->once())
|
|
|
|
->method('getAppInfo')
|
|
|
|
->with('test')
|
|
|
|
->willReturn($appInfo);
|
|
|
|
|
2022-12-08 10:55:19 +01:00
|
|
|
$this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2']));
|
|
|
|
|
2016-01-14 15:23:07 +01:00
|
|
|
$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): void {
|
2019-11-27 15:27:18 +01:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('test can\'t be enabled for groups.');
|
|
|
|
|
2019-02-22 13:07:26 +01: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 15:23:07 +01:00
|
|
|
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2017-03-20 10:21:08 +01:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
2016-01-14 15:23:07 +01:00
|
|
|
->setConstructorArgs([
|
2024-03-06 11:13:29 +01:00
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger,
|
2025-01-24 12:52:33 +01:00
|
|
|
$this->serverVersion,
|
2016-01-14 15:23:07 +01:00
|
|
|
])
|
2024-03-06 11:13:29 +01:00
|
|
|
->onlyMethods([
|
2019-01-26 22:31:45 +01:00
|
|
|
'getAppPath',
|
|
|
|
'getAppInfo',
|
2016-01-14 15:23:07 +01:00
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
2019-01-26 22:31:45 +01:00
|
|
|
$manager->expects($this->once())
|
|
|
|
->method('getAppPath')
|
|
|
|
->with('test')
|
2024-09-12 16:17:19 +02:00
|
|
|
->willReturn('');
|
2019-01-26 22:31:45 +01:00
|
|
|
|
2016-01-14 15:23:07 +01:00
|
|
|
$manager->expects($this->once())
|
|
|
|
->method('getAppInfo')
|
|
|
|
->with('test')
|
|
|
|
->willReturn([
|
|
|
|
'types' => [$type],
|
|
|
|
]);
|
|
|
|
|
2022-12-08 10:55:19 +01:00
|
|
|
$this->eventDispatcher->expects($this->never())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2']));
|
|
|
|
|
2016-01-14 15:23:07 +01:00
|
|
|
$manager->enableAppForGroups('test', $groups);
|
|
|
|
}
|
|
|
|
|
2014-11-07 14:26:12 +01:00
|
|
|
public function testIsInstalledEnabled(): void {
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', 'yes');
|
2025-02-10 11:25:50 +01:00
|
|
|
$this->assertTrue($this->manager->isEnabledForAnyone('test'));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsInstalledDisabled(): void {
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', 'no');
|
2025-02-10 11:25:50 +01:00
|
|
|
$this->assertFalse($this->manager->isEnabledForAnyone('test'));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsInstalledEnabledForGroups(): void {
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
2025-02-10 11:25:50 +01:00
|
|
|
$this->assertTrue($this->manager->isEnabledForAnyone('test'));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
2016-07-14 13:49:18 +02:00
|
|
|
private function newUser($uid) {
|
2019-02-22 13:07:26 +01:00
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
$user->method('getUID')
|
|
|
|
->willReturn($uid);
|
2016-07-14 13:49:18 +02:00
|
|
|
|
2019-02-22 13:07:26 +01:00
|
|
|
return $user;
|
2016-07-14 13:49:18 +02:00
|
|
|
}
|
|
|
|
|
2014-11-07 14:26:12 +01:00
|
|
|
public function testIsEnabledForUserEnabled(): void {
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', 'yes');
|
2016-07-14 13:49:18 +02:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->assertTrue($this->manager->isEnabledForUser('test', $user));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsEnabledForUserDisabled(): void {
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', 'no');
|
2016-07-14 13:49:18 +02:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->assertFalse($this->manager->isEnabledForUser('test', $user));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
2016-11-17 12:30:52 +01:00
|
|
|
public function testGetAppPath(): void {
|
|
|
|
$this->assertEquals(\OC::$SERVERROOT . '/apps/files', $this->manager->getAppPath('files'));
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:14:36 +01:00
|
|
|
public function testGetAppPathSymlink(): void {
|
|
|
|
$fakeAppDirname = sha1(uniqid('test', true));
|
|
|
|
$fakeAppPath = sys_get_temp_dir() . '/' . $fakeAppDirname;
|
|
|
|
$fakeAppLink = \OC::$SERVERROOT . '/' . $fakeAppDirname;
|
|
|
|
|
|
|
|
mkdir($fakeAppPath);
|
|
|
|
if (symlink($fakeAppPath, $fakeAppLink) === false) {
|
|
|
|
$this->markTestSkipped('Failed to create symlink');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the symlink as the app path
|
|
|
|
\OC::$APPSROOTS[] = [
|
|
|
|
'path' => $fakeAppLink,
|
|
|
|
'url' => \OC::$WEBROOT . '/' . $fakeAppDirname,
|
|
|
|
'writable' => false,
|
|
|
|
];
|
|
|
|
|
|
|
|
$fakeTestAppPath = $fakeAppPath . '/' . 'test-test-app';
|
|
|
|
mkdir($fakeTestAppPath);
|
|
|
|
|
|
|
|
$generatedAppPath = $this->manager->getAppPath('test-test-app');
|
|
|
|
|
|
|
|
rmdir($fakeTestAppPath);
|
|
|
|
unlink($fakeAppLink);
|
|
|
|
rmdir($fakeAppPath);
|
|
|
|
|
|
|
|
$this->assertEquals($fakeAppLink . '/test-test-app', $generatedAppPath);
|
|
|
|
}
|
|
|
|
|
2016-11-17 12:30:52 +01:00
|
|
|
public function testGetAppPathFail(): void {
|
|
|
|
$this->expectException(AppPathNotFoundException::class);
|
|
|
|
$this->manager->getAppPath('testnotexisting');
|
|
|
|
}
|
|
|
|
|
2014-11-07 14:26:12 +01:00
|
|
|
public function testIsEnabledForUserEnabledForGroup(): void {
|
2016-07-14 13:49:18 +02:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-11-07 14:26:12 +01:00
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 09:30:18 +01:00
|
|
|
->willReturn(['foo', 'bar']);
|
2014-11-07 14:26:12 +01:00
|
|
|
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
|
|
|
$this->assertTrue($this->manager->isEnabledForUser('test', $user));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsEnabledForUserDisabledForGroup(): void {
|
2016-07-14 13:49:18 +02:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-11-07 14:26:12 +01:00
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 09:30:18 +01:00
|
|
|
->willReturn(['bar']);
|
2014-11-07 14:26:12 +01:00
|
|
|
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
|
|
|
$this->assertFalse($this->manager->isEnabledForUser('test', $user));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsEnabledForUserLoggedOut(): void {
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
2017-03-20 10:21:08 +01:00
|
|
|
$this->assertFalse($this->manager->isEnabledForUser('test'));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsEnabledForUserLoggedIn(): void {
|
2016-07-14 13:49:18 +02:00
|
|
|
$user = $this->newUser('user1');
|
2014-11-07 14:26:12 +01:00
|
|
|
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->userSession->expects($this->once())
|
2014-11-07 14:26:12 +01:00
|
|
|
->method('getUser')
|
2020-03-25 22:21:27 +01:00
|
|
|
->willReturn($user);
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->groupManager->expects($this->once())
|
2014-11-07 14:26:12 +01:00
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 09:30:18 +01:00
|
|
|
->willReturn(['foo', 'bar']);
|
2014-11-07 14:26:12 +01:00
|
|
|
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]');
|
|
|
|
$this->assertTrue($this->manager->isEnabledForUser('test'));
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|
2015-02-02 14:47:29 +01:00
|
|
|
|
2025-02-10 11:35:38 +01:00
|
|
|
public function testGetEnabledApps(): void {
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->appConfig->setValue('test1', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test2', 'enabled', 'no');
|
|
|
|
$this->appConfig->setValue('test3', 'enabled', '["foo"]');
|
2016-09-19 19:43:47 +02:00
|
|
|
$apps = [
|
2018-06-29 10:46:09 +02:00
|
|
|
'cloud_federation_api',
|
2016-09-19 19:43:47 +02:00
|
|
|
'dav',
|
|
|
|
'federatedfilesharing',
|
|
|
|
'files',
|
2016-11-17 12:14:13 +01:00
|
|
|
'lookup_server_connector',
|
2017-05-20 20:58:36 +02:00
|
|
|
'oauth2',
|
2024-11-13 10:45:01 +01:00
|
|
|
'profile',
|
2016-09-19 19:43:47 +02:00
|
|
|
'provisioning_api',
|
2019-09-17 16:33:27 +02:00
|
|
|
'settings',
|
2016-09-19 19:43:47 +02:00
|
|
|
'test1',
|
|
|
|
'test3',
|
2022-10-14 15:25:02 +02:00
|
|
|
'theming',
|
2016-09-19 19:43:47 +02:00
|
|
|
'twofactor_backupcodes',
|
2019-12-10 15:08:19 +01:00
|
|
|
'viewer',
|
2016-09-19 19:43:47 +02:00
|
|
|
'workflowengine',
|
|
|
|
];
|
2025-02-10 11:35:38 +01:00
|
|
|
$this->assertEquals($apps, $this->manager->getEnabledApps());
|
2015-02-02 14:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAppsForUser(): void {
|
2016-07-14 13:49:18 +02:00
|
|
|
$user = $this->newUser('user1');
|
2015-04-01 17:19:44 +02:00
|
|
|
$this->groupManager->expects($this->any())
|
2015-02-02 14:47:29 +01:00
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($user)
|
2020-03-26 09:30:18 +01:00
|
|
|
->willReturn(['foo', 'bar']);
|
2015-02-02 14:47:29 +01:00
|
|
|
|
2015-04-01 17:19:44 +02: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 12:53:44 +02:00
|
|
|
$enabled = [
|
2018-06-29 10:46:09 +02:00
|
|
|
'cloud_federation_api',
|
2016-09-02 12:53:44 +02:00
|
|
|
'dav',
|
|
|
|
'federatedfilesharing',
|
|
|
|
'files',
|
2016-11-17 12:14:13 +01:00
|
|
|
'lookup_server_connector',
|
2017-05-20 20:58:36 +02:00
|
|
|
'oauth2',
|
2024-11-13 10:45:01 +01:00
|
|
|
'profile',
|
2016-09-19 19:43:47 +02:00
|
|
|
'provisioning_api',
|
2019-09-17 16:33:27 +02:00
|
|
|
'settings',
|
2016-09-02 12:53:44 +02:00
|
|
|
'test1',
|
|
|
|
'test3',
|
2022-10-14 15:25:02 +02:00
|
|
|
'theming',
|
2016-09-02 12:53:44 +02:00
|
|
|
'twofactor_backupcodes',
|
2019-12-10 15:08:19 +01:00
|
|
|
'viewer',
|
2017-05-20 20:58:36 +02:00
|
|
|
'workflowengine',
|
2016-09-02 12:53:44 +02:00
|
|
|
];
|
|
|
|
$this->assertEquals($enabled, $this->manager->getEnabledAppsForUser($user));
|
2015-02-02 14:47:29 +01:00
|
|
|
}
|
2015-07-07 12:12:54 +02:00
|
|
|
|
|
|
|
public function testGetAppsNeedingUpgrade(): void {
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2017-03-20 10:21:08 +01:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
2024-03-06 11:13:29 +01:00
|
|
|
->setConstructorArgs([
|
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger,
|
2025-01-24 12:52:33 +01:00
|
|
|
$this->serverVersion,
|
2024-03-06 11:13:29 +01:00
|
|
|
])
|
|
|
|
->onlyMethods(['getAppInfo'])
|
2015-07-07 12:12:54 +02:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$appInfos = [
|
2018-06-29 10:46:09 +02:00
|
|
|
'cloud_federation_api' => ['id' => 'cloud_federation_api'],
|
2015-11-23 13:13:26 +01:00
|
|
|
'dav' => ['id' => 'dav'],
|
|
|
|
'files' => ['id' => 'files'],
|
2016-02-04 12:07:25 +01:00
|
|
|
'federatedfilesharing' => ['id' => 'federatedfilesharing'],
|
2024-11-13 10:45:01 +01:00
|
|
|
'profile' => ['id' => 'profile'],
|
2016-09-19 19:43:47 +02:00
|
|
|
'provisioning_api' => ['id' => 'provisioning_api'],
|
2016-11-17 12:14:13 +01:00
|
|
|
'lookup_server_connector' => ['id' => 'lookup_server_connector'],
|
2015-08-20 11:14:30 +02:00
|
|
|
'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '9.0.0'],
|
2015-07-07 12:12:54 +02: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 11:14:30 +02:00
|
|
|
'test4' => ['id' => 'test4', 'version' => '3.0.0', 'requiremin' => '8.1.0'],
|
2015-07-07 12:12:54 +02:00
|
|
|
'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'],
|
2019-09-17 16:33:27 +02:00
|
|
|
'settings' => ['id' => 'settings'],
|
2022-10-14 15:25:02 +02:00
|
|
|
'theming' => ['id' => 'theming'],
|
2016-09-02 12:53:44 +02:00
|
|
|
'twofactor_backupcodes' => ['id' => 'twofactor_backupcodes'],
|
2019-12-10 15:08:19 +01:00
|
|
|
'viewer' => ['id' => 'viewer'],
|
2016-07-26 11:16:34 +02:00
|
|
|
'workflowengine' => ['id' => 'workflowengine'],
|
2017-05-20 20:58:36 +02:00
|
|
|
'oauth2' => ['id' => 'oauth2'],
|
2015-07-07 12:12:54 +02:00
|
|
|
];
|
|
|
|
|
2017-03-20 10:21:08 +01:00
|
|
|
$manager->expects($this->any())
|
2015-07-07 12:12:54 +02:00
|
|
|
->method('getAppInfo')
|
2020-03-25 22:21:27 +01:00
|
|
|
->willReturnCallback(
|
2020-04-09 13:53:40 +02:00
|
|
|
function ($appId) use ($appInfos) {
|
2015-07-07 12:12:54 +02:00
|
|
|
return $appInfos[$appId];
|
|
|
|
}
|
2020-03-25 22:21:27 +01:00
|
|
|
);
|
2015-07-07 12:12:54 +02: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 11:14:30 +02:00
|
|
|
$this->appConfig->setValue('test4', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test4', 'installed_version', '2.4.0');
|
2015-07-07 12:12:54 +02:00
|
|
|
|
2017-03-20 10:21:08 +01:00
|
|
|
$apps = $manager->getAppsNeedingUpgrade('8.2.0');
|
2015-07-07 12:12:54 +02:00
|
|
|
|
|
|
|
$this->assertCount(2, $apps);
|
|
|
|
$this->assertEquals('test1', $apps[0]['id']);
|
2015-08-20 11:14:30 +02:00
|
|
|
$this->assertEquals('test4', $apps[1]['id']);
|
2015-07-07 12:12:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIncompatibleApps(): void {
|
2019-09-05 12:55:24 +02:00
|
|
|
/** @var AppManager|MockObject $manager */
|
2017-03-20 10:21:08 +01:00
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
2024-03-06 11:13:29 +01:00
|
|
|
->setConstructorArgs([
|
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger,
|
2025-01-24 12:52:33 +01:00
|
|
|
$this->serverVersion,
|
2024-03-06 11:13:29 +01:00
|
|
|
])
|
|
|
|
->onlyMethods(['getAppInfo'])
|
2015-07-07 12:12:54 +02:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$appInfos = [
|
2018-06-29 10:46:09 +02:00
|
|
|
'cloud_federation_api' => ['id' => 'cloud_federation_api'],
|
2015-11-23 13:13:26 +01:00
|
|
|
'dav' => ['id' => 'dav'],
|
|
|
|
'files' => ['id' => 'files'],
|
2016-02-04 12:07:25 +01:00
|
|
|
'federatedfilesharing' => ['id' => 'federatedfilesharing'],
|
2024-11-13 10:45:01 +01:00
|
|
|
'profile' => ['id' => 'profile'],
|
2016-09-19 19:43:47 +02:00
|
|
|
'provisioning_api' => ['id' => 'provisioning_api'],
|
2016-11-17 12:14:13 +01:00
|
|
|
'lookup_server_connector' => ['id' => 'lookup_server_connector'],
|
2015-07-07 12:12:54 +02: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 16:33:27 +02:00
|
|
|
'settings' => ['id' => 'settings'],
|
2015-07-07 12:12:54 +02:00
|
|
|
'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'],
|
2022-10-14 15:25:02 +02:00
|
|
|
'theming' => ['id' => 'theming'],
|
2016-09-02 12:53:44 +02:00
|
|
|
'twofactor_backupcodes' => ['id' => 'twofactor_backupcodes'],
|
2016-07-26 11:16:34 +02:00
|
|
|
'workflowengine' => ['id' => 'workflowengine'],
|
2017-05-20 20:58:36 +02:00
|
|
|
'oauth2' => ['id' => 'oauth2'],
|
2019-12-10 15:08:19 +01:00
|
|
|
'viewer' => ['id' => 'viewer'],
|
2015-07-07 12:12:54 +02:00
|
|
|
];
|
|
|
|
|
2017-03-20 10:21:08 +01:00
|
|
|
$manager->expects($this->any())
|
2015-07-07 12:12:54 +02:00
|
|
|
->method('getAppInfo')
|
2020-03-25 22:21:27 +01:00
|
|
|
->willReturnCallback(
|
2020-04-09 13:53:40 +02:00
|
|
|
function ($appId) use ($appInfos) {
|
2015-07-07 12:12:54 +02:00
|
|
|
return $appInfos[$appId];
|
|
|
|
}
|
2020-03-25 22:21:27 +01:00
|
|
|
);
|
2015-07-07 12:12:54 +02:00
|
|
|
|
|
|
|
$this->appConfig->setValue('test1', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test2', 'enabled', 'yes');
|
|
|
|
$this->appConfig->setValue('test3', 'enabled', 'yes');
|
|
|
|
|
2017-03-20 10:21:08 +01:00
|
|
|
$apps = $manager->getIncompatibleApps('8.2.0');
|
2015-07-07 12:12:54 +02:00
|
|
|
|
|
|
|
$this->assertCount(2, $apps);
|
|
|
|
$this->assertEquals('test1', $apps[0]['id']);
|
|
|
|
$this->assertEquals('test3', $apps[1]['id']);
|
|
|
|
}
|
2019-06-25 15:20:06 +02:00
|
|
|
|
|
|
|
public function testGetEnabledAppsForGroup(): void {
|
|
|
|
$group = $this->createMock(IGroup::class);
|
|
|
|
$group->expects($this->any())
|
|
|
|
->method('getGID')
|
2020-03-25 22:21:27 +01:00
|
|
|
->willReturn('foo');
|
2019-06-25 15:20:06 +02: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',
|
2024-11-13 10:45:01 +01:00
|
|
|
'profile',
|
2019-06-25 15:20:06 +02:00
|
|
|
'provisioning_api',
|
2019-09-17 16:33:27 +02:00
|
|
|
'settings',
|
2019-06-25 15:20:06 +02:00
|
|
|
'test1',
|
|
|
|
'test3',
|
2022-10-14 15:25:02 +02:00
|
|
|
'theming',
|
2019-06-25 15:20:06 +02:00
|
|
|
'twofactor_backupcodes',
|
2019-12-10 15:08:19 +01:00
|
|
|
'viewer',
|
2019-06-25 15:20:06 +02:00
|
|
|
'workflowengine',
|
|
|
|
];
|
|
|
|
$this->assertEquals($enabled, $this->manager->getEnabledAppsForGroup($group));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAppRestriction(): void {
|
|
|
|
$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'));
|
|
|
|
}
|
2023-03-29 13:36:45 -07:00
|
|
|
|
2024-07-13 16:51:16 +02:00
|
|
|
public static function isBackendRequiredDataProvider(): array {
|
|
|
|
return [
|
|
|
|
// backend available
|
|
|
|
[
|
|
|
|
'caldav',
|
|
|
|
['app1' => ['caldav']],
|
|
|
|
true,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'caldav',
|
|
|
|
['app1' => [], 'app2' => ['foo'], 'app3' => ['caldav']],
|
|
|
|
true,
|
|
|
|
],
|
|
|
|
// backend not available
|
|
|
|
[
|
|
|
|
'caldav',
|
|
|
|
['app3' => [], 'app1' => ['foo'], 'app2' => ['bar', 'baz']],
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
// no app available
|
|
|
|
[
|
|
|
|
'caldav',
|
|
|
|
[],
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider isBackendRequiredDataProvider
|
|
|
|
*/
|
|
|
|
public function testIsBackendRequired(
|
|
|
|
string $backend,
|
|
|
|
array $appBackends,
|
|
|
|
bool $expected,
|
|
|
|
): void {
|
|
|
|
$appInfoData = array_map(
|
|
|
|
static fn (array $backends) => ['dependencies' => ['backend' => $backends]],
|
|
|
|
$appBackends,
|
|
|
|
);
|
|
|
|
|
|
|
|
$reflection = new \ReflectionClass($this->manager);
|
|
|
|
$property = $reflection->getProperty('appInfos');
|
|
|
|
$property->setValue($this->manager, $appInfoData);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->manager->isBackendRequired($backend));
|
|
|
|
}
|
2025-01-24 12:52:33 +01:00
|
|
|
|
|
|
|
public function testGetAppVersion() {
|
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
|
|
|
->setConstructorArgs([
|
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger,
|
|
|
|
$this->serverVersion,
|
|
|
|
])
|
|
|
|
->onlyMethods([
|
|
|
|
'getAppInfo',
|
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$manager->expects(self::once())
|
|
|
|
->method('getAppInfo')
|
|
|
|
->with('myapp')
|
|
|
|
->willReturn(['version' => '99.99.99-rc.99']);
|
|
|
|
|
|
|
|
$this->serverVersion
|
|
|
|
->expects(self::never())
|
|
|
|
->method('getVersionString');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'99.99.99-rc.99',
|
|
|
|
$manager->getAppVersion('myapp'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAppVersionCore() {
|
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
|
|
|
->setConstructorArgs([
|
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger,
|
|
|
|
$this->serverVersion,
|
|
|
|
])
|
|
|
|
->onlyMethods([
|
|
|
|
'getAppInfo',
|
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$manager->expects(self::never())
|
|
|
|
->method('getAppInfo');
|
|
|
|
|
|
|
|
$this->serverVersion
|
|
|
|
->expects(self::once())
|
|
|
|
->method('getVersionString')
|
|
|
|
->willReturn('1.2.3-beta.4');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'1.2.3-beta.4',
|
|
|
|
$manager->getAppVersion('core'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAppVersionUnknown() {
|
|
|
|
$manager = $this->getMockBuilder(AppManager::class)
|
|
|
|
->setConstructorArgs([
|
|
|
|
$this->userSession,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->cacheFactory,
|
|
|
|
$this->eventDispatcher,
|
|
|
|
$this->logger,
|
|
|
|
$this->serverVersion,
|
|
|
|
])
|
|
|
|
->onlyMethods([
|
|
|
|
'getAppInfo',
|
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$manager->expects(self::once())
|
|
|
|
->method('getAppInfo')
|
|
|
|
->with('unknown')
|
|
|
|
->willReturn(null);
|
|
|
|
|
|
|
|
$this->serverVersion
|
|
|
|
->expects(self::never())
|
|
|
|
->method('getVersionString');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'0',
|
|
|
|
$manager->getAppVersion('unknown'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-11-07 14:26:12 +01:00
|
|
|
}
|