Skip to content

Commit c16ca8c

Browse files
committed
modify normalizeWorkingDir()
1 parent 79d98d6 commit c16ca8c

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

src/Lfm.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,15 @@ public function getUserSlug()
115115
return empty(auth()->user()) ? '' : auth()->user()->$config;
116116
}
117117

118-
public function getRootFolder($type)
118+
public function getRootFolder($type = null)
119119
{
120+
if (is_null($type)) {
121+
$type = 'share';
122+
if ($this->allowFolderType('user')) {
123+
$type = 'user';
124+
}
125+
}
126+
120127
if ($type === 'user') {
121128
$folder = $this->getUserSlug();
122129
} else {

src/LfmPath.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,9 @@ public function createFolder()
156156

157157
public function normalizeWorkingDir()
158158
{
159-
$working_dir = $this->working_dir ?: $this->helper->input('working_dir');
160-
161-
if (empty($working_dir)) {
162-
$default_folder_type = 'share';
163-
if ($this->helper->allowFolderType('user')) {
164-
$default_folder_type = 'user';
165-
}
166-
167-
$working_dir = $this->helper->getRootFolder($default_folder_type);
168-
}
169-
170-
return $working_dir;
159+
return $this->working_dir
160+
?: $this->helper->input('working_dir')
161+
?: $this->helper->getRootFolder();
171162
}
172163

173164
/**

tests/LfmPathTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ public function testSetNameAndGetName()
7373
public function testPath()
7474
{
7575
$helper = m::mock(Lfm::class);
76-
$helper->shouldReceive('allowFolderType')->with('user')->andReturn(true);
77-
$helper->shouldReceive('getRootFolder')->with('user')->andReturn('/foo');
76+
$helper->shouldReceive('getRootFolder')->andReturn('/foo');
7877
$helper->shouldReceive('basePath')->andReturn(realpath(__DIR__ . '/../'));
7978
$helper->shouldReceive('input')->with('working_dir')->andReturnNull();
8079
$helper->shouldReceive('getCategoryName')->andReturn('files');
@@ -94,8 +93,7 @@ public function testPath()
9493
public function testUrl()
9594
{
9695
$helper = m::mock(Lfm::class);
97-
$helper->shouldReceive('allowFolderType')->with('user')->once()->andReturn(true);
98-
$helper->shouldReceive('getRootFolder')->with('user')->once()->andReturn('/foo');
96+
$helper->shouldReceive('getRootFolder')->once()->andReturn('/foo');
9997
$helper->shouldReceive('input')->with('working_dir')->once()->andReturnNull();
10098
$helper->shouldReceive('getCategoryName')->andReturn('files');
10199
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);

tests/LfmTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function testGetUserSlug()
122122
public function testGetRootFolder()
123123
{
124124
$config = m::mock(Config::class);
125+
$config->shouldReceive('get')->with('lfm.allow_multi_user')->andReturn(true);
125126
$config->shouldReceive('get')->with('lfm.user_folder_name')->once()->andReturn(function () {
126127
return 'foo';
127128
});

0 commit comments

Comments
 (0)