mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-29 08:40:42 +02:00
Fixed file and parent dir links not working properly
This commit is contained in:
@@ -18,8 +18,10 @@ class ParentDir extends ViewFunction
|
||||
*/
|
||||
public function __invoke(string $path)
|
||||
{
|
||||
return Collection::make(
|
||||
$parentDir = dirname($_SERVER['SCRIPT_NAME']) . '/' . Collection::make(
|
||||
explode('/', $path)
|
||||
)->filter()->slice(0, -1)->implode('/');
|
||||
|
||||
return '/' . ltrim($parentDir, '/');
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<a
|
||||
href="/{{ parentDir ? parent_dir(path) : file.getPathname }}"
|
||||
href="{{ parentDir ? parent_dir(path) : url(file.getPathname) }}"
|
||||
class="flex flex-col items-center rounded-lg font-mono group hover:bg-gray-200 hover:shadow"
|
||||
>
|
||||
<div class="flex justify-between items-center p-4 w-full">
|
||||
|
25
tests/ViewFunctions/ParentDirTest.php
Normal file
25
tests/ViewFunctions/ParentDirTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\ViewFunctions;
|
||||
|
||||
use App\ViewFunctions\ParentDir;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ParentDirTest extends TestCase
|
||||
{
|
||||
public function test_it_can_get_the_parent_directory_from_a_path(): void
|
||||
{
|
||||
$parentDir = new ParentDir($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('/foo/bar', $parentDir('foo/bar/baz'));
|
||||
}
|
||||
|
||||
public function test_it_can_get_the_parent_directory_from_a_path_in_a_subdirectory(): void
|
||||
{
|
||||
$_SERVER['SCRIPT_NAME'] = '/some/dir/index.php';
|
||||
|
||||
$parentDir = new ParentDir($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('/some/dir/foo/bar', $parentDir('foo/bar/baz'));
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\ViewFunctions;
|
||||
|
||||
use App\ViewFunctions\ParentDir;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ParentDirTest extends TestCase
|
||||
{
|
||||
public function test_it_can_get_the_parent_directory_from_a_path(): void
|
||||
{
|
||||
$parentDir = new ParentDir($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('foo/bar', $parentDir('foo/bar/baz'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user