Permalink
Browse files

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

Test case added.
Refs #49
  • Loading branch information...
1 parent a0feb84 commit 325446a8b33732182d3eeddf112ad711bff426f1 @markstory markstory committed Aug 24, 2009
Showing with 42 additions and 13 deletions.
  1. +4 −1 cake/libs/view/view.php
  2. +38 −12 cake/tests/cases/libs/view/view.test.php
View
5 cake/libs/view/view.php
@@ -939,11 +939,14 @@ function _paths($plugin = null, $cached = true) {
}
$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
50 cake/tests/cases/libs/view/view.test.php
@@ -111,18 +111,6 @@ function _stop() {
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
*
* @param mixed $name
@@ -158,6 +146,18 @@ function loadHelpers(&$loaded, $helpers, $parent = null) {
}
/**
+ * 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
*
* @param mixed $method
@@ -295,6 +295,32 @@ function testPluginGetTemplate() {
}
/**
+ * 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.
*
* @return void

0 comments on commit 325446a

Please sign in to comment.