Laravel version update
Laravel version update
This commit is contained in:
@@ -11,62 +11,39 @@
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests;
|
||||
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
class ResponseHeaderBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideAllPreserveCase
|
||||
*/
|
||||
public function testAllPreserveCase($headers, $expected)
|
||||
public function testAllPreserveCase()
|
||||
{
|
||||
$bag = new ResponseHeaderBag($headers);
|
||||
|
||||
$this->assertEquals($expected, $bag->allPreserveCase(), '->allPreserveCase() gets all input keys in original case');
|
||||
}
|
||||
|
||||
public function provideAllPreserveCase()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('fOo' => 'BAR'),
|
||||
array('fOo' => array('BAR'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('ETag' => 'xyzzy'),
|
||||
array('ETag' => array('xyzzy'), 'Cache-Control' => array('private, must-revalidate')),
|
||||
),
|
||||
array(
|
||||
array('Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ=='),
|
||||
array('Content-MD5' => array('Q2hlY2sgSW50ZWdyaXR5IQ=='), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('P3P' => 'CP="CAO PSA OUR"'),
|
||||
array('P3P' => array('CP="CAO PSA OUR"'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('WWW-Authenticate' => 'Basic realm="WallyWorld"'),
|
||||
array('WWW-Authenticate' => array('Basic realm="WallyWorld"'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('X-UA-Compatible' => 'IE=edge,chrome=1'),
|
||||
array('X-UA-Compatible' => array('IE=edge,chrome=1'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
array(
|
||||
array('X-XSS-Protection' => '1; mode=block'),
|
||||
array('X-XSS-Protection' => array('1; mode=block'), 'Cache-Control' => array('no-cache')),
|
||||
),
|
||||
$headers = array(
|
||||
'fOo' => 'BAR',
|
||||
'ETag' => 'xyzzy',
|
||||
'Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ==',
|
||||
'P3P' => 'CP="CAO PSA OUR"',
|
||||
'WWW-Authenticate' => 'Basic realm="WallyWorld"',
|
||||
'X-UA-Compatible' => 'IE=edge,chrome=1',
|
||||
'X-XSS-Protection' => '1; mode=block',
|
||||
);
|
||||
|
||||
$bag = new ResponseHeaderBag($headers);
|
||||
$allPreservedCase = $bag->allPreserveCase();
|
||||
|
||||
foreach (array_keys($headers) as $headerName) {
|
||||
$this->assertArrayHasKey($headerName, $allPreservedCase, '->allPreserveCase() gets all input keys in original case');
|
||||
}
|
||||
}
|
||||
|
||||
public function testCacheControlHeader()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('Cache-Control' => 'public'));
|
||||
@@ -109,6 +86,25 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Last-Modified', 'abcde');
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Cache-Control', array('public', 'must-revalidate'));
|
||||
$this->assertCount(1, $bag->get('Cache-Control', null, false));
|
||||
$this->assertEquals('must-revalidate, public', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Cache-Control', 'public');
|
||||
$bag->set('Cache-Control', 'must-revalidate', false);
|
||||
$this->assertCount(1, $bag->get('Cache-Control', null, false));
|
||||
$this->assertEquals('must-revalidate, public', $bag->get('Cache-Control'));
|
||||
}
|
||||
|
||||
public function testCacheControlClone()
|
||||
{
|
||||
$headers = array('foo' => 'bar');
|
||||
$bag1 = new ResponseHeaderBag($headers);
|
||||
$bag2 = new ResponseHeaderBag($bag1->allPreserveCase());
|
||||
$this->assertEquals($bag1->allPreserveCase(), $bag2->allPreserveCase());
|
||||
}
|
||||
|
||||
public function testToStringIncludesCookieHeaders()
|
||||
@@ -116,11 +112,11 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$bag->setCookie(new Cookie('foo', 'bar'));
|
||||
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', explode("\r\n", $bag->__toString()));
|
||||
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
|
||||
|
||||
$bag->clearCookie('foo');
|
||||
|
||||
$this->assertRegExp('#^Set-Cookie: foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; httponly#m', $bag->__toString());
|
||||
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; httponly', $bag);
|
||||
}
|
||||
|
||||
public function testClearCookieSecureNotHttpOnly()
|
||||
@@ -129,13 +125,13 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$bag->clearCookie('foo', '/', null, true, false);
|
||||
|
||||
$this->assertRegExp('#^Set-Cookie: foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; path=/; secure#m', $bag->__toString());
|
||||
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure', $bag);
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag->replace(array('Cache-Control' => 'public'));
|
||||
@@ -146,12 +142,12 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
public function testReplaceWithRemove()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag->remove('Cache-Control');
|
||||
$bag->replace(array());
|
||||
$this->assertEquals('no-cache', $bag->get('Cache-Control'));
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
}
|
||||
|
||||
@@ -164,38 +160,50 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$bag->setCookie(new Cookie('foo', 'bar'));
|
||||
|
||||
$this->assertCount(4, $bag->getCookies());
|
||||
$this->assertEquals('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag->get('set-cookie'));
|
||||
$this->assertEquals(array(
|
||||
'foo=bar; path=/path/foo; domain=foo.bar; httponly',
|
||||
'foo=bar; path=/path/bar; domain=foo.bar; httponly',
|
||||
'foo=bar; path=/path/bar; domain=bar.foo; httponly',
|
||||
'foo=bar; path=/; httponly',
|
||||
), $bag->get('set-cookie', null, false));
|
||||
|
||||
$headers = explode("\r\n", $bag->__toString());
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly', $headers);
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/path/bar; domain=bar.foo; httponly', $headers);
|
||||
$this->assertContains('Set-Cookie: foo=bar; path=/; httponly', $headers);
|
||||
$this->assertSetCookieHeader('foo=bar; path=/path/foo; domain=foo.bar; httponly', $bag);
|
||||
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=foo.bar; httponly', $bag);
|
||||
$this->assertSetCookieHeader('foo=bar; path=/path/bar; domain=bar.foo; httponly', $bag);
|
||||
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']['foo']));
|
||||
$this->assertTrue(isset($cookies['foo.bar']['/path/bar']['foo']));
|
||||
$this->assertTrue(isset($cookies['bar.foo']['/path/bar']['foo']));
|
||||
$this->assertTrue(isset($cookies['']['/']['foo']));
|
||||
|
||||
$this->assertArrayHasKey('foo', $cookies['foo.bar']['/path/foo']);
|
||||
$this->assertArrayHasKey('foo', $cookies['foo.bar']['/path/bar']);
|
||||
$this->assertArrayHasKey('foo', $cookies['bar.foo']['/path/bar']);
|
||||
$this->assertArrayHasKey('foo', $cookies['']['/']);
|
||||
}
|
||||
|
||||
public function testRemoveCookie()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$this->assertFalse($bag->has('set-cookie'));
|
||||
|
||||
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/foo', 'foo.bar'));
|
||||
$bag->setCookie(new Cookie('bar', 'foo', 0, '/path/bar', 'foo.bar'));
|
||||
$this->assertTrue($bag->has('set-cookie'));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']));
|
||||
$this->assertArrayHasKey('/path/foo', $cookies['foo.bar']);
|
||||
|
||||
$bag->removeCookie('foo', '/path/foo', 'foo.bar');
|
||||
$this->assertTrue($bag->has('set-cookie'));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertFalse(isset($cookies['foo.bar']['/path/foo']));
|
||||
$this->assertArrayNotHasKey('/path/foo', $cookies['foo.bar']);
|
||||
|
||||
$bag->removeCookie('bar', '/path/bar', 'foo.bar');
|
||||
$this->assertFalse($bag->has('set-cookie'));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertFalse(isset($cookies['foo.bar']));
|
||||
$this->assertArrayNotHasKey('foo.bar', $cookies);
|
||||
}
|
||||
|
||||
public function testRemoveCookieWithNullRemove()
|
||||
@@ -205,17 +213,33 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
$bag->setCookie(new Cookie('bar', 'foo', 0));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertTrue(isset($cookies['']['/']));
|
||||
$this->assertArrayHasKey('/', $cookies['']);
|
||||
|
||||
$bag->removeCookie('foo', null);
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertFalse(isset($cookies['']['/']['foo']));
|
||||
$this->assertArrayNotHasKey('foo', $cookies['']['/']);
|
||||
|
||||
$bag->removeCookie('bar', null);
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertFalse(isset($cookies['']['/']['bar']));
|
||||
}
|
||||
|
||||
public function testSetCookieHeader()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('set-cookie', 'foo=bar');
|
||||
$this->assertEquals(array(new Cookie('foo', 'bar', 0, '/', null, false, false, true)), $bag->getCookies());
|
||||
|
||||
$bag->set('set-cookie', 'foo2=bar2', false);
|
||||
$this->assertEquals(array(
|
||||
new Cookie('foo', 'bar', 0, '/', null, false, false, true),
|
||||
new Cookie('foo2', 'bar2', 0, '/', null, false, false, true),
|
||||
), $bag->getCookies());
|
||||
|
||||
$bag->remove('set-cookie');
|
||||
$this->assertEquals(array(), $bag->getCookies());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
@@ -223,7 +247,7 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
|
||||
$cookies = $bag->getCookies('invalid_argument');
|
||||
$bag->getCookies('invalid_argument');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,4 +318,46 @@ class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||
array('attachment', 'föö.html'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testDateHeaderAddedOnCreation()
|
||||
{
|
||||
$now = time();
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
|
||||
$this->assertEquals($now, $bag->getDate('Date')->getTimestamp());
|
||||
}
|
||||
|
||||
public function testDateHeaderCanBeSetOnCreation()
|
||||
{
|
||||
$someDate = 'Thu, 23 Mar 2017 09:15:12 GMT';
|
||||
$bag = new ResponseHeaderBag(array('Date' => $someDate));
|
||||
|
||||
$this->assertEquals($someDate, $bag->get('Date'));
|
||||
}
|
||||
|
||||
public function testDateHeaderWillBeRecreatedWhenRemoved()
|
||||
{
|
||||
$someDate = 'Thu, 23 Mar 2017 09:15:12 GMT';
|
||||
$bag = new ResponseHeaderBag(array('Date' => $someDate));
|
||||
$bag->remove('Date');
|
||||
|
||||
// a (new) Date header is still present
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
$this->assertNotEquals($someDate, $bag->get('Date'));
|
||||
}
|
||||
|
||||
public function testDateHeaderWillBeRecreatedWhenHeadersAreReplaced()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->replace(array());
|
||||
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
}
|
||||
|
||||
private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
|
||||
{
|
||||
$this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user