Skip to content

Commit

Permalink
[HttpFoundation] Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
inoryy authored and fabpot committed Aug 28, 2013
1 parent 32947b2 commit aef78f2
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -966,6 +966,12 @@ public function testOverrideGlobals()

$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
$_SERVER = $server;
}
Expand Down Expand Up @@ -1429,6 +1435,24 @@ public function testTrustedProxies()
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
*/
Expand Down
87 changes: 87 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
Expand Up @@ -79,6 +79,19 @@ public function testIsCacheable()
$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()
{
$response = new Response();
Expand Down Expand Up @@ -118,6 +131,50 @@ public function testIsNotModified()
$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()
{
$response = new Response('', 200, array('Last-Modified' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
Expand Down Expand Up @@ -366,6 +423,36 @@ public function testPrepareRemovesContentForHeadRequests()
$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()
{
$request = Request::create('/', 'GET');
Expand Down

0 comments on commit aef78f2

Please sign in to comment.