Skip to content

Commit

Permalink
modify normalizeWorkingDir()
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Dec 11, 2017
1 parent 79d98d6 commit c16ca8c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
9 changes: 8 additions & 1 deletion src/Lfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ public function getUserSlug()
return empty(auth()->user()) ? '' : auth()->user()->$config;
}

public function getRootFolder($type)
public function getRootFolder($type = null)
{
if (is_null($type)) {
$type = 'share';
if ($this->allowFolderType('user')) {
$type = 'user';
}
}

if ($type === 'user') {
$folder = $this->getUserSlug();
} else {
Expand Down
15 changes: 3 additions & 12 deletions src/LfmPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,9 @@ public function createFolder()

public function normalizeWorkingDir()
{
$working_dir = $this->working_dir ?: $this->helper->input('working_dir');

if (empty($working_dir)) {
$default_folder_type = 'share';
if ($this->helper->allowFolderType('user')) {
$default_folder_type = 'user';
}

$working_dir = $this->helper->getRootFolder($default_folder_type);
}

return $working_dir;
return $this->working_dir
?: $this->helper->input('working_dir')
?: $this->helper->getRootFolder();
}

/**
Expand Down
6 changes: 2 additions & 4 deletions tests/LfmPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public function testSetNameAndGetName()
public function testPath()
{
$helper = m::mock(Lfm::class);
$helper->shouldReceive('allowFolderType')->with('user')->andReturn(true);
$helper->shouldReceive('getRootFolder')->with('user')->andReturn('/foo');
$helper->shouldReceive('getRootFolder')->andReturn('/foo');
$helper->shouldReceive('basePath')->andReturn(realpath(__DIR__ . '/../'));
$helper->shouldReceive('input')->with('working_dir')->andReturnNull();
$helper->shouldReceive('getCategoryName')->andReturn('files');
Expand All @@ -94,8 +93,7 @@ public function testPath()
public function testUrl()
{
$helper = m::mock(Lfm::class);
$helper->shouldReceive('allowFolderType')->with('user')->once()->andReturn(true);
$helper->shouldReceive('getRootFolder')->with('user')->once()->andReturn('/foo');
$helper->shouldReceive('getRootFolder')->once()->andReturn('/foo');
$helper->shouldReceive('input')->with('working_dir')->once()->andReturnNull();
$helper->shouldReceive('getCategoryName')->andReturn('files');
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
Expand Down
1 change: 1 addition & 0 deletions tests/LfmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function testGetUserSlug()
public function testGetRootFolder()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.allow_multi_user')->andReturn(true);
$config->shouldReceive('get')->with('lfm.user_folder_name')->once()->andReturn(function () {
return 'foo';
});
Expand Down

0 comments on commit c16ca8c

Please sign in to comment.