Skip to content

Commit 6211d18

Browse files
committed
Add tests for NavigationController
Signed-off-by: Julius Härtl <[email protected]>
1 parent b6da8c5 commit 6211d18

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

core/Controller/NavigationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class NavigationController extends Controller {
3232
/** @var INavigationManager */
3333
private $navigationManager;
3434

35-
public function __construct(IRequest $request, INavigationManager $navigationManager) {
36-
parent::__construct('core', $request);
35+
public function __construct(string $appName, IRequest $request, INavigationManager $navigationManager) {
36+
parent::__construct($appName, $request);
3737
$this->navigationManager = $navigationManager;
3838
}
3939

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2018 Julius Härtl <[email protected]>
4+
*
5+
* @author Julius Härtl <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
namespace Tests\Core\Controller;
24+
25+
use OC\Core\Controller\NavigationController;
26+
use OCP\AppFramework\Http\JSONResponse;
27+
use OCP\INavigationManager;
28+
use OCP\IRequest;
29+
use Test\TestCase;
30+
31+
class NavigationControllerTest extends TestCase {
32+
33+
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
34+
private $request;
35+
36+
/** @var INavigationManager|\PHPUnit_Framework_MockObject_MockObject */
37+
private $navigationManager;
38+
39+
/** @var NavigationController */
40+
private $controller;
41+
42+
public function setUp() {
43+
parent::setUp();
44+
45+
46+
$this->request = $this->createMock(IRequest::class);
47+
$this->navigationManager = $this->createMock(INavigationManager::class);
48+
49+
$this->controller = new NavigationController(
50+
'core',
51+
$this->request,
52+
$this->navigationManager
53+
);
54+
}
55+
56+
public function dataGetNavigation() {
57+
return [
58+
[false], [true]
59+
];
60+
}
61+
/** @dataProvider dataGetNavigation */
62+
public function testGetAppNavigation($absolute) {
63+
$this->navigationManager->expects($this->once())
64+
->method('getAll')
65+
->with('link', $absolute);
66+
$this->assertInstanceOf(JSONResponse::class, $this->controller->getAppsNavigation($absolute));
67+
}
68+
69+
/** @dataProvider dataGetNavigation */
70+
public function testGetSettingsNavigation($absolute) {
71+
$this->navigationManager->expects($this->once())
72+
->method('getAll')
73+
->with('settings', $absolute);
74+
$this->assertInstanceOf(JSONResponse::class, $this->controller->getSettingsNavigation($absolute));
75+
}
76+
77+
}

0 commit comments

Comments
 (0)