From 68d89ad0e07b0937874b8f7a074f82bc77144a5c Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Thu, 6 Feb 2020 09:22:30 -0700 Subject: [PATCH] Fixed parent directory when one level deep --- app/src/ViewFunctions/ParentDir.php | 2 +- tests/ViewFunctions/ParentDirTest.php | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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);