Skip to content

Commit

Permalink
Fix relative path resolution in View.
Browse files Browse the repository at this point in the history
Relative paths in view file names where handled very poorly before when
subdirectories were involved. This was not very important in 2.x but is
more important for 3.x as we have Cells and relative paths should work
properly there.

Refs #3945
  • Loading branch information
markstory committed Jul 16, 2014
1 parent 4733a8e commit 31ed8c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/View/View.php
Expand Up @@ -851,7 +851,7 @@ protected function _getViewFileName($name = null) {
}
$name = trim($name, DS);
} elseif ($name[0] === '.') {
$name = substr($name, 3);
$name = $this->viewPath . DS . $subDir . $name;
} elseif (!$plugin || $this->viewPath !== $this->name) {
$name = $this->viewPath . DS . $subDir . $name;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/View/ViewTest.php
Expand Up @@ -492,7 +492,7 @@ public function testGetViewFileNames() {
$result = $View->getViewFileName('/Posts/index');
$this->assertPathEquals($expected, $result);

$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Posts' . DS . 'index.ctp';
$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Pages' . DS . '..' . DS . 'Posts' . DS . 'index.ctp';
$result = $View->getViewFileName('../Posts/index');
$this->assertPathEquals($expected, $result);

Expand Down Expand Up @@ -1127,7 +1127,7 @@ public function testViewFileName() {
$result = $View->getViewFileName('../Element/test_element');
$this->assertRegExp('/Element(\/|\\\)test_element.ctp/', $result);

$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Posts' . DS . 'index.ctp';
$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Posts' . DS . '..' . DS . 'Posts' . DS . 'index.ctp';
$result = $View->getViewFileName('../Posts/index');
$this->assertPathEquals($expected, $result);
}
Expand Down

0 comments on commit 31ed8c3

Please sign in to comment.