Skip to content
Permalink
Browse files

Fix asset delivery for vendor namespaced plugins.

Search up to two directories for plugin names as people will often use
vendor namespaced plugins and AssetFilter should handle that scenario.

Fixes #4616
  • Loading branch information...
markstory committed Sep 17, 2014
1 parent cca12c5 commit 7a72c8db1ba62e0ca5aa0d2648136ca2c307f15e
Showing with 17 additions and 9 deletions.
  1. +10 −6 src/Routing/Filter/AssetFilter.php
  2. +7 −3 tests/TestCase/Routing/Filter/AssetFilterTest.php
@@ -78,12 +78,16 @@ public function beforeDispatch(Event $event) {
*/
protected function _getAssetFile($url) {
$parts = explode('/', $url);
$plugin = Inflector::camelize($parts[0]);
if ($plugin && Plugin::loaded($plugin)) {
unset($parts[0]);
$fileFragment = implode(DS, $parts);
$pluginWebroot = Plugin::path($plugin) . 'webroot' . DS;
return $pluginWebroot . $fileFragment;
$pluginPart = [];
for ($i = 0; $i < 2; $i++) {
$pluginPart[] = Inflector::camelize($parts[$i]);
$plugin = implode('/', $pluginPart);
if ($plugin && Plugin::loaded($plugin)) {
$parts = array_slice($parts, $i + 1);
$fileFragment = implode(DS, $parts);
$pluginWebroot = Plugin::path($plugin) . 'webroot' . DS;
return $pluginWebroot . $fileFragment;
}
}
}
@@ -203,26 +203,30 @@ public static function assetProvider() {
'test_plugin/css/theme_one.htc',
'Plugin/TestPlugin/webroot/css/theme_one.htc'
),
array(
'company/test_plugin_three/css/company.css',
'Plugin/Company/TestPluginThree/webroot/css/company.css'
),
);
}
/**
* Test assets
*
* @dataProvider assetProvider
* @outputBuffering enabled
* @return void
*/
public function testAsset($url, $file) {
Plugin::load(array('TestPlugin', 'PluginJs'));
Plugin::load(array('Company/TestPluginThree', 'TestPlugin', 'PluginJs'));
$filter = new AssetFilter();
$response = $this->getMock('Cake\Network\Response', array('_sendHeader'));
$request = new Request($url);
$event = new Event('Dispatcher.beforeDispatch', $this, compact('request', 'response'));
$filter->beforeDispatch($event);
$result = ob_get_clean();
$result = ob_get_contents();
ob_end_clean();
$path = TEST_APP . str_replace('/', DS, $file);
$file = file_get_contents($path);

0 comments on commit 7a72c8d

Please sign in to comment.
You can’t perform that action at this time.