예제 #1
0
 /**
  * Builds asset file path based off url
  *
  * @param string $url URL
  * @return string|null Absolute path for asset file
  */
 protected function _getAssetFile($url)
 {
     $path = parent::_getAssetFile($url);
     if (!empty($path)) {
         return $path;
     }
     $parts = explode('/', $url);
     $fileFragment = implode(DS, $parts);
     $path = BASER_WEBROOT;
     if (file_exists($path . $fileFragment)) {
         return $path . $fileFragment;
     }
     return null;
 }
예제 #2
0
 /**
  * Tests that $response->checkNotModified() is called and bypasses
  * file dispatching
  *
  * @return void
  */
 public function testNotModified()
 {
     $filter = new AssetDispatcher();
     Configure::write('Asset.filter', array('js' => '', 'css' => ''));
     App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS), 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $time = filemtime(App::themePath('TestTheme') . 'webroot' . DS . 'img' . DS . 'cake.power.gif');
     $time = new DateTime('@' . $time);
     $response = $this->getMock('CakeResponse', array('send', 'checkNotModified'));
     $request = new CakeRequest('theme/test_theme/img/cake.power.gif');
     $response->expects($this->once())->method('checkNotModified')->with($request)->will($this->returnValue(true));
     $event = new CakeEvent('DispatcherTest', $this, compact('request', 'response'));
     ob_start();
     $this->assertSame($response, $filter->beforeDispatch($event));
     ob_end_clean();
     $this->assertEquals(200, $response->statusCode());
     $this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
     $response = $this->getMock('CakeResponse', array('_sendHeader', 'checkNotModified'));
     $request = new CakeRequest('theme/test_theme/img/cake.power.gif');
     $response->expects($this->once())->method('checkNotModified')->with($request)->will($this->returnValue(true));
     $response->expects($this->never())->method('send');
     $event = new CakeEvent('DispatcherTest', $this, compact('request', 'response'));
     $this->assertSame($response, $filter->beforeDispatch($event));
     $this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
 }
예제 #3
0
 /**
  * Builds asset file path based off url
  *
  * @param string $url
  * @return string Absolute path for asset file
  */
 protected function _getAssetFile($url)
 {
     $parts = explode('/', $url);
     // start zuha addition
     $path = App::themePath($parts[1]) . 'webroot' . DS;
     $fileFragment = urldecode(implode(DS, $parts));
     if (file_exists($path . $fileFragment)) {
         return $path . $fileFragment;
     }
     // copied directly from Cake/Routing/Filter/AssetDispatcher.php
     $parts = explode('/', $url);
     if ($parts[0] === 'theme') {
         $themeName = $parts[1];
         unset($parts[0], $parts[1]);
         $fileFragment = implode(DS, $parts);
         $path = App::themePath($themeName) . 'webroot' . DS;
         return str_replace('//', '/', $path . $fileFragment);
         // and added this one fix
     }
     return parent::_getAssetFile($url);
 }
 /**
  * Test that attempts to traverse directories with urlencoded paths fail.
  *
  * @return void
  */
 public function test404OnDoubleDotEncoded()
 {
     App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS), 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)), App::RESET);
     $response = $this->getMock('CakeResponse', array('_sendHeader', 'send'));
     $request = new CakeRequest('theme/test_theme/%2e./%2e./%2e./%2e./%2e./%2e./VERSION.txt');
     $event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response'));
     $response->expects($this->never())->method('send');
     $filter = new AssetDispatcher();
     $this->assertNull($filter->beforeDispatch($event));
     $this->assertFalse($event->isStopped());
 }
 /**
  * Test asset content length is unset
  *
  * If content length is unset, then the webserver can figure it out.
  *
  * @outputBuffering enabled
  * @return void
  */
 public function testAssetContentLength()
 {
     Router::reload();
     Configure::write('Dispatcher.filters', array('AssetDispatcher'));
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $url = 'theme/test_theme/css/test_asset.css';
     $file = 'View/Themed/TestTheme/webroot/css/test_asset.css';
     $request = new CakeRequest($url);
     $response = $this->getMock('CakeResponse', array('_sendHeader', 'send'));
     $event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response'));
     $filter = new AssetDispatcher();
     $filter->beforeDispatch($event);
     $result = ob_get_clean();
     $path = CAKE . 'Test' . DS . 'test_app' . DS . str_replace('/', DS, $file);
     $file = file_get_contents($path);
     $this->assertEquals($file, $result);
     $headers = $response->header();
     $this->assertFalse($headers['Content-Length']);
 }
 /**
  * Test that no exceptions are thrown for //index.php type urls.
  *
  * @return void
  */
 public function test404OnDoubleSlash()
 {
     $filter = new AssetDispatcher();
     $response = $this->getMock('CakeResponse', array('_sendHeader'));
     $request = new CakeRequest('//index.php');
     $event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response'));
     $this->assertNull($filter->beforeDispatch($event));
     $this->assertFalse($event->isStopped());
 }