Permalink
Browse files

Adding View::_paths() optimization.

Test cases added.
Refs #49
  • Loading branch information...
1 parent e9cfb66 commit 31ec714e2eb322ecfcc45fa4a2aeb2cfa1f479d8 @markstory markstory committed Aug 24, 2009
Showing with 50 additions and 2 deletions.
  1. +4 −1 cake/libs/view/view.php
  2. +46 −1 cake/tests/cases/libs/view/view.test.php
View
5 cake/libs/view/view.php
@@ -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);
View
47 cake/tests/cases/libs/view/view.test.php
@@ -144,6 +144,18 @@ 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
*
* @param mixed $method
@@ -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');
@@ -248,6 +263,36 @@ function testPluginGetTemplate() {
$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.
*
* @return void

0 comments on commit 31ec714

Please sign in to comment.