Fixed parent directory when one level deep

This commit is contained in:
Chris Kankiewicz
2020-02-06 09:22:30 -07:00
parent 148425619d
commit 68d89ad0e0
2 changed files with 16 additions and 2 deletions

View File

@@ -22,6 +22,6 @@ class ParentDir extends ViewFunction
explode('/', $path)
)->filter()->slice(0, -1)->implode('/');
return empty($parentDir) ? '' : sprintf('?dir=%s', $parentDir);
return empty($parentDir) ? '.' : sprintf('?dir=%s', $parentDir);
}
}

View File

@@ -7,7 +7,21 @@ use Tests\TestCase;
class ParentDirTest extends TestCase
{
public function test_it_can_get_the_parent_directory_from_a_path(): void
public function test_it_can_get_the_parent_directory_when_one_level_deep(): void
{
$parentDir = new ParentDir($this->container, $this->config);
$this->assertEquals('.', $parentDir('foo'));
}
public function test_it_can_get_the_parent_directory_when_two_levels_deep(): void
{
$parentDir = new ParentDir($this->container, $this->config);
$this->assertEquals('?dir=foo', $parentDir('foo/bar'));
}
public function test_it_can_get_the_parent_directory_when_three_levels_deep(): void
{
$parentDir = new ParentDir($this->container, $this->config);