Skip to content
Permalink
Browse files

Deprecated MediaView and updated MediaView::render() to use CakeRespo…

…nse::file()
  • Loading branch information...
ADmad committed Jul 10, 2012
1 parent c5d1260 commit 69eba678f49e804846191d884d3e6ed761c4b447
Showing with 86 additions and 281 deletions.
  1. +71 −133 lib/Cake/Test/Case/View/MediaViewTest.php
  2. +15 −148 lib/Cake/View/MediaView.php
@@ -35,8 +35,15 @@ class MediaViewTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->MediaView = $this->getMock('MediaView', array('_isActive', '_clearBuffer', '_flushBuffer'));
$this->MediaView->response = $this->getMock('CakeResponse');
$this->MediaView = new MediaView();
$this->MediaView->response = $this->getMock('CakeResponse', array(
'_isActive',
'_clearBuffer',
'_flushBuffer',
'type',
'header',
'download'
));
}
/**
@@ -71,10 +78,10 @@ public function testRenderNotFound() {
public function testRender() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
'id' => 'test_asset.css'
);
$this->MediaView->expects($this->exactly(2))
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
@@ -83,23 +90,23 @@ public function testRender() {
->with('css')
->will($this->returnArgument(0));
$this->MediaView->response->expects($this->at(1))
$this->MediaView->response->expects($this->at(0))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
'Last-Modified' => gmdate('D, d M Y H:i:s', time()) . ' GMT'
));
$this->MediaView->response->expects($this->at(2))
->method('header')
->with(array(
'Content-Length' => 31
));
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
->with('Content-Length', 31);
$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
@@ -118,25 +125,20 @@ public function testRenderWithUnknownFileTypeGeneric() {
$_SERVER['HTTP_USER_AGENT'] = 'Some generic browser';
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
'id' => 'no_section.ini'
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->exactly(1))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
$this->MediaView->response->expects($this->at(0))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
'Last-Modified' => gmdate('D, d M Y H:i:s', time()) . ' GMT'
));
$this->MediaView->response->expects($this->once())
@@ -145,17 +147,17 @@ public function testRenderWithUnknownFileTypeGeneric() {
$this->MediaView->response->expects($this->at(3))
->method('header')
->with(array(
'Accept-Ranges' => 'bytes'
));
->with('Accept-Ranges', 'bytes');
$this->MediaView->response->expects($this->at(4))
->method('header')
->with('Content-Length', 35);
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
@@ -178,48 +180,43 @@ public function testRenderWithUnknownFileTypeOpera() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->at(0))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
'Last-Modified' => gmdate('D, d M Y H:i:s', time()) . ' GMT'
));
$this->MediaView->response->expects($this->at(1))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(2))
->method('type')
->with('application/octetstream')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())
$this->MediaView->response->expects($this->at(3))
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->at(4))
->method('header')
->with(array(
'Accept-Ranges' => 'bytes'
));
->with('Accept-Ranges', 'bytes');
$this->MediaView->response->expects($this->at(5))
->method('header')
->with('Content-Length', 35);
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
@@ -242,49 +239,44 @@ public function testRenderWithUnknownFileTypeIE() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
'name' => 'config'
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->at(0))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
'Last-Modified' => gmdate('D, d M Y H:i:s', time()) . ' GMT'
));
$this->MediaView->response->expects($this->at(1))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(2))
->method('type')
->with('application/force-download')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())
$this->MediaView->response->expects($this->at(3))
->method('download')
->with('config.ini');
$this->MediaView->response->expects($this->at(4))
->method('header')
->with(array(
'Accept-Ranges' => 'bytes'
));
->with('Accept-Ranges', 'bytes');
$this->MediaView->response->expects($this->at(5))
->method('header')
->with('Content-Length', 35);
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
@@ -296,29 +288,6 @@ public function testRenderWithUnknownFileTypeIE() {
}
}
/**
* testConnectionAborted method
*
* @return void
*/
public function testConnectionAborted() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
);
$this->MediaView->expects($this->once())
->method('_isActive')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->never())
->method('type');
$result = $this->MediaView->render();
$this->assertFalse($result);
}
/**
* testConnectionAbortedOnBuffering method
*
@@ -327,29 +296,22 @@ public function testConnectionAborted() {
public function testConnectionAbortedOnBuffering() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
'id' => 'test_asset.css'
);
$this->MediaView->expects($this->at(0))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->any())
->method('type')
->with('css')
->will($this->returnArgument(0));
$this->MediaView->expects($this->at(1))
$this->MediaView->response->expects($this->at(1))
->method('_isActive')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->never())->method('_flushBuffer');
$this->MediaView->response->expects($this->once())->method('_clearBuffer');
$this->MediaView->response->expects($this->never())->method('_flushBuffer');
$result = $this->MediaView->render();
$this->assertFalse($result);
$this->MediaView->render();
}
/**
@@ -360,39 +322,15 @@ public function testConnectionAbortedOnBuffering() {
public function testRenderUpperExtension() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,
'id' => 'test_2.JPG',
'extension' => 'JPG',
);
$this->MediaView->response->expects($this->any())
->method('type')
->with('jpg')
->will($this->returnArgument(0));
$this->MediaView->expects($this->at(0))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->render();
}
/**
* Test downloading files with extension not explicitly set.
*
* @return void
*/
public function testRenderExtensionNotSet() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,
'id' => 'test_2.JPG',
'id' => 'test_2.JPG'
);
$this->MediaView->response->expects($this->any())
->method('type')
->with('jpg')
->will($this->returnArgument(0));
$this->MediaView->expects($this->at(0))
$this->MediaView->response->expects($this->at(0))
->method('_isActive')
->will($this->returnValue(true));
Oops, something went wrong.

0 comments on commit 69eba67

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