From 43889d1a49feadb032402cff45bf8ee13184b4c8 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Fri, 14 Sep 2018 22:06:56 +0200 Subject: [PATCH] Fixes empty favorite names for trailing slashes Signed-off-by: Michael Weimann --- apps/files/lib/Controller/ViewController.php | 3 +- .../tests/Controller/ViewControllerTest.php | 72 ++++++++++++++++++- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 0655718f8c..d91d3b9db4 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -176,7 +176,6 @@ class ViewController extends Controller { $currentCount = 0; foreach ($favElements['folders'] as $dir) { - $id = substr($dir, strrpos($dir, '/') + 1, strlen($dir)); $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); $sortingValue = ++$currentCount; $element = [ @@ -186,7 +185,7 @@ class ViewController extends Controller { 'dir' => $dir, 'order' => $navBarPositionPosition, 'folderPosition' => $sortingValue, - 'name' => $id, + 'name' => basename($dir), 'icon' => 'files', 'quickaccesselement' => 'true' ]; diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index 7dc9940980..f11a6faf86 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -176,8 +176,53 @@ class ViewControllerTest extends TestCase { 'active' => false, 'icon' => '', 'type' => 'link', - 'classes' => '', - 'sublist' => [], + 'classes' => 'collapsible', + 'sublist' => [ + [ + 'id' => '-test1', + 'view' => 'files', + 'href' => '', + 'dir' => '/test1', + 'order' => 6, + 'folderPosition' => 1, + 'name' => 'test1', + 'icon' => 'files', + 'quickaccesselement' => 'true', + ], + [ + 'name' => 'test2', + 'id' => '-test2-', + 'view' => 'files', + 'href' => '', + 'dir' => '/test2/', + 'order' => 7, + 'folderPosition' => 2, + 'icon' => 'files', + 'quickaccesselement' => 'true', + ], + [ + 'name' => 'sub4', + 'id' => '-test3-sub4', + 'view' => 'files', + 'href' => '', + 'dir' => '/test3/sub4', + 'order' => 8, + 'folderPosition' => 3, + 'icon' => 'files', + 'quickaccesselement' => 'true', + ], + [ + 'name' => 'sub6', + 'id' => '-test5-sub6-', + 'view' => 'files', + 'href' => '', + 'dir' => '/test5/sub6/', + 'order' => 9, + 'folderPosition' => 4, + 'icon' => 'files', + 'quickaccesselement' => 'true', + ], + ], 'defaultExpandedState' => false, 'expandedState' => 'show_Quick_Access' ], @@ -303,6 +348,22 @@ class ViewControllerTest extends TestCase { 'id' => 'shareoverview', 'content' => null, ], + '-test1' => [ + 'id' => '-test1', + 'content' => '', + ], + '-test2-' => [ + 'id' => '-test2-', + 'content' => '', + ], + '-test3-sub4' => [ + 'id' => '-test3-sub4', + 'content' => '', + ], + '-test5-sub6-' => [ + 'id' => '-test5-sub6-', + 'content' => '', + ], ], 'hiddenFields' => [], ] @@ -315,7 +376,12 @@ class ViewControllerTest extends TestCase { ->with($this->user->getUID()) ->willReturn([ 'item' => [], - 'folders' => [], + 'folders' => [ + '/test1', + '/test2/', + '/test3/sub4', + '/test5/sub6/', + ], ]); $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));