Skip to content
This repository
Browse code

More work allowing assets in themes and plugins.

  • Loading branch information...
commit 49c11a821945513a5f8e44f52561ace6ba76e3c7 1 parent 0977029
Larry E. Masters authored
14  cake/dispatcher.php
@@ -637,10 +637,16 @@ function cached($url) {
637 637
 
638 638
 					if (strpos($plugin, '/') !== false) {
639 639
 						list($plugin, $theme) = explode('/', $plugin);
640  
-						$path = VIEWS . 'themed' . DS . $theme . DS . 'webroot' . DS;
641  
-						if ($plugin === 'theme' && (is_file($path . $url) && file_exists($path . $url))) {
642  
-							$assetFile = $path . $url;
643  
-							$matched = true;
  640
+						$themePaths = App::path('views');
  641
+						
  642
+						foreach ($themePaths as $viewPath) {
  643
+							$path = $viewPath . 'themed' . DS . $theme . DS . 'webroot' . DS;
  644
+							
  645
+							if ($plugin === 'theme' && (is_file($path . $url) && file_exists($path . $url))) {
  646
+								$assetFile = $path . $url;
  647
+								$matched = true;
  648
+								break;
  649
+							}
644 650
 						}
645 651
 					}
646 652
 
75  cake/tests/cases/dispatcher.test.php
@@ -1780,52 +1780,71 @@ function testStaticAssets() {
1780 1780
 
1781 1781
 		App::build(array(
1782 1782
 			'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
1783  
-			'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS)
  1783
+			'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
  1784
+			'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
1784 1785
 		));
1785  
-
1786 1786
 		$Dispatcher =& new TestDispatcher();
1787  
-/**
1788  
- * Removing assets in vendors so these 2 tests need to be removed
1789  
- *		Configure::write('debug', 0);
1790  
- *		ob_start();
1791  
- *		$Dispatcher->dispatch('img/test.jpg');
1792  
- *		$result = ob_get_clean();
1793  
- *		$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'img' . DS . 'test.jpg');
1794  
- *		$this->assertEqual($file, $result);
1795  
- *
1796  
- *
1797  
- *		Configure::write('debug', 0);
1798  
- *		$Dispatcher->params = $Dispatcher->parseParams('css/test_asset.css');
1799  
- *
1800  
- *		ob_start();
1801  
- *		$Dispatcher->cached('css/test_asset.css');
1802  
- *		$result = ob_get_clean();
1803  
- *		$this->assertEqual('this is the test asset css file', $result);
1804  
- */
1805  
-
  1787
+		$debug = Configure::read('debug');
  1788
+		Configure::write('debug', 0);
  1789
+		
  1790
+		ob_start();
  1791
+		$Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
  1792
+		$result = ob_get_clean();
  1793
+		$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');
  1794
+		$this->assertEqual($file, $result);
  1795
+		$this->assertEqual('this is just a test to load swf file from the theme.', $result);
  1796
+		
  1797
+		ob_start();
  1798
+		$Dispatcher->dispatch('theme/test_theme/pdfs/theme_test.pdf');
  1799
+		$result = ob_get_clean();
  1800
+		$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');
  1801
+		$this->assertEqual($file, $result);
  1802
+		$this->assertEqual('this is just a test to load pdf file from the theme.', $result);
  1803
+		
  1804
+		ob_start();
  1805
+		$Dispatcher->dispatch('theme/test_theme/img/test.jpg');
  1806
+		$result = ob_get_clean();
  1807
+		$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');
  1808
+		$this->assertEqual($file, $result);
  1809
+		
  1810
+		
  1811
+		$Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/css/test_asset.css');
  1812
+		ob_start();
  1813
+		$Dispatcher->cached('theme/test_theme/css/test_asset.css');
  1814
+		$result = ob_get_clean();
  1815
+		$this->assertEqual('this is the test asset css file', $result);
  1816
+		
  1817
+		ob_start();
  1818
+		$Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
  1819
+		$result = ob_get_clean();
  1820
+		$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');
  1821
+		$this->assertEqual($file, $result);
  1822
+		$this->assertEqual('this is just a test to load swf file from the plugin.', $result);
  1823
+	
  1824
+		ob_start();
  1825
+		$Dispatcher->dispatch('test_plugin/pdfs/plugin_test.pdf');
  1826
+		$result = ob_get_clean();
  1827
+		$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');
  1828
+		$this->assertEqual($file, $result);
  1829
+		 $this->assertEqual('this is just a test to load pdf file from the plugin.', $result);
  1830
+		
1806 1831
 		ob_start();
1807 1832
 		$Dispatcher->cached('test_plugin/js/test_plugin/test.js');
1808 1833
 		$result = ob_get_clean();
1809 1834
 		$this->assertEqual('alert("Test App");', $result);
1810 1835
 
1811  
-
1812  
-		Configure::write('debug', 0);
1813 1836
 		$Dispatcher->params = $Dispatcher->parseParams('test_plugin/js/test_plugin/test.js');
1814 1837
 		ob_start();
1815 1838
 		$Dispatcher->cached('test_plugin/js/test_plugin/test.js');
1816 1839
 		$result = ob_get_clean();
1817 1840
 		$this->assertEqual('alert("Test App");', $result);
1818 1841
 
1819  
-
1820  
-		Configure::write('debug', 0);
1821 1842
 		$Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
1822 1843
 		ob_start();
1823 1844
 		$Dispatcher->cached('test_plugin/css/test_plugin_asset.css');
1824 1845
 		$result = ob_get_clean();
1825 1846
 		$this->assertEqual('this is the test plugin asset css file', $result);
1826 1847
 
1827  
-
1828  
-		Configure::write('debug', 0);
1829 1848
 		$Dispatcher->params = $Dispatcher->parseParams('test_plugin/img/cake.icon.gif');
1830 1849
 		ob_start();
1831 1850
 		$Dispatcher->cached('test_plugin/img/cake.icon.gif');
@@ -1834,7 +1853,7 @@ function testStaticAssets() {
1834 1853
 		$this->assertEqual($file, $result);
1835 1854
 
1836 1855
 
1837  
-		Configure::write('debug', 2);
  1856
+		Configure::write('debug', $debug);
1838 1857
 		$Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
1839 1858
 		ob_start();
1840 1859
 		$Dispatcher->cached('plugin_js/js/plugin_js.js');
1  cake/tests/test_app/plugins/test_plugin/webroot/flash/plugin_test.swf
... ...
@@ -0,0 +1 @@
  1
+this is just a test to load swf file from the plugin.
1  cake/tests/test_app/plugins/test_plugin/webroot/pdfs/plugin_test.pdf
... ...
@@ -0,0 +1 @@
  1
+this is just a test to load pdf file from the plugin.
1  cake/tests/test_app/views/themed/test_theme/webroot/css/test_asset.css
... ...
@@ -0,0 +1 @@
  1
+this is the test asset css file
1  cake/tests/test_app/views/themed/test_theme/webroot/flash/theme_test.swf
... ...
@@ -0,0 +1 @@
  1
+this is just a test to load swf file from the theme.
BIN  cake/tests/test_app/views/themed/test_theme/webroot/img/test.jpg
1  cake/tests/test_app/views/themed/test_theme/webroot/pdfs/theme_test.pdf
... ...
@@ -0,0 +1 @@
  1
+this is just a test to load pdf file from the theme.

0 notes on commit 49c11a8

Please sign in to comment.
Something went wrong with that request. Please try again.