diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2023-09-28 10:55:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-28 10:55:52 +0200 |
commit | c9ed1e981bb0493cd02a4fcccfb299dcd847e618 (patch) | |
tree | 51a96cc7da5006b32f878479762f11ba23c45550 /tests | |
parent | 99e287b49abaa1c0807a5bb6e7bae6d6f764f82d (diff) | |
parent | 8049702413f4422ea299733c8f69b852732edcb2 (diff) | |
download | nextcloud-server-c9ed1e981bb0493cd02a4fcccfb299dcd847e618.tar.gz nextcloud-server-c9ed1e981bb0493cd02a4fcccfb299dcd847e618.zip |
Merge pull request #40617 from nextcloud/enh/allow-user-to-set-apporder
Read apporder from configuration value
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 32 | ||||
-rw-r--r-- | tests/lib/NavigationManagerTest.php | 84 |
2 files changed, 107 insertions, 9 deletions
diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index 3bf2195499f..73ac7b79909 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -607,21 +607,43 @@ class AppManagerTest extends TestCase { // none specified, default to files [ '', + '', + '{}', 'files', ], // unexisting or inaccessible app specified, default to files [ 'unexist', + '', + '{}', 'files', ], // non-standard app [ 'settings', + '', + '{}', 'settings', ], // non-standard app with fallback [ 'unexist,settings', + '', + '{}', + 'settings', + ], + // user-customized defaultapp + [ + 'unexist,settings', + 'files', + '{"settings":[1],"files":[2]}', + 'files', + ], + // user-customized apporder fallback + [ + '', + '', + '{"settings":[1],"files":[2]}', 'settings', ], ]; @@ -630,7 +652,7 @@ class AppManagerTest extends TestCase { /** * @dataProvider provideDefaultApps */ - public function testGetDefaultAppForUser($defaultApps, $expectedApp) { + public function testGetDefaultAppForUser($defaultApps, $userDefaultApps, $userApporder, $expectedApp) { $user = $this->newUser('user1'); $this->userSession->expects($this->once()) @@ -642,10 +664,12 @@ class AppManagerTest extends TestCase { ->with('defaultapp', $this->anything()) ->willReturn($defaultApps); - $this->config->expects($this->once()) + $this->config->expects($this->atLeastOnce()) ->method('getUserValue') - ->with('user1', 'core', 'defaultapp') - ->willReturn(''); + ->willReturnMap([ + ['user1', 'core', 'defaultapp', '', $userDefaultApps], + ['user1', 'core', 'apporder', '[]', $userApporder], + ]); $this->assertEquals($expectedApp, $this->manager->getDefaultAppForUser()); } diff --git a/tests/lib/NavigationManagerTest.php b/tests/lib/NavigationManagerTest.php index d5c827fe1cb..65289799d59 100644 --- a/tests/lib/NavigationManagerTest.php +++ b/tests/lib/NavigationManagerTest.php @@ -215,6 +215,10 @@ class NavigationManagerTest extends TestCase { return vsprintf($text, $parameters); }); + /* Return default value */ + $this->config->method('getUserValue') + ->willReturnArgument(3); + $this->appManager->expects($this->any()) ->method('isEnabledForUser') ->with('theming') @@ -417,12 +421,82 @@ class NavigationManagerTest extends TestCase { ], 'no admin' => [ $defaults, - ['navigations' => [[ - '@attributes' => ['role' => 'admin'], - 'route' => 'test.page.index', - 'name' => 'Test' - ]]] + ['navigations' => [ + 'navigation' => [ + ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test'] + ], + ]], ] ]; } + + public function testWithAppManagerAndApporder() { + $l = $this->createMock(IL10N::class); + $l->expects($this->any())->method('t')->willReturnCallback(function ($text, $parameters = []) { + return vsprintf($text, $parameters); + }); + + $testOrder = 12; + $expected = [ + 'test' => [ + 'type' => 'link', + 'id' => 'test', + 'order' => $testOrder, + 'href' => '/apps/test/', + 'name' => 'Test', + 'icon' => '/apps/test/img/app.svg', + 'active' => false, + 'classes' => '', + 'unread' => 0, + ], + ]; + $navigation = ['navigations' => [ + 'navigation' => [ + ['route' => 'test.page.index', 'name' => 'Test'] + ], + ]]; + + $this->config->method('getUserValue') + ->willReturnCallback( + function (string $userId, string $appName, string $key, mixed $default = '') use ($testOrder) { + $this->assertEquals('user001', $userId); + if ($key === 'apporder') { + return json_encode(['test' => [$testOrder]]); + } + return $default; + } + ); + + $this->appManager->expects($this->any()) + ->method('isEnabledForUser') + ->with('theming') + ->willReturn(true); + $this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation); + $this->l10nFac->expects($this->any())->method('get')->willReturn($l); + $this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function ($appName, $file) { + return "/apps/$appName/img/$file"; + }); + $this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function ($route) { + if ($route === 'core.login.logout') { + return 'https://example.com/logout'; + } + return '/apps/test/'; + }); + $user = $this->createMock(IUser::class); + $user->expects($this->any())->method('getUID')->willReturn('user001'); + $this->userSession->expects($this->any())->method('getUser')->willReturn($user); + $this->userSession->expects($this->any())->method('isLoggedIn')->willReturn(true); + $this->appManager->expects($this->any()) + ->method('getEnabledAppsForUser') + ->with($user) + ->willReturn(['test']); + $this->groupManager->expects($this->any())->method('isAdmin')->willReturn(false); + $subadmin = $this->createMock(SubAdmin::class); + $subadmin->expects($this->any())->method('isSubAdmin')->with($user)->willReturn(false); + $this->groupManager->expects($this->any())->method('getSubAdmin')->willReturn($subadmin); + + $this->navigationManager->clear(); + $entries = $this->navigationManager->getAll(); + $this->assertEquals($expected, $entries); + } } |