From 325446a8b33732182d3eeddf112ad711bff426f1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 23 Aug 2009 22:43:51 -0400 Subject: [PATCH] Updating View::_paths to remove an always miss file_exists() check. Test case added. Refs #49 --- cake/libs/view/view.php | 5 ++- cake/tests/cases/libs/view/view.test.php | 50 ++++++++++++++++++------ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 22d98045f..25aa8e045 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -939,11 +939,14 @@ class View extends Object { } $paths = array(); $viewPaths = App::path('views'); + $corePaths = array_flip(App::core('views')); if (!empty($plugin)) { $count = count($viewPaths); for ($i = 0; $i < $count; $i++) { - $paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS; + if (!isset($corePaths[$viewPaths[$i]])) { + $paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS; + } } $pluginPaths = App::path('plugins'); $count = count($pluginPaths); diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 562aff8d3..d793b86d9 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -110,18 +110,6 @@ class ViewTestErrorHandler extends ErrorHandler { */ class TestView extends View { -/** - * renderElement method - * - * @param mixed $name - * @param array $params - * @access public - * @return void - */ - function renderElement($name, $params = array()) { - return $name; - } - /** * getViewFileName method * @@ -157,6 +145,18 @@ class TestView extends View { return $this->_loadHelpers($loaded, $helpers, $parent); } +/** + * paths method + * + * @param string $plugin + * @param boolean $cached + * @access public + * @return void + */ + function paths($plugin = null, $cached = true) { + return $this->_paths($plugin, $cached); + } + /** * cakeError method * @@ -294,6 +294,32 @@ class ViewTest extends CakeTestCase { $this->assertEqual($result, $expected); } +/** + * test that plugin/$plugin_name is only appended to the paths it should be. + * + * @return void + **/ + function testPluginPathGeneration() { + $this->Controller->plugin = 'test_plugin'; + $this->Controller->name = 'TestPlugin'; + $this->Controller->viewPath = 'tests'; + $this->Controller->action = 'index'; + + $View = new TestView($this->Controller); + $paths = $View->paths(); + $this->assertEqual($paths, App::path('views')); + + $paths = $View->paths('test_plugin'); + + $expected = array( + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'plugins' . DS . 'test_plugin' . DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'views' . DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS, + TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS + ); + $this->assertEqual($paths, $expected); + } + /** * test that CamelCase plugins still find their view files. *