Skip to content

Commit ad5775f

Browse files
committed
DownloadResponse testing completed
1 parent b8bbadd commit ad5775f

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

system/HTTP/DownloadResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public function sendHeaders()
399399

400400
// Per spec, MUST be sent with each request, if possible.
401401
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
402-
if (isset($this->headers['Date']))
402+
if (! isset($this->headers['Date']))
403403
{
404404
$this->setDate(\DateTime::createFromFormat('U', time()));
405405
}

tests/system/HTTP/DownloadResponseTest.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace CodeIgniter\HTTP;
1+
<?php
2+
namespace CodeIgniter\HTTP;
23

34
use CodeIgniter\Files\Exceptions\FileNotFoundException;
45
use DateTime;
@@ -7,6 +8,7 @@
78

89
class DownloadResponseTest extends \CIUnitTestCase
910
{
11+
1012
public function tearDown()
1113
{
1214
if (isset($_SERVER['HTTP_USER_AGENT']))
@@ -250,4 +252,54 @@ public function testThrowExceptionWhenNoSetDownloadSource()
250252
$this->expectException(DownloadException::class);
251253
$response->sendBody();
252254
}
255+
256+
//--------------------------------------------------------------------
257+
public function testGetReason()
258+
{
259+
$response = new DownloadResponse('unit-test.php', false);
260+
$this->assertEquals('OK', $response->getReason());
261+
}
262+
263+
//--------------------------------------------------------------------
264+
public function testPretendOutput()
265+
{
266+
$response = new DownloadResponse('unit-test.php', false);
267+
$response->pretend(true);
268+
269+
$response->setFilePath(__FILE__);
270+
271+
ob_start();
272+
$response->send();
273+
$actual = ob_get_contents();
274+
ob_end_clean();
275+
276+
$this->assertSame(file_get_contents(__FILE__), $actual);
277+
}
278+
279+
//--------------------------------------------------------------------
280+
/**
281+
* @runInSeparateProcess
282+
* @preserveGlobalState disabled
283+
*/
284+
public function testRealOutput()
285+
{
286+
$response = new DownloadResponse('unit-test.php', false);
287+
$response->pretend(false);
288+
$response->setFilePath(__FILE__);
289+
290+
// send it
291+
ob_start();
292+
$response->send();
293+
294+
$buffer = ob_clean();
295+
if (ob_get_level() > 0)
296+
{
297+
ob_end_clean();
298+
}
299+
300+
// and what actually got sent?
301+
$this->assertHeaderEmitted('Content-Length: ' . filesize(__FILE__));
302+
$this->assertHeaderEmitted('Date:');
303+
}
304+
253305
}

0 commit comments

Comments
 (0)