From 8734afd04c3cff985b2bf7e38eb8cca3a89ad75e Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Tue, 12 Aug 2014 12:34:25 +0100 Subject: [PATCH] Test get filename from requested URI --- src/Dispatcher/Dispatcher.php | 10 +++------ test/Unit/Dispatcher/PageDispatcher.test.php | 23 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Dispatcher/Dispatcher.php b/src/Dispatcher/Dispatcher.php index 0f814dcc..b5a43210 100644 --- a/src/Dispatcher/Dispatcher.php +++ b/src/Dispatcher/Dispatcher.php @@ -122,15 +122,11 @@ public function process() { /** * Gets the name of the requested file in the current directory path, or returns * the default index filename if the directory is requested. - * TODO: Needs test! */ public function getFilename($uri, $indexFilename, $path) { - $filename = basename($this->request->uri); - if(empty($filename) - // TODO: Temporary solution. Needs to be robust, so nested directories of - // the same name are possible. - || strtolower($filename) === strtolower(basename($path))) { - $filename = $this->request->indexFilename; + $filename = basename($uri); + if(empty($filename) || substr($uri, -1) === "/") { + $filename = $indexFilename; } return $filename; diff --git a/test/Unit/Dispatcher/PageDispatcher.test.php b/test/Unit/Dispatcher/PageDispatcher.test.php index 26a7401e..35063861 100644 --- a/test/Unit/Dispatcher/PageDispatcher.test.php +++ b/test/Unit/Dispatcher/PageDispatcher.test.php @@ -46,6 +46,7 @@ public function tearDown() { "/directory/", "/directory/inner-file", "/directory/nested/double-inner-file", + "/doubleName/doubleName", ]; public function data_uris() { @@ -215,8 +216,26 @@ public function testCreateResponseContentThrowsTypeException() { $responseContent = $this->dispatcher->createResponseContent($notHtml); } -// public function testGetFilenameRequestedFromUri() { -// // Or index filename if none set. +/** + * @dataProvider data_uris + */ +public function testGetFilenameRequestedFromUri($uri) { + $path = $this->pageViewDir; + $filename = $this->dispatcher->getFilename($uri, "index", $path); + + if(substr($uri, -1) === "/") { + $this->assertEquals("index", $filename); + } + else { + $this->assertEquals(basename($uri), $filename); + } +} + +// /** +// * @dataProvider data_uris +// */ +// public function testDispatcherFixesUri($uri) { + // } }# \ No newline at end of file