diff options
author | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-12-08 17:43:46 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-12-22 12:34:41 +0100 |
commit | aa8755bd4b2d5a949a35f1308eefa6d00140a1a7 (patch) | |
tree | 09153939dd285480a1225290d7bde664e41826fa /tests | |
parent | 7f8d22e7102293d96c365b380bf1845ff2de6b71 (diff) | |
download | nextcloud-server-aa8755bd4b2d5a949a35f1308eefa6d00140a1a7.tar.gz nextcloud-server-aa8755bd4b2d5a949a35f1308eefa6d00140a1a7.zip |
Add navigation via info.xml (#26785)
* Read navigation information from info.xml
* Load files navigation elements from info.xml
* Add comment about ignoring the exception
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/NavigationManagerTest.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/lib/NavigationManagerTest.php b/tests/lib/NavigationManagerTest.php index 96708786e39..942dcbe1865 100644 --- a/tests/lib/NavigationManagerTest.php +++ b/tests/lib/NavigationManagerTest.php @@ -13,6 +13,13 @@ namespace Test; use OC\NavigationManager; +use OCP\App\IAppManager; +use OCP\IGroupManager; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\IUser; +use OCP\IUserSession; +use OCP\L10N\IFactory; class NavigationManagerTest extends TestCase { /** @var \OC\NavigationManager */ @@ -157,4 +164,61 @@ class NavigationManagerTest extends TestCase { $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists after clear()'); $this->assertEquals(0, $testAddClosureNumberOfCalls, 'Expected that the closure is not called by getAll()'); } + + /** + * @dataProvider providesNavigationConfig + */ + public function testWithAppManager($expected, $config, $isAdmin = false) { + + $appManager = $this->createMock(IAppManager::class); + $urlGenerator = $this->createMock(IURLGenerator::class); + $l10nFac = $this->createMock(IFactory::class); + $userSession = $this->createMock(IUserSession::class); + $groupManager = $this->createMock(IGroupManager::class); + $l = $this->createMock(IL10N::class); + $l->expects($this->any())->method('t')->willReturnCallback(function($text, $parameters = []) { + return vsprintf($text, $parameters); + }); + + $appManager->expects($this->once())->method('getInstalledApps')->willReturn(['test']); + $appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($config); + $l10nFac->expects($this->exactly(count($expected)))->method('get')->with('test')->willReturn($l); + $urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function($appName, $file) { + return "/apps/$appName/img/$file"; + }); + $urlGenerator->expects($this->exactly(count($expected)))->method('linkToRoute')->willReturnCallback(function($route) { + return "/apps/test/"; + }); + $user = $this->createMock(IUser::class); + $user->expects($this->any())->method('getUID')->willReturn('user001'); + $userSession->expects($this->any())->method('getUser')->willReturn($user); + $groupManager->expects($this->any())->method('isAdmin')->willReturn($isAdmin); + + $navigationManager = new NavigationManager($appManager, $urlGenerator, $l10nFac, $userSession, $groupManager); + + $entries = $navigationManager->getAll(); + $this->assertEquals($expected, $entries); + } + + public function providesNavigationConfig() { + return [ + 'minimalistic' => [[[ + 'id' => 'test', + 'order' => 100, + 'href' => '/apps/test/', + 'icon' => '/apps/test/img/app.svg', + 'name' => 'Test', + 'active' => false + ]], ['navigation' => ['route' => 'test.page.index']]], + 'no admin' => [[[ + 'id' => 'test', + 'order' => 100, + 'href' => '/apps/test/', + 'icon' => '/apps/test/img/app.svg', + 'name' => 'Test', + 'active' => false + ]], ['navigation' => ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']], true], + 'admin' => [[], ['navigation' => ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']]] + ]; + } } |