diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-01-27 11:25:26 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-27 11:25:26 -0600 |
commit | 8b95bd29ee5131721ff2644936309fd75c1ab956 (patch) | |
tree | 82fb4a10a5c85e6540698bee7c355d420c316ac7 /tests | |
parent | 05884bcd7c80ddd84b945ba6917bdf4a16532b52 (diff) | |
parent | 27f8a832e41590a33a7815d328564a1fd70e7760 (diff) | |
download | nextcloud-server-8b95bd29ee5131721ff2644936309fd75c1ab956.tar.gz nextcloud-server-8b95bd29ee5131721ff2644936309fd75c1ab956.zip |
Merge pull request #2822 from nextcloud/add-navigation-via-info.xml
Add navigation via info.xml (#26785)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/NavigationManagerTest.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/lib/NavigationManagerTest.php b/tests/lib/NavigationManagerTest.php index 96708786e39..64fec802eca 100644 --- a/tests/lib/NavigationManagerTest.php +++ b/tests/lib/NavigationManagerTest.php @@ -12,7 +12,15 @@ namespace Test; +use OC\App\AppManager; 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 +165,62 @@ 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(AppManager::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', 'name' => 'Test']]], + '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', 'name' => 'Test']], true], + 'no name' => [[], ['navigation' => ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']], true], + 'admin' => [[], ['navigation' => ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]] + ]; + } } |