From 31ed8c3eea630153bcd30885aeeb08de852909a8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 14 Jul 2014 23:29:13 -0400 Subject: [PATCH] Fix relative path resolution in View. 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 --- src/View/View.php | 2 +- tests/TestCase/View/ViewTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/View/View.php b/src/View/View.php index 547c2325800..5537fa7b7f9 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -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; } diff --git a/tests/TestCase/View/ViewTest.php b/tests/TestCase/View/ViewTest.php index efe748f0c98..55f8732c0c4 100644 --- a/tests/TestCase/View/ViewTest.php +++ b/tests/TestCase/View/ViewTest.php @@ -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); @@ -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); }