diff --git a/src/Symfony/Component/HttpFoundation/Tests/Fixtures/common.inc b/src/Symfony/Component/HttpFoundation/Tests/Fixtures/common.inc new file mode 100644 index 0000000000000..63dbd73b737ad --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Tests/Fixtures/common.inc @@ -0,0 +1,32 @@ + Content-Type: text/plain; charset=utf-8 + [1] => Cache-Control: no-cache, private + [2] => Date: Sat, 12 Nov 1955 20:04:00 GMT + [3] => Set-Cookie: CookieSamesiteLaxTest=LaxValue; path=/; httponly; samesite=lax +) +shutdown diff --git a/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_lax.php b/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_lax.php new file mode 100644 index 0000000000000..487096de4e280 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_lax.php @@ -0,0 +1,11 @@ +headers->set('Date', 'Sat, 12 Nov 1955 20:04:00 GMT'); +$r->headers->setCookie(new Cookie('CookieSamesiteLaxTest', 'LaxValue', 0, '/', null, false, true, false, Cookie::SAMESITE_LAX)); +$r->sendHeaders(); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_strict.expected b/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_strict.expected new file mode 100644 index 0000000000000..adc491fd2bc51 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_strict.expected @@ -0,0 +1,9 @@ + +Array +( + [0] => Content-Type: text/plain; charset=utf-8 + [1] => Cache-Control: no-cache, private + [2] => Date: Sat, 12 Nov 1955 20:04:00 GMT + [3] => Set-Cookie: CookieSamesiteStrictTest=StrictValue; path=/; httponly; samesite=strict +) +shutdown diff --git a/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_strict.php b/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_strict.php new file mode 100644 index 0000000000000..512ccd37dc3fd --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Tests/Fixtures/cookie_samesite_strict.php @@ -0,0 +1,11 @@ +headers->set('Date', 'Sat, 12 Nov 1955 20:04:00 GMT'); +$r->headers->setCookie(new Cookie('CookieSamesiteStrictTest', 'StrictValue', 0, '/', null, false, true, false, Cookie::SAMESITE_STRICT)); +$r->sendHeaders(); diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestFunctionalTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestFunctionalTest.php new file mode 100644 index 0000000000000..d1b9b67a79d83 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestFunctionalTest.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\Tests; + +use PHPUnit\Framework\TestCase; + +class RequestFunctionalTest extends TestCase +{ + private static $server; + + public static function setUpBeforeClass() + { + $spec = array( + 1 => array('file', '/dev/null', 'w'), + 2 => array('file', '/dev/null', 'w'), + ); + if (!self::$server = @proc_open('exec php -S localhost:8054', $spec, $pipes, __DIR__.'/Fixtures')) { + self::markTestSkipped('PHP server unable to start.'); + } + sleep(1); + } + + public static function tearDownAfterClass() + { + if (self::$server) { + proc_terminate(self::$server); + proc_close(self::$server); + } + } + + /** + * @dataProvider provideCookie + */ + public function testCookieSamesite($fixture) + { + $result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture)); + $this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result); + } + + public function provideCookie() + { + foreach (glob(__DIR__.'/Fixtures/cookie_*.php') as $file) { + yield array(pathinfo($file, PATHINFO_FILENAME)); + } + } +}