AppManagerTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
  5. * This file is licensed under the Affero General Public License version 3 or
  6. * later.
  7. * See the COPYING-README file.
  8. */
  9. namespace Test\App;
  10. use OC\App\AppManager;
  11. use OC\AppConfig;
  12. use OCP\App\AppPathNotFoundException;
  13. use OCP\App\Events\AppDisableEvent;
  14. use OCP\App\Events\AppEnableEvent;
  15. use OCP\App\IAppManager;
  16. use OCP\EventDispatcher\IEventDispatcher;
  17. use OCP\ICache;
  18. use OCP\ICacheFactory;
  19. use OCP\IConfig;
  20. use OCP\IGroup;
  21. use OCP\IGroupManager;
  22. use OCP\IUser;
  23. use OCP\IUserSession;
  24. use PHPUnit\Framework\MockObject\MockObject;
  25. use Psr\Log\LoggerInterface;
  26. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  27. use Test\TestCase;
  28. /**
  29. * Class AppManagerTest
  30. *
  31. * @package Test\App
  32. */
  33. class AppManagerTest extends TestCase {
  34. /**
  35. * @return AppConfig|MockObject
  36. */
  37. protected function getAppConfig() {
  38. $appConfig = [];
  39. $config = $this->createMock(AppConfig::class);
  40. $config->expects($this->any())
  41. ->method('getValue')
  42. ->willReturnCallback(function ($app, $key, $default) use (&$appConfig) {
  43. return (isset($appConfig[$app]) and isset($appConfig[$app][$key])) ? $appConfig[$app][$key] : $default;
  44. });
  45. $config->expects($this->any())
  46. ->method('setValue')
  47. ->willReturnCallback(function ($app, $key, $value) use (&$appConfig) {
  48. if (!isset($appConfig[$app])) {
  49. $appConfig[$app] = [];
  50. }
  51. $appConfig[$app][$key] = $value;
  52. });
  53. $config->expects($this->any())
  54. ->method('getValues')
  55. ->willReturnCallback(function ($app, $key) use (&$appConfig) {
  56. if ($app) {
  57. return $appConfig[$app];
  58. } else {
  59. $values = [];
  60. foreach ($appConfig as $appid => $appData) {
  61. if (isset($appData[$key])) {
  62. $values[$appid] = $appData[$key];
  63. }
  64. }
  65. return $values;
  66. }
  67. });
  68. return $config;
  69. }
  70. /** @var IUserSession|MockObject */
  71. protected $userSession;
  72. /** @var IConfig|MockObject */
  73. private $config;
  74. /** @var IGroupManager|MockObject */
  75. protected $groupManager;
  76. /** @var AppConfig|MockObject */
  77. protected $appConfig;
  78. /** @var ICache|MockObject */
  79. protected $cache;
  80. /** @var ICacheFactory|MockObject */
  81. protected $cacheFactory;
  82. /** @var EventDispatcherInterface|MockObject */
  83. protected $legacyEventDispatcher;
  84. /** @var IEventDispatcher|MockObject */
  85. protected $eventDispatcher;
  86. /** @var LoggerInterface|MockObject */
  87. protected $logger;
  88. /** @var IAppManager */
  89. protected $manager;
  90. protected function setUp(): void {
  91. parent::setUp();
  92. $this->userSession = $this->createMock(IUserSession::class);
  93. $this->groupManager = $this->createMock(IGroupManager::class);
  94. $this->config = $this->createMock(IConfig::class);
  95. $this->appConfig = $this->getAppConfig();
  96. $this->cacheFactory = $this->createMock(ICacheFactory::class);
  97. $this->cache = $this->createMock(ICache::class);
  98. $this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class);
  99. $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
  100. $this->logger = $this->createMock(LoggerInterface::class);
  101. $this->cacheFactory->expects($this->any())
  102. ->method('createDistributed')
  103. ->with('settings')
  104. ->willReturn($this->cache);
  105. $this->manager = new AppManager(
  106. $this->userSession,
  107. $this->config,
  108. $this->appConfig,
  109. $this->groupManager,
  110. $this->cacheFactory,
  111. $this->legacyEventDispatcher,
  112. $this->eventDispatcher,
  113. $this->logger
  114. );
  115. }
  116. protected function expectClearCache() {
  117. $this->cache->expects($this->once())
  118. ->method('clear')
  119. ->with('listApps');
  120. }
  121. public function testEnableApp() {
  122. $this->expectClearCache();
  123. // making sure "files_trashbin" is disabled
  124. if ($this->manager->isEnabledForUser('files_trashbin')) {
  125. $this->manager->disableApp('files_trashbin');
  126. }
  127. $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('files_trashbin'));
  128. $this->manager->enableApp('files_trashbin');
  129. $this->assertEquals('yes', $this->appConfig->getValue('files_trashbin', 'enabled', 'no'));
  130. }
  131. public function testDisableApp() {
  132. $this->expectClearCache();
  133. $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppDisableEvent('files_trashbin'));
  134. $this->manager->disableApp('files_trashbin');
  135. $this->assertEquals('no', $this->appConfig->getValue('files_trashbin', 'enabled', 'no'));
  136. }
  137. public function testNotEnableIfNotInstalled() {
  138. try {
  139. $this->manager->enableApp('some_random_name_which_i_hope_is_not_an_app');
  140. $this->assertFalse(true, 'If this line is reached the expected exception is not thrown.');
  141. } catch (AppPathNotFoundException $e) {
  142. // Exception is expected
  143. $this->assertEquals('Could not find path for some_random_name_which_i_hope_is_not_an_app', $e->getMessage());
  144. }
  145. $this->assertEquals('no', $this->appConfig->getValue(
  146. 'some_random_name_which_i_hope_is_not_an_app', 'enabled', 'no'
  147. ));
  148. }
  149. public function testEnableAppForGroups() {
  150. $group1 = $this->createMock(IGroup::class);
  151. $group1->method('getGID')
  152. ->willReturn('group1');
  153. $group2 = $this->createMock(IGroup::class);
  154. $group2->method('getGID')
  155. ->willReturn('group2');
  156. $groups = [$group1, $group2];
  157. $this->expectClearCache();
  158. /** @var AppManager|MockObject $manager */
  159. $manager = $this->getMockBuilder(AppManager::class)
  160. ->setConstructorArgs([
  161. $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger
  162. ])
  163. ->setMethods([
  164. 'getAppPath',
  165. ])
  166. ->getMock();
  167. $manager->expects($this->exactly(2))
  168. ->method('getAppPath')
  169. ->with('test')
  170. ->willReturn('apps/test');
  171. $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2']));
  172. $manager->enableAppForGroups('test', $groups);
  173. $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no'));
  174. }
  175. public function dataEnableAppForGroupsAllowedTypes() {
  176. return [
  177. [[]],
  178. [[
  179. 'types' => [],
  180. ]],
  181. [[
  182. 'types' => ['nickvergessen'],
  183. ]],
  184. ];
  185. }
  186. /**
  187. * @dataProvider dataEnableAppForGroupsAllowedTypes
  188. *
  189. * @param array $appInfo
  190. */
  191. public function testEnableAppForGroupsAllowedTypes(array $appInfo) {
  192. $group1 = $this->createMock(IGroup::class);
  193. $group1->method('getGID')
  194. ->willReturn('group1');
  195. $group2 = $this->createMock(IGroup::class);
  196. $group2->method('getGID')
  197. ->willReturn('group2');
  198. $groups = [$group1, $group2];
  199. $this->expectClearCache();
  200. /** @var AppManager|MockObject $manager */
  201. $manager = $this->getMockBuilder(AppManager::class)
  202. ->setConstructorArgs([
  203. $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger
  204. ])
  205. ->setMethods([
  206. 'getAppPath',
  207. 'getAppInfo',
  208. ])
  209. ->getMock();
  210. $manager->expects($this->once())
  211. ->method('getAppPath')
  212. ->with('test')
  213. ->willReturn(null);
  214. $manager->expects($this->once())
  215. ->method('getAppInfo')
  216. ->with('test')
  217. ->willReturn($appInfo);
  218. $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2']));
  219. $manager->enableAppForGroups('test', $groups);
  220. $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no'));
  221. }
  222. public function dataEnableAppForGroupsForbiddenTypes() {
  223. return [
  224. ['filesystem'],
  225. ['prelogin'],
  226. ['authentication'],
  227. ['logging'],
  228. ['prevent_group_restriction'],
  229. ];
  230. }
  231. /**
  232. * @dataProvider dataEnableAppForGroupsForbiddenTypes
  233. *
  234. * @param string $type
  235. *
  236. */
  237. public function testEnableAppForGroupsForbiddenTypes($type) {
  238. $this->expectException(\Exception::class);
  239. $this->expectExceptionMessage('test can\'t be enabled for groups.');
  240. $group1 = $this->createMock(IGroup::class);
  241. $group1->method('getGID')
  242. ->willReturn('group1');
  243. $group2 = $this->createMock(IGroup::class);
  244. $group2->method('getGID')
  245. ->willReturn('group2');
  246. $groups = [$group1, $group2];
  247. /** @var AppManager|MockObject $manager */
  248. $manager = $this->getMockBuilder(AppManager::class)
  249. ->setConstructorArgs([
  250. $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger
  251. ])
  252. ->setMethods([
  253. 'getAppPath',
  254. 'getAppInfo',
  255. ])
  256. ->getMock();
  257. $manager->expects($this->once())
  258. ->method('getAppPath')
  259. ->with('test')
  260. ->willReturn(null);
  261. $manager->expects($this->once())
  262. ->method('getAppInfo')
  263. ->with('test')
  264. ->willReturn([
  265. 'types' => [$type],
  266. ]);
  267. $this->eventDispatcher->expects($this->never())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2']));
  268. $manager->enableAppForGroups('test', $groups);
  269. }
  270. public function testIsInstalledEnabled() {
  271. $this->appConfig->setValue('test', 'enabled', 'yes');
  272. $this->assertTrue($this->manager->isInstalled('test'));
  273. }
  274. public function testIsInstalledDisabled() {
  275. $this->appConfig->setValue('test', 'enabled', 'no');
  276. $this->assertFalse($this->manager->isInstalled('test'));
  277. }
  278. public function testIsInstalledEnabledForGroups() {
  279. $this->appConfig->setValue('test', 'enabled', '["foo"]');
  280. $this->assertTrue($this->manager->isInstalled('test'));
  281. }
  282. private function newUser($uid) {
  283. $user = $this->createMock(IUser::class);
  284. $user->method('getUID')
  285. ->willReturn($uid);
  286. return $user;
  287. }
  288. public function testIsEnabledForUserEnabled() {
  289. $this->appConfig->setValue('test', 'enabled', 'yes');
  290. $user = $this->newUser('user1');
  291. $this->assertTrue($this->manager->isEnabledForUser('test', $user));
  292. }
  293. public function testIsEnabledForUserDisabled() {
  294. $this->appConfig->setValue('test', 'enabled', 'no');
  295. $user = $this->newUser('user1');
  296. $this->assertFalse($this->manager->isEnabledForUser('test', $user));
  297. }
  298. public function testGetAppPath() {
  299. $this->assertEquals(\OC::$SERVERROOT . '/apps/files', $this->manager->getAppPath('files'));
  300. }
  301. public function testGetAppPathSymlink() {
  302. $fakeAppDirname = sha1(uniqid('test', true));
  303. $fakeAppPath = sys_get_temp_dir() . '/' . $fakeAppDirname;
  304. $fakeAppLink = \OC::$SERVERROOT . '/' . $fakeAppDirname;
  305. mkdir($fakeAppPath);
  306. if (symlink($fakeAppPath, $fakeAppLink) === false) {
  307. $this->markTestSkipped('Failed to create symlink');
  308. }
  309. // Use the symlink as the app path
  310. \OC::$APPSROOTS[] = [
  311. 'path' => $fakeAppLink,
  312. 'url' => \OC::$WEBROOT . '/' . $fakeAppDirname,
  313. 'writable' => false,
  314. ];
  315. $fakeTestAppPath = $fakeAppPath . '/' . 'test-test-app';
  316. mkdir($fakeTestAppPath);
  317. $generatedAppPath = $this->manager->getAppPath('test-test-app');
  318. rmdir($fakeTestAppPath);
  319. unlink($fakeAppLink);
  320. rmdir($fakeAppPath);
  321. $this->assertEquals($fakeAppLink . '/test-test-app', $generatedAppPath);
  322. }
  323. public function testGetAppPathFail() {
  324. $this->expectException(AppPathNotFoundException::class);
  325. $this->manager->getAppPath('testnotexisting');
  326. }
  327. public function testIsEnabledForUserEnabledForGroup() {
  328. $user = $this->newUser('user1');
  329. $this->groupManager->expects($this->once())
  330. ->method('getUserGroupIds')
  331. ->with($user)
  332. ->willReturn(['foo', 'bar']);
  333. $this->appConfig->setValue('test', 'enabled', '["foo"]');
  334. $this->assertTrue($this->manager->isEnabledForUser('test', $user));
  335. }
  336. public function testIsEnabledForUserDisabledForGroup() {
  337. $user = $this->newUser('user1');
  338. $this->groupManager->expects($this->once())
  339. ->method('getUserGroupIds')
  340. ->with($user)
  341. ->willReturn(['bar']);
  342. $this->appConfig->setValue('test', 'enabled', '["foo"]');
  343. $this->assertFalse($this->manager->isEnabledForUser('test', $user));
  344. }
  345. public function testIsEnabledForUserLoggedOut() {
  346. $this->appConfig->setValue('test', 'enabled', '["foo"]');
  347. $this->assertFalse($this->manager->isEnabledForUser('test'));
  348. }
  349. public function testIsEnabledForUserLoggedIn() {
  350. $user = $this->newUser('user1');
  351. $this->userSession->expects($this->once())
  352. ->method('getUser')
  353. ->willReturn($user);
  354. $this->groupManager->expects($this->once())
  355. ->method('getUserGroupIds')
  356. ->with($user)
  357. ->willReturn(['foo', 'bar']);
  358. $this->appConfig->setValue('test', 'enabled', '["foo"]');
  359. $this->assertTrue($this->manager->isEnabledForUser('test'));
  360. }
  361. public function testGetInstalledApps() {
  362. $this->appConfig->setValue('test1', 'enabled', 'yes');
  363. $this->appConfig->setValue('test2', 'enabled', 'no');
  364. $this->appConfig->setValue('test3', 'enabled', '["foo"]');
  365. $apps = [
  366. 'cloud_federation_api',
  367. 'dav',
  368. 'federatedfilesharing',
  369. 'files',
  370. 'lookup_server_connector',
  371. 'oauth2',
  372. 'provisioning_api',
  373. 'settings',
  374. 'test1',
  375. 'test3',
  376. 'theming',
  377. 'twofactor_backupcodes',
  378. 'viewer',
  379. 'workflowengine',
  380. ];
  381. $this->assertEquals($apps, $this->manager->getInstalledApps());
  382. }
  383. public function testGetAppsForUser() {
  384. $user = $this->newUser('user1');
  385. $this->groupManager->expects($this->any())
  386. ->method('getUserGroupIds')
  387. ->with($user)
  388. ->willReturn(['foo', 'bar']);
  389. $this->appConfig->setValue('test1', 'enabled', 'yes');
  390. $this->appConfig->setValue('test2', 'enabled', 'no');
  391. $this->appConfig->setValue('test3', 'enabled', '["foo"]');
  392. $this->appConfig->setValue('test4', 'enabled', '["asd"]');
  393. $enabled = [
  394. 'cloud_federation_api',
  395. 'dav',
  396. 'federatedfilesharing',
  397. 'files',
  398. 'lookup_server_connector',
  399. 'oauth2',
  400. 'provisioning_api',
  401. 'settings',
  402. 'test1',
  403. 'test3',
  404. 'theming',
  405. 'twofactor_backupcodes',
  406. 'viewer',
  407. 'workflowengine',
  408. ];
  409. $this->assertEquals($enabled, $this->manager->getEnabledAppsForUser($user));
  410. }
  411. public function testGetAppsNeedingUpgrade() {
  412. /** @var AppManager|MockObject $manager */
  413. $manager = $this->getMockBuilder(AppManager::class)
  414. ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger])
  415. ->setMethods(['getAppInfo'])
  416. ->getMock();
  417. $appInfos = [
  418. 'cloud_federation_api' => ['id' => 'cloud_federation_api'],
  419. 'dav' => ['id' => 'dav'],
  420. 'files' => ['id' => 'files'],
  421. 'federatedfilesharing' => ['id' => 'federatedfilesharing'],
  422. 'provisioning_api' => ['id' => 'provisioning_api'],
  423. 'lookup_server_connector' => ['id' => 'lookup_server_connector'],
  424. 'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '9.0.0'],
  425. 'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'],
  426. 'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'],
  427. 'test4' => ['id' => 'test4', 'version' => '3.0.0', 'requiremin' => '8.1.0'],
  428. 'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'],
  429. 'settings' => ['id' => 'settings'],
  430. 'theming' => ['id' => 'theming'],
  431. 'twofactor_backupcodes' => ['id' => 'twofactor_backupcodes'],
  432. 'viewer' => ['id' => 'viewer'],
  433. 'workflowengine' => ['id' => 'workflowengine'],
  434. 'oauth2' => ['id' => 'oauth2'],
  435. ];
  436. $manager->expects($this->any())
  437. ->method('getAppInfo')
  438. ->willReturnCallback(
  439. function ($appId) use ($appInfos) {
  440. return $appInfos[$appId];
  441. }
  442. );
  443. $this->appConfig->setValue('test1', 'enabled', 'yes');
  444. $this->appConfig->setValue('test1', 'installed_version', '1.0.0');
  445. $this->appConfig->setValue('test2', 'enabled', 'yes');
  446. $this->appConfig->setValue('test2', 'installed_version', '1.0.0');
  447. $this->appConfig->setValue('test3', 'enabled', 'yes');
  448. $this->appConfig->setValue('test3', 'installed_version', '1.0.0');
  449. $this->appConfig->setValue('test4', 'enabled', 'yes');
  450. $this->appConfig->setValue('test4', 'installed_version', '2.4.0');
  451. $apps = $manager->getAppsNeedingUpgrade('8.2.0');
  452. $this->assertCount(2, $apps);
  453. $this->assertEquals('test1', $apps[0]['id']);
  454. $this->assertEquals('test4', $apps[1]['id']);
  455. }
  456. public function testGetIncompatibleApps() {
  457. /** @var AppManager|MockObject $manager */
  458. $manager = $this->getMockBuilder(AppManager::class)
  459. ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger])
  460. ->setMethods(['getAppInfo'])
  461. ->getMock();
  462. $appInfos = [
  463. 'cloud_federation_api' => ['id' => 'cloud_federation_api'],
  464. 'dav' => ['id' => 'dav'],
  465. 'files' => ['id' => 'files'],
  466. 'federatedfilesharing' => ['id' => 'federatedfilesharing'],
  467. 'provisioning_api' => ['id' => 'provisioning_api'],
  468. 'lookup_server_connector' => ['id' => 'lookup_server_connector'],
  469. 'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '8.0.0'],
  470. 'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'],
  471. 'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'],
  472. 'settings' => ['id' => 'settings'],
  473. 'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'],
  474. 'theming' => ['id' => 'theming'],
  475. 'twofactor_backupcodes' => ['id' => 'twofactor_backupcodes'],
  476. 'workflowengine' => ['id' => 'workflowengine'],
  477. 'oauth2' => ['id' => 'oauth2'],
  478. 'viewer' => ['id' => 'viewer'],
  479. ];
  480. $manager->expects($this->any())
  481. ->method('getAppInfo')
  482. ->willReturnCallback(
  483. function ($appId) use ($appInfos) {
  484. return $appInfos[$appId];
  485. }
  486. );
  487. $this->appConfig->setValue('test1', 'enabled', 'yes');
  488. $this->appConfig->setValue('test2', 'enabled', 'yes');
  489. $this->appConfig->setValue('test3', 'enabled', 'yes');
  490. $apps = $manager->getIncompatibleApps('8.2.0');
  491. $this->assertCount(2, $apps);
  492. $this->assertEquals('test1', $apps[0]['id']);
  493. $this->assertEquals('test3', $apps[1]['id']);
  494. }
  495. public function testGetEnabledAppsForGroup() {
  496. $group = $this->createMock(IGroup::class);
  497. $group->expects($this->any())
  498. ->method('getGID')
  499. ->willReturn('foo');
  500. $this->appConfig->setValue('test1', 'enabled', 'yes');
  501. $this->appConfig->setValue('test2', 'enabled', 'no');
  502. $this->appConfig->setValue('test3', 'enabled', '["foo"]');
  503. $this->appConfig->setValue('test4', 'enabled', '["asd"]');
  504. $enabled = [
  505. 'cloud_federation_api',
  506. 'dav',
  507. 'federatedfilesharing',
  508. 'files',
  509. 'lookup_server_connector',
  510. 'oauth2',
  511. 'provisioning_api',
  512. 'settings',
  513. 'test1',
  514. 'test3',
  515. 'theming',
  516. 'twofactor_backupcodes',
  517. 'viewer',
  518. 'workflowengine',
  519. ];
  520. $this->assertEquals($enabled, $this->manager->getEnabledAppsForGroup($group));
  521. }
  522. public function testGetAppRestriction() {
  523. $this->appConfig->setValue('test1', 'enabled', 'yes');
  524. $this->appConfig->setValue('test2', 'enabled', 'no');
  525. $this->appConfig->setValue('test3', 'enabled', '["foo"]');
  526. $this->assertEquals([], $this->manager->getAppRestriction('test1'));
  527. $this->assertEquals([], $this->manager->getAppRestriction('test2'));
  528. $this->assertEquals(['foo'], $this->manager->getAppRestriction('test3'));
  529. }
  530. public function provideDefaultApps(): array {
  531. return [
  532. // none specified, default to files
  533. [
  534. '',
  535. 'files',
  536. ],
  537. // unexisting or inaccessible app specified, default to files
  538. [
  539. 'unexist',
  540. 'files',
  541. ],
  542. // non-standard app
  543. [
  544. 'settings',
  545. 'settings',
  546. ],
  547. // non-standard app with fallback
  548. [
  549. 'unexist,settings',
  550. 'settings',
  551. ],
  552. ];
  553. }
  554. /**
  555. * @dataProvider provideDefaultApps
  556. */
  557. public function testGetDefaultAppForUser($defaultApps, $expectedApp) {
  558. $user = $this->newUser('user1');
  559. $this->userSession->expects($this->once())
  560. ->method('getUser')
  561. ->willReturn($user);
  562. $this->config->expects($this->once())
  563. ->method('getSystemValueString')
  564. ->with('defaultapp', $this->anything())
  565. ->willReturn($defaultApps);
  566. $this->assertEquals($expectedApp, $this->manager->getDefaultAppForUser());
  567. }
  568. }