mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 14:50:17 -04:00
fix(navigation): Fix default app entry registered as closure
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
0c3ebbfed5
commit
553870d30a
2 changed files with 45 additions and 14 deletions
|
|
@ -77,7 +77,7 @@ class NavigationManager implements INavigationManager {
|
|||
$this->closureEntries[] = $entry;
|
||||
return;
|
||||
}
|
||||
$this->init();
|
||||
$this->init(false);
|
||||
|
||||
$id = $entry['id'];
|
||||
|
||||
|
|
@ -123,10 +123,6 @@ class NavigationManager implements INavigationManager {
|
|||
*/
|
||||
public function getAll(string $type = 'link'): array {
|
||||
$this->init();
|
||||
foreach ($this->closureEntries as $c) {
|
||||
$this->add($c());
|
||||
}
|
||||
$this->closureEntries = [];
|
||||
|
||||
$result = $this->entries;
|
||||
if ($type !== 'all') {
|
||||
|
|
@ -212,7 +208,13 @@ class NavigationManager implements INavigationManager {
|
|||
return $this->activeEntry;
|
||||
}
|
||||
|
||||
private function init() {
|
||||
private function init(bool $resolveClosures = true): void {
|
||||
if ($resolveClosures) {
|
||||
while ($c = array_pop($this->closureEntries)) {
|
||||
$this->add($c());
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->init) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -420,11 +422,6 @@ class NavigationManager implements INavigationManager {
|
|||
|
||||
public function get(string $id): ?array {
|
||||
$this->init();
|
||||
foreach ($this->closureEntries as $c) {
|
||||
$this->add($c());
|
||||
}
|
||||
$this->closureEntries = [];
|
||||
|
||||
return $this->entries[$id];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -704,30 +704,64 @@ class NavigationManagerTest extends TestCase {
|
|||
true,
|
||||
'settings',
|
||||
],
|
||||
// closure navigation entries are also resolved
|
||||
[
|
||||
'closure2',
|
||||
'',
|
||||
'',
|
||||
true,
|
||||
'closure2',
|
||||
],
|
||||
[
|
||||
'',
|
||||
'closure2',
|
||||
'',
|
||||
true,
|
||||
'closure2',
|
||||
],
|
||||
[
|
||||
'',
|
||||
'',
|
||||
'{"closure2":{"order":1,"app":"closure2","href":"/closure2"}}',
|
||||
true,
|
||||
'closure2',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDefaultEntries
|
||||
*/
|
||||
public function testGetDefaultEntryIdForUser($defaultApps, $userDefaultApps, $userApporder, $withFallbacks, $expectedApp): void {
|
||||
public function testGetDefaultEntryIdForUser(string $defaultApps, string $userDefaultApps, string $userApporder, bool $withFallbacks, string $expectedApp): void {
|
||||
$this->navigationManager->add([
|
||||
'id' => 'files',
|
||||
]);
|
||||
$this->navigationManager->add([
|
||||
'id' => 'settings',
|
||||
]);
|
||||
$this->navigationManager->add(static function (): array {
|
||||
return [
|
||||
'id' => 'closure1',
|
||||
'href' => '/closure1',
|
||||
];
|
||||
});
|
||||
$this->navigationManager->add(static function (): array {
|
||||
return [
|
||||
'id' => 'closure2',
|
||||
'href' => '/closure2',
|
||||
];
|
||||
});
|
||||
|
||||
$this->appManager->method('getEnabledApps')->willReturn([]);
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->method('getUID')->willReturn('user1');
|
||||
|
||||
$this->userSession->expects($this->once())
|
||||
$this->userSession->expects($this->atLeastOnce())
|
||||
->method('getUser')
|
||||
->willReturn($user);
|
||||
|
||||
$this->config->expects($this->once())
|
||||
$this->config->expects($this->atLeastOnce())
|
||||
->method('getSystemValueString')
|
||||
->with('defaultapp', $this->anything())
|
||||
->willReturn($defaultApps);
|
||||
|
|
|
|||
Loading…
Reference in a new issue