merged branch Inori/tests-coverage (PR #8856)
This PR was squashed before being merged into the master branch (closes #8856).
Discussion
----------
[HttpFoundation] Improve test coverage
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| License | MIT
Commits
-------
aef78f2
[HttpFoundation] Improve test coverage
This commit is contained in:
commit
803c0b74c5
@ -966,6 +966,12 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);
|
$this->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);
|
||||||
|
|
||||||
|
$request->headers->set('CONTENT_TYPE', 'multipart/form-data');
|
||||||
|
$request->headers->set('CONTENT_LENGTH', 12345);
|
||||||
|
$request->overrideGlobals();
|
||||||
|
$this->assertArrayHasKey('CONTENT_TYPE', $_SERVER);
|
||||||
|
$this->assertArrayHasKey('CONTENT_LENGTH', $_SERVER);
|
||||||
|
|
||||||
// restore initial $_SERVER array
|
// restore initial $_SERVER array
|
||||||
$_SERVER = $server;
|
$_SERVER = $server;
|
||||||
}
|
}
|
||||||
@ -1429,6 +1435,24 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO');
|
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testSetTrustedProxiesInvalidHeaderName()
|
||||||
|
{
|
||||||
|
Request::create('http://example.com/');
|
||||||
|
Request::setTrustedHeaderName('bogus name', 'X_MY_FOR');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testGetTrustedProxiesInvalidHeaderName()
|
||||||
|
{
|
||||||
|
Request::create('http://example.com/');
|
||||||
|
Request::getTrustedHeaderName('bogus name');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider iisRequestUriProvider
|
* @dataProvider iisRequestUriProvider
|
||||||
*/
|
*/
|
||||||
|
@ -79,6 +79,19 @@ class ResponseTest extends ResponseTestCase
|
|||||||
$this->assertFalse($response->isCacheable());
|
$this->assertFalse($response->isCacheable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIsCacheableWithErrorCode()
|
||||||
|
{
|
||||||
|
$response = new Response('', 500);
|
||||||
|
$this->assertFalse($response->isCacheable());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsCacheableWithNoStoreDirective()
|
||||||
|
{
|
||||||
|
$response = new Response();
|
||||||
|
$response->headers->set('cache-control', 'private');
|
||||||
|
$this->assertFalse($response->isCacheable());
|
||||||
|
}
|
||||||
|
|
||||||
public function testIsCacheableWithSetTtl()
|
public function testIsCacheableWithSetTtl()
|
||||||
{
|
{
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
@ -118,6 +131,50 @@ class ResponseTest extends ResponseTestCase
|
|||||||
$this->assertFalse($modified);
|
$this->assertFalse($modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIsNotModifiedNotSafe()
|
||||||
|
{
|
||||||
|
$request = Request::create('/homepage', 'POST');
|
||||||
|
|
||||||
|
$response = new Response();
|
||||||
|
$this->assertFalse($response->isNotModified($request));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsNotModifiedLastModified()
|
||||||
|
{
|
||||||
|
$modified = 'Sun, 25 Aug 2013 18:33:31 GMT';
|
||||||
|
|
||||||
|
$request = new Request();
|
||||||
|
$request->headers->set('If-Modified-Since', $modified);
|
||||||
|
|
||||||
|
$response = new Response();
|
||||||
|
$response->headers->set('Last-Modified', $modified);
|
||||||
|
|
||||||
|
$this->assertTrue($response->isNotModified($request));
|
||||||
|
|
||||||
|
$response->headers->set('Last-Modified', '');
|
||||||
|
$this->assertFalse($response->isNotModified($request));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsNotModifiedEtag()
|
||||||
|
{
|
||||||
|
$etagOne = 'randomly_generated_etag';
|
||||||
|
$etagTwo = 'randomly_generated_etag_2';
|
||||||
|
|
||||||
|
$request = new Request();
|
||||||
|
$request->headers->set('if_none_match', sprintf('%s, %s, %s', $etagOne, $etagTwo, 'etagThree'));
|
||||||
|
|
||||||
|
$response = new Response();
|
||||||
|
|
||||||
|
$response->headers->set('ETag', $etagOne);
|
||||||
|
$this->assertTrue($response->isNotModified($request));
|
||||||
|
|
||||||
|
$response->headers->set('ETag', $etagTwo);
|
||||||
|
$this->assertTrue($response->isNotModified($request));
|
||||||
|
|
||||||
|
$response->headers->set('ETag', '');
|
||||||
|
$this->assertFalse($response->isNotModified($request));
|
||||||
|
}
|
||||||
|
|
||||||
public function testIsValidateable()
|
public function testIsValidateable()
|
||||||
{
|
{
|
||||||
$response = new Response('', 200, array('Last-Modified' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
|
$response = new Response('', 200, array('Last-Modified' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
|
||||||
@ -366,6 +423,36 @@ class ResponseTest extends ResponseTestCase
|
|||||||
$this->assertEquals('', $response->getContent());
|
$this->assertEquals('', $response->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPrepareRemovesContentForInformationalResponse()
|
||||||
|
{
|
||||||
|
$response = new Response('foo');
|
||||||
|
$request = Request::create('/');
|
||||||
|
|
||||||
|
$response->setContent('content');
|
||||||
|
$response->setStatusCode(101);
|
||||||
|
$response->prepare($request);
|
||||||
|
$this->assertEquals('', $response->getContent());
|
||||||
|
|
||||||
|
$response->setContent('content');
|
||||||
|
$response->setStatusCode(304);
|
||||||
|
$response->prepare($request);
|
||||||
|
$this->assertEquals('', $response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPrepareRemovesContentLength()
|
||||||
|
{
|
||||||
|
$response = new Response('foo');
|
||||||
|
$request = Request::create('/');
|
||||||
|
|
||||||
|
$response->headers->set('Content-Length', 12345);
|
||||||
|
$response->prepare($request);
|
||||||
|
$this->assertEquals(12345, $response->headers->get('Content-Length'));
|
||||||
|
|
||||||
|
$response->headers->set('Transfer-Encoding', 'chunked');
|
||||||
|
$response->prepare($request);
|
||||||
|
$this->assertFalse($response->headers->has('Content-Length'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testPrepareSetsPragmaOnHttp10Only()
|
public function testPrepareSetsPragmaOnHttp10Only()
|
||||||
{
|
{
|
||||||
$request = Request::create('/', 'GET');
|
$request = Request::create('/', 'GET');
|
||||||
|
Reference in New Issue
Block a user