1
0

AppManagerTest.php 18 KB

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