diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-09-26 16:21:22 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-09-26 16:21:22 +0200 |
commit | b11eb9e6d6551dda57b5b8c65a5666c63c4e02c7 (patch) | |
tree | bca595665cd4bdb26fee04d99924fb7766c67c7f /tests/lib | |
parent | 2d28e8110fd8a5b01d1d540f1d1cf42f117c3bab (diff) | |
download | nextcloud-server-b11eb9e6d6551dda57b5b8c65a5666c63c4e02c7.tar.gz nextcloud-server-b11eb9e6d6551dda57b5b8c65a5666c63c4e02c7.zip |
Fix and extend NavigationManagerTest.php
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/NavigationManagerTest.php | 84 |
1 files changed, 79 insertions, 5 deletions
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); + } } |