|
1 | | -<?php namespace CodeIgniter\HTTP; |
| 1 | +<?php |
| 2 | +namespace CodeIgniter\HTTP; |
2 | 3 |
|
3 | 4 | use CodeIgniter\Files\Exceptions\FileNotFoundException; |
4 | 5 | use DateTime; |
|
7 | 8 |
|
8 | 9 | class DownloadResponseTest extends \CIUnitTestCase |
9 | 10 | { |
| 11 | + |
10 | 12 | public function tearDown() |
11 | 13 | { |
12 | 14 | if (isset($_SERVER['HTTP_USER_AGENT'])) |
@@ -250,4 +252,54 @@ public function testThrowExceptionWhenNoSetDownloadSource() |
250 | 252 | $this->expectException(DownloadException::class); |
251 | 253 | $response->sendBody(); |
252 | 254 | } |
| 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 | + |
253 | 305 | } |
0 commit comments