From b8814ff39b3b9af796faef38e1f2a18c84df250c Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 17 Oct 2012 20:28:43 -0400 Subject: [PATCH] Remove support for asset filters. Remove support for Asset.filter.css and Asset.filter.js. Both of these features were never fully implemented by CakePHP. Asset filtering is now easily accomplished using the Dispatcher filters/middleware system as well. Refs #3279 --- lib/Cake/Routing/Filter/AssetDispatcher.php | 41 --------------- .../Test/TestCase/Routing/DispatcherTest.php | 19 ------- .../Routing/Filter/AssetDispatcherTest.php | 52 ------------------- .../TestCase/View/Helper/HtmlHelperTest.php | 38 -------------- lib/Cake/View/Helper/HtmlHelper.php | 11 ---- 5 files changed, 161 deletions(-) diff --git a/lib/Cake/Routing/Filter/AssetDispatcher.php b/lib/Cake/Routing/Filter/AssetDispatcher.php index 494d1cf76ed..ecec0ba0a95 100644 --- a/lib/Cake/Routing/Filter/AssetDispatcher.php +++ b/lib/Cake/Routing/Filter/AssetDispatcher.php @@ -48,11 +48,6 @@ public function beforeDispatch($event) { return; } - if ($result = $this->_filterAsset($event)) { - $event->stopPropagation(); - return $result; - } - $assetFile = $this->_getAssetFile($url); if ($assetFile === null || !file_exists($assetFile)) { return null; @@ -72,42 +67,6 @@ public function beforeDispatch($event) { return $response; } -/** - * Checks if the client is requesting a filtered asset and runs the corresponding - * filter if any is configured - * - * @param Cake\Event\Event $event containing the request and response object - * @return Cake\Network\Response if the client is requesting a recognized asset, null otherwise - */ - protected function _filterAsset($event) { - $url = $event->data['request']->url; - $response = $event->data['response']; - $filters = Configure::read('Asset.filter'); - $isCss = ( - strpos($url, 'ccss/') === 0 || - preg_match('#^(theme/([^/]+)/ccss/)|(([^/]+)(?statusCode(404); - return $response; - } - - if ($isCss) { - include WWW_ROOT . DS . $filters['css']; - return $response; - } - - if ($isJs) { - include WWW_ROOT . DS . $filters['js']; - return $response; - } - } - /** * Builds asset file path based off url * diff --git a/lib/Cake/Test/TestCase/Routing/DispatcherTest.php b/lib/Cake/Test/TestCase/Routing/DispatcherTest.php index c9a9041df5d..0a7af5aa9d8 100644 --- a/lib/Cake/Test/TestCase/Routing/DispatcherTest.php +++ b/lib/Cake/Test/TestCase/Routing/DispatcherTest.php @@ -913,25 +913,6 @@ public function testAsset($url, $file) { $this->assertEquals($expected, $headers['Content-Length']); } -/** - * test that missing asset processors trigger a 404 with no response body. - * - * @return void - */ - public function testMissingAssetProcessor404() { - $response = $this->getMock('Cake\Network\Response', array('send')); - $Dispatcher = new TestDispatcher(); - Configure::write('Asset.filter', array( - 'js' => '', - 'css' => null - )); - Configure::write('Dispatcher.filters', array('AssetDispatcher')); - - $request = new Request('ccss/cake.generic.css'); - $Dispatcher->dispatch($request, $response); - $this->assertEquals('404', $response->statusCode()); - } - /** * Data provider for cached actions. * diff --git a/lib/Cake/Test/TestCase/Routing/Filter/AssetDispatcherTest.php b/lib/Cake/Test/TestCase/Routing/Filter/AssetDispatcherTest.php index 53428313109..463ac8b854f 100644 --- a/lib/Cake/Test/TestCase/Routing/Filter/AssetDispatcherTest.php +++ b/lib/Cake/Test/TestCase/Routing/Filter/AssetDispatcherTest.php @@ -33,54 +33,6 @@ public function tearDown() { Configure::write('Dispatcher.filters', array()); } -/** - * test that asset filters work for theme and plugin assets - * - * @return void - */ - public function testAssetFilterForThemeAndPlugins() { - $filter = new AssetDispatcher(); - $response = $this->getMock('Cake\Network\Response', array('_sendHeader')); - Configure::write('Asset.filter', array( - 'js' => '', - 'css' => '' - )); - App::build(array( - 'Plugin' => array(CAKE . 'Test/TestApp/Plugin/'), - 'View' => array(CAKE . 'Test/TestApp/View/') - ), APP::RESET); - - $request = new Request('theme/test_theme/ccss/cake.generic.css'); - $event = new Event('DispatcherTest', $this, compact('request', 'response')); - $this->assertSame($response, $filter->beforeDispatch($event)); - $this->assertTrue($event->isStopped()); - - $request = new Request('theme/test_theme/cjs/debug_kit.js'); - $event = new Event('DispatcherTest', $this, compact('request', 'response')); - $this->assertSame($response, $filter->beforeDispatch($event)); - $this->assertTrue($event->isStopped()); - - $request = new Request('test_plugin/ccss/cake.generic.css'); - $event = new Event('DispatcherTest', $this, compact('request', 'response')); - $this->assertSame($response, $filter->beforeDispatch($event)); - $this->assertTrue($event->isStopped()); - - $request = new Request('test_plugin/cjs/debug_kit.js'); - $event = new Event('DispatcherTest', $this, compact('request', 'response')); - $this->assertSame($response, $filter->beforeDispatch($event)); - $this->assertTrue($event->isStopped()); - - $request = new Request('css/ccss/debug_kit.css'); - $event = new Event('DispatcherTest', $this, compact('request', 'response')); - $this->assertNull($filter->beforeDispatch($event)); - $this->assertFalse($event->isStopped()); - - $request = new Request('js/cjs/debug_kit.js'); - $event = new Event('DispatcherTest', $this, compact('request', 'response')); - $this->assertNull($filter->beforeDispatch($event)); - $this->assertFalse($event->isStopped()); - } - /** * Tests that $response->checkNotModified() is called and bypasses * file dispatching @@ -89,10 +41,6 @@ public function testAssetFilterForThemeAndPlugins() { */ public function testNotModified() { $filter = new AssetDispatcher(); - Configure::write('Asset.filter', array( - 'js' => '', - 'css' => '' - )); App::build(array( 'Plugin' => array(CAKE . 'Test/TestApp/Plugin/'), 'View' => array(CAKE . 'Test/TestApp/View/') diff --git a/lib/Cake/Test/TestCase/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/TestCase/View/Helper/HtmlHelperTest.php index 143a9568515..4b3edc77b57 100644 --- a/lib/Cake/Test/TestCase/View/Helper/HtmlHelperTest.php +++ b/lib/Cake/Test/TestCase/View/Helper/HtmlHelperTest.php @@ -527,8 +527,6 @@ public function testStyle() { * @return void */ public function testCssLink() { - Configure::write('Asset.filter.css', false); - $result = $this->Html->css('screen'); $expected = array( 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/') @@ -560,17 +558,10 @@ public function testCssLink() { $expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/'; $this->assertTags($result, $expected); - Configure::write('Asset.filter.css', 'css.php'); - $result = $this->Html->css('cake.generic'); - $expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/'; - $this->assertTags($result, $expected); - $result = $this->Html->css('//example.com/css/cake.generic.css'); $expected['link']['href'] = 'preg:/.*example\.com\/css\/cake\.generic\.css/'; $this->assertTags($result, $expected); - Configure::write('Asset.filter.css', false); - $result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic')))); $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/'; $this->assertTags($result[0], $expected); @@ -599,7 +590,6 @@ public function testCssLink() { * @return void */ public function testPluginCssLink() { - Configure::write('Asset.filter.css', false); Plugin::load('TestPlugin'); $result = $this->Html->css('TestPlugin.test_plugin_asset'); @@ -619,13 +609,6 @@ public function testPluginCssLink() { $expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?1234/'; $this->assertTags($result, $expected); - Configure::write('Asset.filter.css', 'css.php'); - $result = $this->Html->css('TestPlugin.test_plugin_asset'); - $expected['link']['href'] = 'preg:/.*test_plugin\/ccss\/test_plugin_asset\.css/'; - $this->assertTags($result, $expected); - - Configure::write('Asset.filter.css', false); - $result = explode("\n", trim($this->Html->css(array('TestPlugin.test_plugin_asset', 'TestPlugin.vendor.generic')))); $expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css/'; $this->assertTags($result[0], $expected); @@ -944,27 +927,6 @@ public function testScriptWithBlocks() { $this->assertNull($result); } -/** - * Test that Asset.filter.js works. - * - * @return void - */ - public function testScriptAssetFilter() { - Configure::write('Asset.filter.js', 'js.php'); - - $result = $this->Html->script('jquery-1.3'); - $expected = array( - 'script' => array('type' => 'text/javascript', 'src' => 'cjs/jquery-1.3.js') - ); - $this->assertTags($result, $expected); - - $result = $this->Html->script('//example.com/js/jquery-1.3.js'); - $expected = array( - 'script' => array('type' => 'text/javascript', 'src' => '//example.com/js/jquery-1.3.js') - ); - $this->assertTags($result, $expected); - } - /** * test a script file in the webroot/theme dir. * diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 0e6dee9f3d5..fe77265c41f 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -435,13 +435,6 @@ public function css($path, $rel = null, $options = array()) { $url = $path; } else { $url = $this->assetUrl($path, $options + array('pathPrefix' => CSS_URL, 'ext' => '.css')); - - if (Configure::read('Asset.filter.css')) { - $pos = strpos($url, CSS_URL); - if ($pos !== false) { - $url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(CSS_URL)); - } - } } if ($rel == 'import') { @@ -529,10 +522,6 @@ public function script($url, $options = array()) { if (strpos($url, '//') === false) { $url = $this->assetUrl($url, $options + array('pathPrefix' => JS_URL, 'ext' => '.js')); - - if (Configure::read('Asset.filter.js')) { - $url = str_replace(JS_URL, 'cjs/', $url); - } } $attributes = $this->_parseAttributes($options, array('block', 'once'), ' '); $out = sprintf($this->_tags['javascriptlink'], $url, $attributes);