From 9ad8c54d492119f2d6a0d56b5834dc9879cb3683 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Sun, 26 Jan 2020 00:54:29 -0700 Subject: [PATCH] Fixed 'Home' link in header breadcrumbs --- app/Providers/TwigProvider.php | 1 + app/ViewFunctions/Url.php | 23 +++++++++++++++++ app/resources/views/components/header.twig | 2 +- tests/ViewFunctions/UrlTest.php | 29 ++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/ViewFunctions/Url.php create mode 100644 tests/ViewFunctions/UrlTest.php diff --git a/app/Providers/TwigProvider.php b/app/Providers/TwigProvider.php index 45177eb..1137d68 100644 --- a/app/Providers/TwigProvider.php +++ b/app/Providers/TwigProvider.php @@ -21,6 +21,7 @@ class TwigProvider ViewFunctions\Markdown::class, ViewFunctions\ParentDir::class, ViewFunctions\SizeForHumans::class, + ViewFunctions\Url::class, ]; /** @var Container The application container */ diff --git a/app/ViewFunctions/Url.php b/app/ViewFunctions/Url.php new file mode 100644 index 0000000..41586ff --- /dev/null +++ b/app/ViewFunctions/Url.php @@ -0,0 +1,23 @@ +
- Home + Home {% if path %} {% for name, path in breadcrumbs(path) %} diff --git a/tests/ViewFunctions/UrlTest.php b/tests/ViewFunctions/UrlTest.php new file mode 100644 index 0000000..dd166ad --- /dev/null +++ b/tests/ViewFunctions/UrlTest.php @@ -0,0 +1,29 @@ +container, $this->config); + + $this->assertEquals('/', $url('/')); + $this->assertEquals('/some/path', $url('some/path')); + $this->assertEquals('/some/file.test', $url('some/file.test')); + } + + public function test_it_can_return_a_url_in_a_subdirectory(): void + { + $_SERVER['SCRIPT_NAME'] = '/some/dir/index.php'; + + $url = new Url($this->container, $this->config); + + $this->assertEquals('/some/dir', $url('/')); + $this->assertEquals('/some/dir/some/path', $url('some/path')); + $this->assertEquals('/some/dir/some/file.test', $url('some/file.test')); + } +}