Skip to content

Commit 31ec714

Browse files
committed
Adding View::_paths() optimization.
Test cases added. Refs #49
1 parent e9cfb66 commit 31ec714

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

cake/libs/view/view.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,14 @@ function _paths($plugin = null, $cached = true) {
895895
}
896896
$paths = array();
897897
$viewPaths = Configure::read('viewPaths');
898+
$corePaths = array_flip(Configure::corePaths('view'));
898899

899900
if (!empty($plugin)) {
900901
$count = count($viewPaths);
901902
for ($i = 0; $i < $count; $i++) {
902-
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
903+
if (!isset($corePaths[$viewPaths[$i]])) {
904+
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
905+
}
903906
}
904907
$pluginPaths = Configure::read('pluginPaths');
905908
$count = count($pluginPaths);

cake/tests/cases/libs/view/view.test.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ function getLayoutFileName($name = null) {
143143
function loadHelpers(&$loaded, $helpers, $parent = null) {
144144
return $this->_loadHelpers($loaded, $helpers, $parent);
145145
}
146+
/**
147+
* paths method
148+
*
149+
* @param string $plugin
150+
* @param boolean $cached
151+
* @access public
152+
* @return void
153+
*/
154+
function paths($plugin = null, $cached = true) {
155+
return $this->_paths($plugin, $cached);
156+
}
157+
146158
/**
147159
* cakeError method
148160
*
@@ -237,7 +249,10 @@ function testPluginGetTemplate() {
237249

238250
$View = new TestView($this->Controller);
239251
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
240-
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
252+
Configure::write('viewPaths', array(
253+
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS,
254+
TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS,
255+
));
241256

242257
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS .'tests' . DS .'index.ctp';
243258
$result = $View->getViewFileName('index');
@@ -247,6 +262,36 @@ function testPluginGetTemplate() {
247262
$result = $View->getLayoutFileName();
248263
$this->assertEqual($result, $expected);
249264
}
265+
/**
266+
* test that plugin/$plugin_name is only appended to the paths it should be.
267+
*
268+
* @return void
269+
**/
270+
function testPluginPathGeneration() {
271+
$this->Controller->plugin = 'test_plugin';
272+
$this->Controller->name = 'TestPlugin';
273+
$this->Controller->viewPath = 'tests';
274+
$this->Controller->action = 'index';
275+
276+
Configure::write('viewPaths', array(
277+
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS,
278+
TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS,
279+
));
280+
281+
$View = new TestView($this->Controller);
282+
$paths = $View->paths();
283+
$this->assertEqual($paths, Configure::read('viewPaths'));
284+
285+
$paths = $View->paths('test_plugin');
286+
$expected = array(
287+
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'plugins' . DS . 'test_plugin' . DS,
288+
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'views' . DS,
289+
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS,
290+
TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS
291+
);
292+
$this->assertEqual($paths, $expected);
293+
}
294+
250295
/**
251296
* test that CamelCase plugins still find their view files.
252297
*

0 commit comments

Comments
 (0)