Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More work allowing assets in themes and plugins.

  • Loading branch information...
commit 49c11a821945513a5f8e44f52561ace6ba76e3c7 1 parent 0977029
@phpnut phpnut authored
View
14 cake/dispatcher.php
@@ -637,10 +637,16 @@ function cached($url) {
if (strpos($plugin, '/') !== false) {
list($plugin, $theme) = explode('/', $plugin);
- $path = VIEWS . 'themed' . DS . $theme . DS . 'webroot' . DS;
- if ($plugin === 'theme' && (is_file($path . $url) && file_exists($path . $url))) {
- $assetFile = $path . $url;
- $matched = true;
+ $themePaths = App::path('views');
+
+ foreach ($themePaths as $viewPath) {
+ $path = $viewPath . 'themed' . DS . $theme . DS . 'webroot' . DS;
+
+ if ($plugin === 'theme' && (is_file($path . $url) && file_exists($path . $url))) {
+ $assetFile = $path . $url;
+ $matched = true;
+ break;
+ }
}
}
View
75 cake/tests/cases/dispatcher.test.php
@@ -1780,52 +1780,71 @@ function testStaticAssets() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
- 'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS)
+ 'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
+ 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
-
$Dispatcher =& new TestDispatcher();
-/**
- * Removing assets in vendors so these 2 tests need to be removed
- * Configure::write('debug', 0);
- * ob_start();
- * $Dispatcher->dispatch('img/test.jpg');
- * $result = ob_get_clean();
- * $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'img' . DS . 'test.jpg');
- * $this->assertEqual($file, $result);
- *
- *
- * Configure::write('debug', 0);
- * $Dispatcher->params = $Dispatcher->parseParams('css/test_asset.css');
- *
- * ob_start();
- * $Dispatcher->cached('css/test_asset.css');
- * $result = ob_get_clean();
- * $this->assertEqual('this is the test asset css file', $result);
- */
-
+ $debug = Configure::read('debug');
+ Configure::write('debug', 0);
+
+ ob_start();
+ $Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
+ $result = ob_get_clean();
+ $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'flash' . DS . 'theme_test.swf');
+ $this->assertEqual($file, $result);
+ $this->assertEqual('this is just a test to load swf file from the theme.', $result);
+
+ ob_start();
+ $Dispatcher->dispatch('theme/test_theme/pdfs/theme_test.pdf');
+ $result = ob_get_clean();
+ $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'pdfs' . DS . 'theme_test.pdf');
+ $this->assertEqual($file, $result);
+ $this->assertEqual('this is just a test to load pdf file from the theme.', $result);
+
+ ob_start();
+ $Dispatcher->dispatch('theme/test_theme/img/test.jpg');
+ $result = ob_get_clean();
+ $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
+ $this->assertEqual($file, $result);
+
+
+ $Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/css/test_asset.css');
+ ob_start();
+ $Dispatcher->cached('theme/test_theme/css/test_asset.css');
+ $result = ob_get_clean();
+ $this->assertEqual('this is the test asset css file', $result);
+
+ ob_start();
+ $Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
+ $result = ob_get_clean();
+ $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'flash' . DS . 'plugin_test.swf');
+ $this->assertEqual($file, $result);
+ $this->assertEqual('this is just a test to load swf file from the plugin.', $result);
+
+ ob_start();
+ $Dispatcher->dispatch('test_plugin/pdfs/plugin_test.pdf');
+ $result = ob_get_clean();
+ $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'pdfs' . DS . 'plugin_test.pdf');
+ $this->assertEqual($file, $result);
+ $this->assertEqual('this is just a test to load pdf file from the plugin.', $result);
+
ob_start();
$Dispatcher->cached('test_plugin/js/test_plugin/test.js');
$result = ob_get_clean();
$this->assertEqual('alert("Test App");', $result);
-
- Configure::write('debug', 0);
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/js/test_plugin/test.js');
ob_start();
$Dispatcher->cached('test_plugin/js/test_plugin/test.js');
$result = ob_get_clean();
$this->assertEqual('alert("Test App");', $result);
-
- Configure::write('debug', 0);
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
ob_start();
$Dispatcher->cached('test_plugin/css/test_plugin_asset.css');
$result = ob_get_clean();
$this->assertEqual('this is the test plugin asset css file', $result);
-
- Configure::write('debug', 0);
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/img/cake.icon.gif');
ob_start();
$Dispatcher->cached('test_plugin/img/cake.icon.gif');
@@ -1834,7 +1853,7 @@ function testStaticAssets() {
$this->assertEqual($file, $result);
- Configure::write('debug', 2);
+ Configure::write('debug', $debug);
$Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
ob_start();
$Dispatcher->cached('plugin_js/js/plugin_js.js');
View
1  cake/tests/test_app/plugins/test_plugin/webroot/flash/plugin_test.swf
@@ -0,0 +1 @@
+this is just a test to load swf file from the plugin.
View
BIN  cake/tests/test_app/plugins/test_plugin/webroot/pdfs/plugin_test.pdf
Binary file not shown
View
1  cake/tests/test_app/views/themed/test_theme/webroot/css/test_asset.css
@@ -0,0 +1 @@
+this is the test asset css file
View
1  cake/tests/test_app/views/themed/test_theme/webroot/flash/theme_test.swf
@@ -0,0 +1 @@
+this is just a test to load swf file from the theme.
View
BIN  cake/tests/test_app/views/themed/test_theme/webroot/img/test.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  cake/tests/test_app/views/themed/test_theme/webroot/pdfs/theme_test.pdf
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.