Skip to content

Commit

Permalink
Adding View::_paths() optimization.
Browse files Browse the repository at this point in the history
Test cases added.
Refs #49
  • Loading branch information
markstory committed Aug 24, 2009
1 parent e9cfb66 commit 31ec714
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cake/libs/view/view.php
Expand Up @@ -895,11 +895,14 @@ function _paths($plugin = null, $cached = true) {
}
$paths = array();
$viewPaths = Configure::read('viewPaths');
$corePaths = array_flip(Configure::corePaths('view'));

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 = Configure::read('pluginPaths');
$count = count($pluginPaths);
Expand Down
47 changes: 46 additions & 1 deletion cake/tests/cases/libs/view/view.test.php
Expand Up @@ -143,6 +143,18 @@ function getLayoutFileName($name = null) {
function loadHelpers(&$loaded, $helpers, $parent = null) {
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
*
Expand Down Expand Up @@ -237,7 +249,10 @@ function testPluginGetTemplate() {

$View = new TestView($this->Controller);
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
Configure::write('viewPaths', array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS,
TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS,
));

$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS .'tests' . DS .'index.ctp';
$result = $View->getViewFileName('index');
Expand All @@ -247,6 +262,36 @@ function testPluginGetTemplate() {
$result = $View->getLayoutFileName();
$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';

Configure::write('viewPaths', array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS,
TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS,
));

$View = new TestView($this->Controller);
$paths = $View->paths();
$this->assertEqual($paths, Configure::read('viewPaths'));

$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.
*
Expand Down

0 comments on commit 31ec714

Please sign in to comment.