mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
commit
3b31bfd218
@ -399,7 +399,7 @@ class DownloadResponse extends Message implements ResponseInterface
|
||||
|
||||
// Per spec, MUST be sent with each request, if possible.
|
||||
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
|
||||
if (isset($this->headers['Date']))
|
||||
if (! isset($this->headers['Date']))
|
||||
{
|
||||
$this->setDate(\DateTime::createFromFormat('U', time()));
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php namespace CodeIgniter\HTTP;
|
||||
<?php
|
||||
namespace CodeIgniter\HTTP;
|
||||
|
||||
use CodeIgniter\Files\Exceptions\FileNotFoundException;
|
||||
use DateTime;
|
||||
@ -7,6 +8,7 @@ use CodeIgniter\Exceptions\DownloadException;
|
||||
|
||||
class DownloadResponseTest extends \CIUnitTestCase
|
||||
{
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if (isset($_SERVER['HTTP_USER_AGENT']))
|
||||
@ -250,4 +252,54 @@ class DownloadResponseTest extends \CIUnitTestCase
|
||||
$this->expectException(DownloadException::class);
|
||||
$response->sendBody();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
public function testGetReason()
|
||||
{
|
||||
$response = new DownloadResponse('unit-test.php', false);
|
||||
$this->assertEquals('OK', $response->getReason());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
public function testPretendOutput()
|
||||
{
|
||||
$response = new DownloadResponse('unit-test.php', false);
|
||||
$response->pretend(true);
|
||||
|
||||
$response->setFilePath(__FILE__);
|
||||
|
||||
ob_start();
|
||||
$response->send();
|
||||
$actual = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertSame(file_get_contents(__FILE__), $actual);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testRealOutput()
|
||||
{
|
||||
$response = new DownloadResponse('unit-test.php', false);
|
||||
$response->pretend(false);
|
||||
$response->setFilePath(__FILE__);
|
||||
|
||||
// send it
|
||||
ob_start();
|
||||
$response->send();
|
||||
|
||||
$buffer = ob_clean();
|
||||
if (ob_get_level() > 0)
|
||||
{
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
// and what actually got sent?
|
||||
$this->assertHeaderEmitted('Content-Length: ' . filesize(__FILE__));
|
||||
$this->assertHeaderEmitted('Date:');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,15 @@ class IncomingRequestDetectingTest extends \CIUnitTestCase
|
||||
$this->assertEquals($expected, $this->request->detectPath());
|
||||
}
|
||||
|
||||
public function testPathEmpty()
|
||||
{
|
||||
$this->request->uri = '/';
|
||||
$_SERVER['REQUEST_URI'] = '/';
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
$expected = '/';
|
||||
$this->assertEquals($expected, $this->request->detectPath());
|
||||
}
|
||||
|
||||
public function testPathRequestURI()
|
||||
{
|
||||
$this->request->uri = '/index.php/woot?code=good#pos';
|
||||
|
@ -61,6 +61,11 @@ class IncomingRequestTest extends \CIUnitTestCase
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testNoOldInput()
|
||||
{
|
||||
$this->assertNull($this->request->getOldInput('name'));
|
||||
}
|
||||
|
||||
public function testCanGetOldInput()
|
||||
{
|
||||
$_SESSION['_ci_old_input'] = [
|
||||
@ -83,6 +88,16 @@ class IncomingRequestTest extends \CIUnitTestCase
|
||||
$this->assertEquals('two', $this->request->getOldInput('apple.name'));
|
||||
}
|
||||
|
||||
public function testMissingOldInput()
|
||||
{
|
||||
$_SESSION['_ci_old_input'] = [
|
||||
'get' => ['apple' => ['name' => 'two']],
|
||||
'post' => ['banana' => ['name' => 'foo']],
|
||||
];
|
||||
|
||||
$this->assertNull($this->request->getOldInput('pineapple.name'));
|
||||
}
|
||||
|
||||
// Reference: https://github.com/codeigniter4/CodeIgniter4/issues/1492
|
||||
public function testCanGetOldInputArray()
|
||||
{
|
||||
@ -349,4 +364,21 @@ class IncomingRequestTest extends \CIUnitTestCase
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testGetFile()
|
||||
{
|
||||
$_FILES = [
|
||||
'userfile' => [
|
||||
'name' => 'someFile.txt',
|
||||
'type' => 'text/plain',
|
||||
'size' => '124',
|
||||
'tmp_name' => '/tmp/myTempFile.txt',
|
||||
'error' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
$gotit = $this->request->getFile('userfile');
|
||||
$this->assertEquals(124, $gotit->getSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -165,24 +165,21 @@ class ResponseTest extends \CIUnitTestCase
|
||||
$response->setLink($pager);
|
||||
|
||||
$this->assertEquals(
|
||||
'<http://example.com?page=1>; rel="first",<http://example.com?page=2>; rel="prev",<http://example.com?page=4>; rel="next",<http://example.com?page=20>; rel="last"',
|
||||
$response->getHeader('Link')->getValue()
|
||||
'<http://example.com?page=1>; rel="first",<http://example.com?page=2>; rel="prev",<http://example.com?page=4>; rel="next",<http://example.com?page=20>; rel="last"', $response->getHeader('Link')->getValue()
|
||||
);
|
||||
|
||||
$pager->store('default', 1, 10, 200);
|
||||
$response->setLink($pager);
|
||||
|
||||
$this->assertEquals(
|
||||
'<http://example.com?page=2>; rel="next",<http://example.com?page=20>; rel="last"',
|
||||
$response->getHeader('Link')->getValue()
|
||||
'<http://example.com?page=2>; rel="next",<http://example.com?page=20>; rel="last"', $response->getHeader('Link')->getValue()
|
||||
);
|
||||
|
||||
$pager->store('default', 20, 10, 200);
|
||||
$response->setLink($pager);
|
||||
|
||||
$this->assertEquals(
|
||||
'<http://example.com?page=1>; rel="first",<http://example.com?page=19>; rel="prev"',
|
||||
$response->getHeader('Link')->getValue()
|
||||
'<http://example.com?page=1>; rel="first",<http://example.com?page=19>; rel="prev"', $response->getHeader('Link')->getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@ -529,4 +526,21 @@ class ResponseTest extends \CIUnitTestCase
|
||||
$this->assertTrue($answer1->hasCookie('login_time'));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Make sure we don't blow up if pretending to send headers
|
||||
public function testPretendOutput()
|
||||
{
|
||||
$response = new Response(new App());
|
||||
$response->pretend(true);
|
||||
|
||||
$response->setBody('Happy days');
|
||||
|
||||
ob_start();
|
||||
$response->send();
|
||||
$actual = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertEquals('Happy days', $actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user