Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing fileLinks on confused paths.
  • Loading branch information
markstory committed May 31, 2009
1 parent ff112b5 commit 214511d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 5 additions & 4 deletions tests/cases/helpers/api_doc.test.php
Expand Up @@ -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
*
Expand All @@ -75,15 +76,15 @@ 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);

$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);
Expand Down
13 changes: 8 additions & 5 deletions views/helpers/api_doc.php
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 214511d

Please sign in to comment.