Updating View::_paths to remove an always miss file_exists() check.

Test case added.
Refs #49
This commit is contained in:
mark_story 2009-08-23 22:43:51 -04:00
parent a0feb84789
commit 325446a8b3
2 changed files with 42 additions and 13 deletions

View file

@ -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);

View file

@ -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.
*