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')); + } +}