Skip to content

Commit

Permalink
[HttpFoundation] added some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 5, 2014
1 parent b6a6791 commit 1017d83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -991,10 +991,9 @@ public function getVary()
return array();
}


$ret = array();
foreach ($vary as $item) {
$ret = array_merge($ret, preg_split('/[\s,]+/', $item));
$ret = array_merge($ret, preg_split('/[\s,]+/', $item));
}

return $ret;
Expand Down
16 changes: 7 additions & 9 deletions src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
Expand Up @@ -285,15 +285,15 @@ public function testGetVary()
$response->headers->set('Vary', 'Accept-Language,User-Agent, X-Foo');
$this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->getVary() parses multiple header name values separated by commas');

$vary = array('Accept-Language', 'User-Agent', 'X-foo');

$response = new Response();
$vary = array(
'Accept-Language',
'User-Agent',
'X-foo',
);
$response->headers->set('Vary', $vary);
$this->assertEquals($response->headers->get('Vary', NULL, FALSE) , $response->getVary(), '->getVary() parses multiple header name values in arrays');
$this->assertEquals($vary, $response->getVary(), '->getVary() parses multiple header name values in arrays');

$response = new Response();
$response->headers->set('Vary', 'Accept-Language, User-Agent, X-foo');
$this->assertEquals($vary, $response->getVary(), '->getVary() parses multiple header name values in arrays');
}

public function testSetVary()
Expand All @@ -306,9 +306,7 @@ public function testSetVary()
$this->assertEquals(array('Accept-Language', 'User-Agent'), $response->getVary(), '->setVary() replace the vary header by default');

$response->setVary('X-Foo', false);
$this->assertTrue(in_array('Accept-Language', $response->getVary()), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false');
$this->assertTrue(in_array('User-Agent', $response->getVary()), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false');
$this->assertTrue(in_array('X-Foo', $response->getVary()), '->setVary() adds new Vary headers when replace is set to false');
$this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false');
}

public function testDefaultContentType()
Expand Down

0 comments on commit 1017d83

Please sign in to comment.