Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aef78f2

Browse files
inoryyfabpot
authored andcommitted
[HttpFoundation] Improve test coverage
1 parent 32947b2 commit aef78f2

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,12 @@ public function testOverrideGlobals()
966966

967967
$this->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);
968968

969+
$request->headers->set('CONTENT_TYPE', 'multipart/form-data');
970+
$request->headers->set('CONTENT_LENGTH', 12345);
971+
$request->overrideGlobals();
972+
$this->assertArrayHasKey('CONTENT_TYPE', $_SERVER);
973+
$this->assertArrayHasKey('CONTENT_LENGTH', $_SERVER);
974+
969975
// restore initial $_SERVER array
970976
$_SERVER = $server;
971977
}
@@ -1429,6 +1435,24 @@ public function testTrustedProxies()
14291435
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO');
14301436
}
14311437

1438+
/**
1439+
* @expectedException \InvalidArgumentException
1440+
*/
1441+
public function testSetTrustedProxiesInvalidHeaderName()
1442+
{
1443+
Request::create('http://example.com/');
1444+
Request::setTrustedHeaderName('bogus name', 'X_MY_FOR');
1445+
}
1446+
1447+
/**
1448+
* @expectedException \InvalidArgumentException
1449+
*/
1450+
public function testGetTrustedProxiesInvalidHeaderName()
1451+
{
1452+
Request::create('http://example.com/');
1453+
Request::getTrustedHeaderName('bogus name');
1454+
}
1455+
14321456
/**
14331457
* @dataProvider iisRequestUriProvider
14341458
*/

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ public function testIsCacheable()
7979
$this->assertFalse($response->isCacheable());
8080
}
8181

82+
public function testIsCacheableWithErrorCode()
83+
{
84+
$response = new Response('', 500);
85+
$this->assertFalse($response->isCacheable());
86+
}
87+
88+
public function testIsCacheableWithNoStoreDirective()
89+
{
90+
$response = new Response();
91+
$response->headers->set('cache-control', 'private');
92+
$this->assertFalse($response->isCacheable());
93+
}
94+
8295
public function testIsCacheableWithSetTtl()
8396
{
8497
$response = new Response();
@@ -118,6 +131,50 @@ public function testIsNotModified()
118131
$this->assertFalse($modified);
119132
}
120133

134+
public function testIsNotModifiedNotSafe()
135+
{
136+
$request = Request::create('/homepage', 'POST');
137+
138+
$response = new Response();
139+
$this->assertFalse($response->isNotModified($request));
140+
}
141+
142+
public function testIsNotModifiedLastModified()
143+
{
144+
$modified = 'Sun, 25 Aug 2013 18:33:31 GMT';
145+
146+
$request = new Request();
147+
$request->headers->set('If-Modified-Since', $modified);
148+
149+
$response = new Response();
150+
$response->headers->set('Last-Modified', $modified);
151+
152+
$this->assertTrue($response->isNotModified($request));
153+
154+
$response->headers->set('Last-Modified', '');
155+
$this->assertFalse($response->isNotModified($request));
156+
}
157+
158+
public function testIsNotModifiedEtag()
159+
{
160+
$etagOne = 'randomly_generated_etag';
161+
$etagTwo = 'randomly_generated_etag_2';
162+
163+
$request = new Request();
164+
$request->headers->set('if_none_match', sprintf('%s, %s, %s', $etagOne, $etagTwo, 'etagThree'));
165+
166+
$response = new Response();
167+
168+
$response->headers->set('ETag', $etagOne);
169+
$this->assertTrue($response->isNotModified($request));
170+
171+
$response->headers->set('ETag', $etagTwo);
172+
$this->assertTrue($response->isNotModified($request));
173+
174+
$response->headers->set('ETag', '');
175+
$this->assertFalse($response->isNotModified($request));
176+
}
177+
121178
public function testIsValidateable()
122179
{
123180
$response = new Response('', 200, array('Last-Modified' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
@@ -366,6 +423,36 @@ public function testPrepareRemovesContentForHeadRequests()
366423
$this->assertEquals('', $response->getContent());
367424
}
368425

426+
public function testPrepareRemovesContentForInformationalResponse()
427+
{
428+
$response = new Response('foo');
429+
$request = Request::create('/');
430+
431+
$response->setContent('content');
432+
$response->setStatusCode(101);
433+
$response->prepare($request);
434+
$this->assertEquals('', $response->getContent());
435+
436+
$response->setContent('content');
437+
$response->setStatusCode(304);
438+
$response->prepare($request);
439+
$this->assertEquals('', $response->getContent());
440+
}
441+
442+
public function testPrepareRemovesContentLength()
443+
{
444+
$response = new Response('foo');
445+
$request = Request::create('/');
446+
447+
$response->headers->set('Content-Length', 12345);
448+
$response->prepare($request);
449+
$this->assertEquals(12345, $response->headers->get('Content-Length'));
450+
451+
$response->headers->set('Transfer-Encoding', 'chunked');
452+
$response->prepare($request);
453+
$this->assertFalse($response->headers->has('Content-Length'));
454+
}
455+
369456
public function testPrepareSetsPragmaOnHttp10Only()
370457
{
371458
$request = Request::create('/', 'GET');

0 commit comments

Comments
 (0)