Skip to content

Commit

Permalink
Test get filename from requested URI
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Aug 12, 2014
1 parent 55f75ca commit 8734afd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/Dispatcher/Dispatcher.php
Expand Up @@ -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;
Expand Down
23 changes: 21 additions & 2 deletions test/Unit/Dispatcher/PageDispatcher.test.php
Expand Up @@ -46,6 +46,7 @@ public function tearDown() {
"/directory/",
"/directory/inner-file",
"/directory/nested/double-inner-file",
"/doubleName/doubleName",
];

public function data_uris() {
Expand Down Expand Up @@ -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) {

// }

}#

0 comments on commit 8734afd

Please sign in to comment.