diff --git a/tests/cases/helpers/api_doc.test.php b/tests/cases/helpers/api_doc.test.php index bfa2593..c1dfd31 100644 --- a/tests/cases/helpers/api_doc.test.php +++ b/tests/cases/helpers/api_doc.test.php @@ -53,12 +53,13 @@ function testInBasePath() { **/ function testTrimFileName() { $result = $this->ApiDoc->trimFileName($this->_pluginPath . '/tests/cases/helpers/api_doc.test.php'); - $this->assertEqual($result, '/tests/cases/helpers/api_doc.test.php'); + $this->assertEqual($result, 'tests/cases/helpers/api_doc.test.php'); $result = $this->ApiDoc->trimFileName('/some/other/path/tests/cases/helpers/api_doc.test.php'); - $expected = '/tests/cases/helpers/api_doc.test.php'; + $expected = 'tests/cases/helpers/api_doc.test.php'; $this->assertEqual($result, $expected, 'Trim path with different bases is not working %s'); } + /** * testFileLink * @@ -75,7 +76,7 @@ function testFileLink() { $result = $this->ApiDoc->fileLink($testFile); $expected = array( 'a' => array('href' => '/api_generator/view_file/views/helpers/api_doc.php'), - 'preg:/\/views\/helpers\/api_doc.php/', + 'views/helpers/api_doc.php', '/a' ); $this->assertTags($result, $expected); @@ -83,7 +84,7 @@ function testFileLink() { $result = $this->ApiDoc->fileLink($testFile, array('controller' => 'foo', 'action' => 'bar')); $expected = array( 'a' => array('href' => '/api_generator/foo/bar/views/helpers/api_doc.php'), - 'preg:/\/views\/helpers\/api_doc.php/', + 'views/helpers/api_doc.php', '/a' ); $this->assertTags($result, $expected); diff --git a/views/helpers/api_doc.php b/views/helpers/api_doc.php index a886dea..0ba9204 100644 --- a/views/helpers/api_doc.php +++ b/views/helpers/api_doc.php @@ -70,7 +70,7 @@ public function __construct($config = array()) { * @return void **/ public function setBasePath($path) { - $this->_basePath = realpath($path); + $this->_basePath = Folder::slashTerm(realpath($path)); } /** * inBasePath @@ -92,10 +92,10 @@ function inBasePath($filename) { **/ public function fileLink($filename, $url = array(), $attributes = array()) { $url = array_merge($this->_defaultUrl['file'], $url); - if ($this->inBasePath($filename)) { - $trimmedName = $this->trimFileName($filename); - $url[] = $trimmedName; - return $this->Html->link($trimmedName, $url, $attributes); + $trimmedFile = $this->trimFileName($filename); + if (!empty($trimmedFile) && $trimmedFile != $filename) { + $url[] = $trimmedFile; + return $this->Html->link($trimmedFile, $url, $attributes); } return $filename; } @@ -127,6 +127,9 @@ protected function _searchBasePath($filename) { $currentPath = $testPath = $this->_basePath; while (!empty($pathBits)) { $pathSegment = array_shift($pathBits); + if (empty($pathSegment)) { + continue; + } $testPath .= $pathSegment; if (count($pathBits)) { $testPath .= DS;