/** * 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()); }
/** * 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()); }