From 91f8e220e49889a82632d39f32a681b67cc5d6ad Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 30 Jun 2010 20:17:17 -0400 Subject: [PATCH] Adding App::themePath(). Will be used to reduce code duplication in a variety of places. --- cake/libs/configure.php | 19 ++++++++++++++++++- cake/tests/cases/libs/configure.test.php | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 956683fe81e..fc2f4eeda67 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -702,7 +702,7 @@ function build($paths = array(), $reset = false) { /** * Get the path that a plugin is on. Searches through the defined plugin paths. * - * @param string $plugin CamelCased plugin name to find the path of. + * @param string $plugin CamelCased/lower_cased plugin name to find the path of. * @return string full path to the plugin. */ function pluginPath($plugin) { @@ -716,6 +716,23 @@ function pluginPath($plugin) { return $_this->plugins[0] . $pluginDir . DS; } +/** + * Find the path that a theme is on. Search through the defined theme paths. + * + * @param string $theme lower_cased theme name to find the path of. + * @return string full path to the theme. + */ + function themePath($theme) { + $_this =& App::getInstance(); + $themeDir = 'themed' . DS . Inflector::underscore($theme); + for ($i = 0, $length = count($_this->views); $i < $length; $i++) { + if (is_dir($_this->views[$i] . $themeDir)) { + return $_this->views[$i] . $themeDir . DS ; + } + } + return $_this->views[0] . $themeDir . DS; + } + /** * Returns a key/value list of all paths where core libs are found. * Passing $type only returns the values for a given value of $key. diff --git a/cake/tests/cases/libs/configure.test.php b/cake/tests/cases/libs/configure.test.php index faa2551c390..ef7fdba20cf 100644 --- a/cake/tests/cases/libs/configure.test.php +++ b/cake/tests/cases/libs/configure.test.php @@ -460,6 +460,26 @@ function testPluginPath() { App::build(); } +/** + * test that pluginPath can find paths for plugins. + * + * @return void + */ + function testThemePath() { + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS) + )); + $path = App::themePath('test_theme'); + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS; + $this->assertEqual($path, $expected); + + $path = App::themePath('TestTheme'); + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS; + $this->assertEqual($path, $expected); + + App::build(); + } + /** * testClassLoading method *