diff --git a/app/src/ViewFunctions/ParentDir.php b/app/src/ViewFunctions/ParentDir.php index a5019dd..a9d3abc 100644 --- a/app/src/ViewFunctions/ParentDir.php +++ b/app/src/ViewFunctions/ParentDir.php @@ -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); } } diff --git a/tests/ViewFunctions/ParentDirTest.php b/tests/ViewFunctions/ParentDirTest.php index 2273f0f..be5cc5e 100644 --- a/tests/ViewFunctions/ParentDirTest.php +++ b/tests/ViewFunctions/ParentDirTest.php @@ -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);