Skip to content
Permalink
Browse files

Use non-mocked methods for tests

This makes reducing off by 1 second errors much easier.
  • Loading branch information...
markstory committed Nov 22, 2012
1 parent 780b6f0 commit e04e0a0ec89ba95eaaa6dc51b1612a2909722018
Showing with 47 additions and 75 deletions.
  1. +47 −75 lib/Cake/Test/Case/View/MediaViewTest.php
@@ -36,7 +36,10 @@ 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->response = $this->getMock(
'CakeResponse',
array('send', 'cache', 'type', 'download', 'statusCode')
);
}
/**
@@ -83,20 +86,6 @@ public function testRender() {
->with('css')
->will($this->returnArgument(0));
$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'
));
$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');
@@ -106,6 +95,16 @@ public function testRender() {
$output = ob_get_clean();
$this->assertEquals('this is the test asset css file', $output);
$this->assertTrue($result !== false);
$headers = $this->MediaView->response->header();
$this->assertEquals(31, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}
/**
@@ -130,32 +129,10 @@ public function testRenderWithUnknownFileTypeGeneric() {
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('header')
->with($this->logicalAnd(
$this->arrayHasKey('Date'),
$this->arrayHasKey('Expires'),
$this->arrayHasKey('Cache-Control'),
$this->arrayHasKey('Pragma'),
$this->contains('0'),
$this->contains('private, must-revalidate, post-check=0, pre-check=0'),
$this->contains('no-cache')
));
$this->MediaView->response->expects($this->once())
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->at(3))
->method('header')
->with(array(
'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');
@@ -168,6 +145,17 @@ public function testRenderWithUnknownFileTypeGeneric() {
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}
/**
@@ -193,15 +181,6 @@ public function testRenderWithUnknownFileTypeOpera() {
->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'
));
$this->MediaView->response->expects($this->at(2))
->method('type')
->with('application/octetstream')
->will($this->returnValue(false));
@@ -210,16 +189,6 @@ public function testRenderWithUnknownFileTypeOpera() {
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->at(4))
->method('header')
->with(array(
'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');
@@ -232,6 +201,17 @@ public function testRenderWithUnknownFileTypeOpera() {
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}
/**
@@ -258,15 +238,6 @@ public function testRenderWithUnknownFileTypeIE() {
->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'
));
$this->MediaView->response->expects($this->at(2))
->method('type')
->with('application/force-download')
->will($this->returnValue(false));
@@ -275,16 +246,6 @@ public function testRenderWithUnknownFileTypeIE() {
->method('download')
->with('config.ini');
$this->MediaView->response->expects($this->at(4))
->method('header')
->with(array(
'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');
@@ -297,6 +258,17 @@ public function testRenderWithUnknownFileTypeIE() {
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}
/**

0 comments on commit e04e0a0

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