first commit
This commit is contained in:
113
modules/ps_metrics/vendor/symfony/http-foundation/Tests/AcceptHeaderItemTest.php
vendored
Normal file
113
modules/ps_metrics/vendor/symfony/http-foundation/Tests/AcceptHeaderItemTest.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\AcceptHeaderItem;
|
||||
|
||||
class AcceptHeaderItemTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideFromStringData
|
||||
*/
|
||||
public function testFromString($string, $value, array $attributes)
|
||||
{
|
||||
$item = AcceptHeaderItem::fromString($string);
|
||||
$this->assertEquals($value, $item->getValue());
|
||||
$this->assertEquals($attributes, $item->getAttributes());
|
||||
}
|
||||
|
||||
public function provideFromStringData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'text/html',
|
||||
'text/html', [],
|
||||
],
|
||||
[
|
||||
'"this;should,not=matter"',
|
||||
'this;should,not=matter', [],
|
||||
],
|
||||
[
|
||||
"text/plain; charset=utf-8;param=\"this;should,not=matter\";\tfootnotes=true",
|
||||
'text/plain', ['charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'],
|
||||
],
|
||||
[
|
||||
'"this;should,not=matter";charset=utf-8',
|
||||
'this;should,not=matter', ['charset' => 'utf-8'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideToStringData
|
||||
*/
|
||||
public function testToString($value, array $attributes, $string)
|
||||
{
|
||||
$item = new AcceptHeaderItem($value, $attributes);
|
||||
$this->assertEquals($string, (string) $item);
|
||||
}
|
||||
|
||||
public function provideToStringData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'text/html', [],
|
||||
'text/html',
|
||||
],
|
||||
[
|
||||
'text/plain', ['charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'],
|
||||
'text/plain;charset=utf-8;param="this;should,not=matter";footnotes=true',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testValue()
|
||||
{
|
||||
$item = new AcceptHeaderItem('value', []);
|
||||
$this->assertEquals('value', $item->getValue());
|
||||
|
||||
$item->setValue('new value');
|
||||
$this->assertEquals('new value', $item->getValue());
|
||||
|
||||
$item->setValue(1);
|
||||
$this->assertEquals('1', $item->getValue());
|
||||
}
|
||||
|
||||
public function testQuality()
|
||||
{
|
||||
$item = new AcceptHeaderItem('value', []);
|
||||
$this->assertEquals(1.0, $item->getQuality());
|
||||
|
||||
$item->setQuality(0.5);
|
||||
$this->assertEquals(0.5, $item->getQuality());
|
||||
|
||||
$item->setAttribute('q', 0.75);
|
||||
$this->assertEquals(0.75, $item->getQuality());
|
||||
$this->assertFalse($item->hasAttribute('q'));
|
||||
}
|
||||
|
||||
public function testAttribute()
|
||||
{
|
||||
$item = new AcceptHeaderItem('value', []);
|
||||
$this->assertEquals([], $item->getAttributes());
|
||||
$this->assertFalse($item->hasAttribute('test'));
|
||||
$this->assertNull($item->getAttribute('test'));
|
||||
$this->assertEquals('default', $item->getAttribute('test', 'default'));
|
||||
|
||||
$item->setAttribute('test', 'value');
|
||||
$this->assertEquals(['test' => 'value'], $item->getAttributes());
|
||||
$this->assertTrue($item->hasAttribute('test'));
|
||||
$this->assertEquals('value', $item->getAttribute('test'));
|
||||
$this->assertEquals('value', $item->getAttribute('test', 'default'));
|
||||
}
|
||||
}
|
||||
103
modules/ps_metrics/vendor/symfony/http-foundation/Tests/AcceptHeaderTest.php
vendored
Normal file
103
modules/ps_metrics/vendor/symfony/http-foundation/Tests/AcceptHeaderTest.php
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\AcceptHeader;
|
||||
use Symfony\Component\HttpFoundation\AcceptHeaderItem;
|
||||
|
||||
class AcceptHeaderTest extends TestCase
|
||||
{
|
||||
public function testFirst()
|
||||
{
|
||||
$header = AcceptHeader::fromString('text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c');
|
||||
$this->assertSame('text/html', $header->first()->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFromStringData
|
||||
*/
|
||||
public function testFromString($string, array $items)
|
||||
{
|
||||
$header = AcceptHeader::fromString($string);
|
||||
$parsed = array_values($header->all());
|
||||
// reset index since the fixtures don't have them set
|
||||
foreach ($parsed as $item) {
|
||||
$item->setIndex(0);
|
||||
}
|
||||
$this->assertEquals($items, $parsed);
|
||||
}
|
||||
|
||||
public function provideFromStringData()
|
||||
{
|
||||
return [
|
||||
['', []],
|
||||
['gzip', [new AcceptHeaderItem('gzip')]],
|
||||
['gzip,deflate,sdch', [new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')]],
|
||||
["gzip, deflate\t,sdch", [new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')]],
|
||||
['"this;should,not=matter"', [new AcceptHeaderItem('this;should,not=matter')]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideToStringData
|
||||
*/
|
||||
public function testToString(array $items, $string)
|
||||
{
|
||||
$header = new AcceptHeader($items);
|
||||
$this->assertEquals($string, (string) $header);
|
||||
}
|
||||
|
||||
public function provideToStringData()
|
||||
{
|
||||
return [
|
||||
[[], ''],
|
||||
[[new AcceptHeaderItem('gzip')], 'gzip'],
|
||||
[[new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')], 'gzip,deflate,sdch'],
|
||||
[[new AcceptHeaderItem('this;should,not=matter')], 'this;should,not=matter'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFilterData
|
||||
*/
|
||||
public function testFilter($string, $filter, array $values)
|
||||
{
|
||||
$header = AcceptHeader::fromString($string)->filter($filter);
|
||||
$this->assertEquals($values, array_keys($header->all()));
|
||||
}
|
||||
|
||||
public function provideFilterData()
|
||||
{
|
||||
return [
|
||||
['fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4', '/fr.*/', ['fr-FR', 'fr']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideSortingData
|
||||
*/
|
||||
public function testSorting($string, array $values)
|
||||
{
|
||||
$header = AcceptHeader::fromString($string);
|
||||
$this->assertEquals($values, array_keys($header->all()));
|
||||
}
|
||||
|
||||
public function provideSortingData()
|
||||
{
|
||||
return [
|
||||
'quality has priority' => ['*;q=0.3,ISO-8859-1,utf-8;q=0.7', ['ISO-8859-1', 'utf-8', '*']],
|
||||
'order matters when q is equal' => ['*;q=0.3,ISO-8859-1;q=0.7,utf-8;q=0.7', ['ISO-8859-1', 'utf-8', '*']],
|
||||
'order matters when q is equal2' => ['*;q=0.3,utf-8;q=0.7,ISO-8859-1;q=0.7', ['utf-8', 'ISO-8859-1', '*']],
|
||||
];
|
||||
}
|
||||
}
|
||||
93
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ApacheRequestTest.php
vendored
Normal file
93
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ApacheRequestTest.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\ApacheRequest;
|
||||
|
||||
class ApacheRequestTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideServerVars
|
||||
*/
|
||||
public function testUriMethods($server, $expectedRequestUri, $expectedBaseUrl, $expectedPathInfo)
|
||||
{
|
||||
$request = new ApacheRequest();
|
||||
$request->server->replace($server);
|
||||
|
||||
$this->assertEquals($expectedRequestUri, $request->getRequestUri(), '->getRequestUri() is correct');
|
||||
$this->assertEquals($expectedBaseUrl, $request->getBaseUrl(), '->getBaseUrl() is correct');
|
||||
$this->assertEquals($expectedPathInfo, $request->getPathInfo(), '->getPathInfo() is correct');
|
||||
}
|
||||
|
||||
public function provideServerVars()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'REQUEST_URI' => '/foo/app_dev.php/bar',
|
||||
'SCRIPT_NAME' => '/foo/app_dev.php',
|
||||
'PATH_INFO' => '/bar',
|
||||
],
|
||||
'/foo/app_dev.php/bar',
|
||||
'/foo/app_dev.php',
|
||||
'/bar',
|
||||
],
|
||||
[
|
||||
[
|
||||
'REQUEST_URI' => '/foo/bar',
|
||||
'SCRIPT_NAME' => '/foo/app_dev.php',
|
||||
],
|
||||
'/foo/bar',
|
||||
'/foo',
|
||||
'/bar',
|
||||
],
|
||||
[
|
||||
[
|
||||
'REQUEST_URI' => '/app_dev.php/foo/bar',
|
||||
'SCRIPT_NAME' => '/app_dev.php',
|
||||
'PATH_INFO' => '/foo/bar',
|
||||
],
|
||||
'/app_dev.php/foo/bar',
|
||||
'/app_dev.php',
|
||||
'/foo/bar',
|
||||
],
|
||||
[
|
||||
[
|
||||
'REQUEST_URI' => '/foo/bar',
|
||||
'SCRIPT_NAME' => '/app_dev.php',
|
||||
],
|
||||
'/foo/bar',
|
||||
'',
|
||||
'/foo/bar',
|
||||
],
|
||||
[
|
||||
[
|
||||
'REQUEST_URI' => '/app_dev.php',
|
||||
'SCRIPT_NAME' => '/app_dev.php',
|
||||
],
|
||||
'/app_dev.php',
|
||||
'/app_dev.php',
|
||||
'/',
|
||||
],
|
||||
[
|
||||
[
|
||||
'REQUEST_URI' => '/',
|
||||
'SCRIPT_NAME' => '/app_dev.php',
|
||||
],
|
||||
'/',
|
||||
'',
|
||||
'/',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
387
modules/ps_metrics/vendor/symfony/http-foundation/Tests/BinaryFileResponseTest.php
vendored
Normal file
387
modules/ps_metrics/vendor/symfony/http-foundation/Tests/BinaryFileResponseTest.php
vendored
Normal file
@@ -0,0 +1,387 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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 Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\File\Stream;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\HttpFoundation\Tests\File\FakeFile;
|
||||
|
||||
class BinaryFileResponseTest extends ResponseTestCase
|
||||
{
|
||||
public function testConstruction()
|
||||
{
|
||||
$file = __DIR__.'/../README.md';
|
||||
$response = new BinaryFileResponse($file, 404, ['X-Header' => 'Foo'], true, null, true, true);
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
$this->assertEquals('Foo', $response->headers->get('X-Header'));
|
||||
$this->assertTrue($response->headers->has('ETag'));
|
||||
$this->assertTrue($response->headers->has('Last-Modified'));
|
||||
$this->assertFalse($response->headers->has('Content-Disposition'));
|
||||
|
||||
$response = BinaryFileResponse::create($file, 404, [], true, ResponseHeaderBag::DISPOSITION_INLINE);
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
$this->assertFalse($response->headers->has('ETag'));
|
||||
$this->assertEquals('inline; filename="README.md"', $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
|
||||
public function testConstructWithNonAsciiFilename()
|
||||
{
|
||||
touch(sys_get_temp_dir().'/fööö.html');
|
||||
|
||||
$response = new BinaryFileResponse(sys_get_temp_dir().'/fööö.html', 200, [], true, 'attachment');
|
||||
|
||||
@unlink(sys_get_temp_dir().'/fööö.html');
|
||||
|
||||
$this->assertSame('fööö.html', $response->getFile()->getFilename());
|
||||
}
|
||||
|
||||
public function testSetContent()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$response = new BinaryFileResponse(__FILE__);
|
||||
$response->setContent('foo');
|
||||
}
|
||||
|
||||
public function testGetContent()
|
||||
{
|
||||
$response = new BinaryFileResponse(__FILE__);
|
||||
$this->assertFalse($response->getContent());
|
||||
}
|
||||
|
||||
public function testSetContentDispositionGeneratesSafeFallbackFilename()
|
||||
{
|
||||
$response = new BinaryFileResponse(__FILE__);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'föö.html');
|
||||
|
||||
$this->assertSame('attachment; filename="f__.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html', $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
|
||||
public function testSetContentDispositionGeneratesSafeFallbackFilenameForWronglyEncodedFilename()
|
||||
{
|
||||
$response = new BinaryFileResponse(__FILE__);
|
||||
|
||||
$iso88591EncodedFilename = utf8_decode('föö.html');
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $iso88591EncodedFilename);
|
||||
|
||||
// the parameter filename* is invalid in this case (rawurldecode('f%F6%F6') does not provide a UTF-8 string but an ISO-8859-1 encoded one)
|
||||
$this->assertSame('attachment; filename="f__.html"; filename*=utf-8\'\'f%F6%F6.html', $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideRanges
|
||||
*/
|
||||
public function testRequests($requestRange, $offset, $length, $responseRange)
|
||||
{
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream'])->setAutoEtag();
|
||||
|
||||
// do a request to get the ETag
|
||||
$request = Request::create('/');
|
||||
$response->prepare($request);
|
||||
$etag = $response->headers->get('ETag');
|
||||
|
||||
// prepare a request for a range of the testing file
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('If-Range', $etag);
|
||||
$request->headers->set('Range', $requestRange);
|
||||
|
||||
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'r');
|
||||
fseek($file, $offset);
|
||||
$data = fread($file, $length);
|
||||
fclose($file);
|
||||
|
||||
$this->expectOutputString($data);
|
||||
$response = clone $response;
|
||||
$response->prepare($request);
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertEquals(206, $response->getStatusCode());
|
||||
$this->assertEquals($responseRange, $response->headers->get('Content-Range'));
|
||||
$this->assertSame((string) $length, $response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideRanges
|
||||
*/
|
||||
public function testRequestsWithoutEtag($requestRange, $offset, $length, $responseRange)
|
||||
{
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream']);
|
||||
|
||||
// do a request to get the LastModified
|
||||
$request = Request::create('/');
|
||||
$response->prepare($request);
|
||||
$lastModified = $response->headers->get('Last-Modified');
|
||||
|
||||
// prepare a request for a range of the testing file
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('If-Range', $lastModified);
|
||||
$request->headers->set('Range', $requestRange);
|
||||
|
||||
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'r');
|
||||
fseek($file, $offset);
|
||||
$data = fread($file, $length);
|
||||
fclose($file);
|
||||
|
||||
$this->expectOutputString($data);
|
||||
$response = clone $response;
|
||||
$response->prepare($request);
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertEquals(206, $response->getStatusCode());
|
||||
$this->assertEquals($responseRange, $response->headers->get('Content-Range'));
|
||||
}
|
||||
|
||||
public function provideRanges()
|
||||
{
|
||||
return [
|
||||
['bytes=1-4', 1, 4, 'bytes 1-4/35'],
|
||||
['bytes=-5', 30, 5, 'bytes 30-34/35'],
|
||||
['bytes=30-', 30, 5, 'bytes 30-34/35'],
|
||||
['bytes=30-30', 30, 1, 'bytes 30-30/35'],
|
||||
['bytes=30-34', 30, 5, 'bytes 30-34/35'],
|
||||
['bytes=30-40', 30, 5, 'bytes 30-34/35'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testRangeRequestsWithoutLastModifiedDate()
|
||||
{
|
||||
// prevent auto last modified
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream'], true, null, false, false);
|
||||
|
||||
// prepare a request for a range of the testing file
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('If-Range', date('D, d M Y H:i:s').' GMT');
|
||||
$request->headers->set('Range', 'bytes=1-4');
|
||||
|
||||
$this->expectOutputString(file_get_contents(__DIR__.'/File/Fixtures/test.gif'));
|
||||
$response = clone $response;
|
||||
$response->prepare($request);
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertNull($response->headers->get('Content-Range'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFullFileRanges
|
||||
*/
|
||||
public function testFullFileRequests($requestRange)
|
||||
{
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream'])->setAutoEtag();
|
||||
|
||||
// prepare a request for a range of the testing file
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('Range', $requestRange);
|
||||
|
||||
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'r');
|
||||
$data = fread($file, 35);
|
||||
fclose($file);
|
||||
|
||||
$this->expectOutputString($data);
|
||||
$response = clone $response;
|
||||
$response->prepare($request);
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function provideFullFileRanges()
|
||||
{
|
||||
return [
|
||||
['bytes=0-'],
|
||||
['bytes=0-34'],
|
||||
['bytes=-35'],
|
||||
// Syntactical invalid range-request should also return the full resource
|
||||
['bytes=20-10'],
|
||||
['bytes=50-40'],
|
||||
// range units other than bytes must be ignored
|
||||
['unknown=10-20'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testRangeOnPostMethod()
|
||||
{
|
||||
$request = Request::create('/', 'POST');
|
||||
$request->headers->set('Range', 'bytes=10-20');
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream']);
|
||||
|
||||
$file = fopen(__DIR__.'/File/Fixtures/test.gif', 'r');
|
||||
$data = fread($file, 35);
|
||||
fclose($file);
|
||||
|
||||
$this->expectOutputString($data);
|
||||
$response = clone $response;
|
||||
$response->prepare($request);
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
$this->assertSame('35', $response->headers->get('Content-Length'));
|
||||
$this->assertNull($response->headers->get('Content-Range'));
|
||||
}
|
||||
|
||||
public function testUnpreparedResponseSendsFullFile()
|
||||
{
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200);
|
||||
|
||||
$data = file_get_contents(__DIR__.'/File/Fixtures/test.gif');
|
||||
|
||||
$this->expectOutputString($data);
|
||||
$response = clone $response;
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidRanges
|
||||
*/
|
||||
public function testInvalidRequests($requestRange)
|
||||
{
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream'])->setAutoEtag();
|
||||
|
||||
// prepare a request for a range of the testing file
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('Range', $requestRange);
|
||||
|
||||
$response = clone $response;
|
||||
$response->prepare($request);
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertEquals(416, $response->getStatusCode());
|
||||
$this->assertEquals('bytes */35', $response->headers->get('Content-Range'));
|
||||
}
|
||||
|
||||
public function provideInvalidRanges()
|
||||
{
|
||||
return [
|
||||
['bytes=-40'],
|
||||
['bytes=40-50'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideXSendfileFiles
|
||||
*/
|
||||
public function testXSendfile($file)
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('X-Sendfile-Type', 'X-Sendfile');
|
||||
|
||||
BinaryFileResponse::trustXSendfileTypeHeader();
|
||||
$response = BinaryFileResponse::create($file, 200, ['Content-Type' => 'application/octet-stream']);
|
||||
$response->prepare($request);
|
||||
|
||||
$this->expectOutputString('');
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertStringContainsString('README.md', $response->headers->get('X-Sendfile'));
|
||||
}
|
||||
|
||||
public function provideXSendfileFiles()
|
||||
{
|
||||
return [
|
||||
[__DIR__.'/../README.md'],
|
||||
['file://'.__DIR__.'/../README.md'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getSampleXAccelMappings
|
||||
*/
|
||||
public function testXAccelMapping($realpath, $mapping, $virtual)
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('X-Sendfile-Type', 'X-Accel-Redirect');
|
||||
$request->headers->set('X-Accel-Mapping', $mapping);
|
||||
|
||||
$file = new FakeFile($realpath, __DIR__.'/File/Fixtures/test');
|
||||
|
||||
BinaryFileResponse::trustXSendfileTypeHeader();
|
||||
$response = new BinaryFileResponse($file, 200, ['Content-Type' => 'application/octet-stream']);
|
||||
$reflection = new \ReflectionObject($response);
|
||||
$property = $reflection->getProperty('file');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($response, $file);
|
||||
|
||||
$response->prepare($request);
|
||||
$this->assertEquals($virtual, $response->headers->get('X-Accel-Redirect'));
|
||||
}
|
||||
|
||||
public function testDeleteFileAfterSend()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
|
||||
$path = __DIR__.'/File/Fixtures/to_delete';
|
||||
touch($path);
|
||||
$realPath = realpath($path);
|
||||
$this->assertFileExists($realPath);
|
||||
|
||||
$response = new BinaryFileResponse($realPath, 200, ['Content-Type' => 'application/octet-stream']);
|
||||
$response->deleteFileAfterSend(true);
|
||||
|
||||
$response->prepare($request);
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertFileDoesNotExist($path);
|
||||
}
|
||||
|
||||
public function testAcceptRangeOnUnsafeMethods()
|
||||
{
|
||||
$request = Request::create('/', 'POST');
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream']);
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertEquals('none', $response->headers->get('Accept-Ranges'));
|
||||
}
|
||||
|
||||
public function testAcceptRangeNotOverriden()
|
||||
{
|
||||
$request = Request::create('/', 'POST');
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream']);
|
||||
$response->headers->set('Accept-Ranges', 'foo');
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertEquals('foo', $response->headers->get('Accept-Ranges'));
|
||||
}
|
||||
|
||||
public function getSampleXAccelMappings()
|
||||
{
|
||||
return [
|
||||
['/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'],
|
||||
['/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'],
|
||||
['/tmp/bar.txt', '"/var/www/"="/files/", "/home/Foo/"="/baz/"', null],
|
||||
];
|
||||
}
|
||||
|
||||
public function testStream()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$response = new BinaryFileResponse(new Stream(__DIR__.'/../README.md'), 200, ['Content-Type' => 'text/plain']);
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertNull($response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
protected function provideResponse()
|
||||
{
|
||||
return new BinaryFileResponse(__DIR__.'/../README.md', 200, ['Content-Type' => 'application/octet-stream']);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
$path = __DIR__.'/../Fixtures/to_delete';
|
||||
if (file_exists($path)) {
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
243
modules/ps_metrics/vendor/symfony/http-foundation/Tests/CookieTest.php
vendored
Normal file
243
modules/ps_metrics/vendor/symfony/http-foundation/Tests/CookieTest.php
vendored
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
/**
|
||||
* CookieTest.
|
||||
*
|
||||
* @author John Kary <john@johnkary.net>
|
||||
* @author Hugo Hamon <hugo.hamon@sensio.com>
|
||||
*
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class CookieTest extends TestCase
|
||||
{
|
||||
public function namesWithSpecialCharacters()
|
||||
{
|
||||
return [
|
||||
[',MyName'],
|
||||
[';MyName'],
|
||||
[' MyName'],
|
||||
["\tMyName"],
|
||||
["\rMyName"],
|
||||
["\nMyName"],
|
||||
["\013MyName"],
|
||||
["\014MyName"],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider namesWithSpecialCharacters
|
||||
*/
|
||||
public function testInstantiationThrowsExceptionIfRawCookieNameContainsSpecialCharacters($name)
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new Cookie($name, null, 0, null, null, null, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider namesWithSpecialCharacters
|
||||
*/
|
||||
public function testInstantiationSucceedNonRawCookieNameContainsSpecialCharacters($name)
|
||||
{
|
||||
$this->assertInstanceOf(Cookie::class, new Cookie($name));
|
||||
}
|
||||
|
||||
public function testInstantiationThrowsExceptionIfCookieNameIsEmpty()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new Cookie('');
|
||||
}
|
||||
|
||||
public function testInvalidExpiration()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new Cookie('MyCookie', 'foo', 'bar');
|
||||
}
|
||||
|
||||
public function testNegativeExpirationIsNotPossible()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', -100);
|
||||
|
||||
$this->assertSame(0, $cookie->getExpiresTime());
|
||||
}
|
||||
|
||||
public function testGetValue()
|
||||
{
|
||||
$value = 'MyValue';
|
||||
$cookie = new Cookie('MyCookie', $value);
|
||||
|
||||
$this->assertSame($value, $cookie->getValue(), '->getValue() returns the proper value');
|
||||
}
|
||||
|
||||
public function testGetPath()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar');
|
||||
|
||||
$this->assertSame('/', $cookie->getPath(), '->getPath() returns / as the default path');
|
||||
}
|
||||
|
||||
public function testGetExpiresTime()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar');
|
||||
|
||||
$this->assertEquals(0, $cookie->getExpiresTime(), '->getExpiresTime() returns the default expire date');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', $expire = time() + 3600);
|
||||
|
||||
$this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
|
||||
}
|
||||
|
||||
public function testGetExpiresTimeIsCastToInt()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 3600.9);
|
||||
|
||||
$this->assertSame(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date as an integer');
|
||||
}
|
||||
|
||||
public function testConstructorWithDateTime()
|
||||
{
|
||||
$expire = new \DateTime();
|
||||
$cookie = new Cookie('foo', 'bar', $expire);
|
||||
|
||||
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
|
||||
}
|
||||
|
||||
public function testConstructorWithDateTimeImmutable()
|
||||
{
|
||||
$expire = new \DateTimeImmutable();
|
||||
$cookie = new Cookie('foo', 'bar', $expire);
|
||||
|
||||
$this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
|
||||
}
|
||||
|
||||
public function testGetExpiresTimeWithStringValue()
|
||||
{
|
||||
$value = '+1 day';
|
||||
$cookie = new Cookie('foo', 'bar', $value);
|
||||
$expire = strtotime($value);
|
||||
|
||||
$this->assertEqualsWithDelta($expire, $cookie->getExpiresTime(), 1, '->getExpiresTime() returns the expire date');
|
||||
}
|
||||
|
||||
public function testGetDomain()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com');
|
||||
|
||||
$this->assertEquals('.myfoodomain.com', $cookie->getDomain(), '->getDomain() returns the domain name on which the cookie is valid');
|
||||
}
|
||||
|
||||
public function testIsSecure()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com', true);
|
||||
|
||||
$this->assertTrue($cookie->isSecure(), '->isSecure() returns whether the cookie is transmitted over HTTPS');
|
||||
}
|
||||
|
||||
public function testIsHttpOnly()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', '.myfoodomain.com', false, true);
|
||||
|
||||
$this->assertTrue($cookie->isHttpOnly(), '->isHttpOnly() returns whether the cookie is only transmitted over HTTP');
|
||||
}
|
||||
|
||||
public function testCookieIsNotCleared()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', time() + 3600 * 24);
|
||||
|
||||
$this->assertFalse($cookie->isCleared(), '->isCleared() returns false if the cookie did not expire yet');
|
||||
}
|
||||
|
||||
public function testCookieIsCleared()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', time() - 20);
|
||||
|
||||
$this->assertTrue($cookie->isCleared(), '->isCleared() returns true if the cookie has expired');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar');
|
||||
|
||||
$this->assertFalse($cookie->isCleared());
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', 0);
|
||||
|
||||
$this->assertFalse($cookie->isCleared());
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', -1);
|
||||
|
||||
$this->assertFalse($cookie->isCleared());
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', $expire = strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
|
||||
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() returns string representation of the cookie');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
|
||||
$this->assertEquals('foo=bar%20with%20white%20spaces; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
|
||||
|
||||
$cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');
|
||||
$this->assertEquals('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', $expire = time() - 31536001).'; Max-Age=0; path=/admin/; domain=.myfoodomain.com; httponly', (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', '');
|
||||
$this->assertEquals('foo=bar; path=/; httponly', (string) $cookie);
|
||||
}
|
||||
|
||||
public function testRawCookie()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'b a r', 0, '/', null, false, false);
|
||||
$this->assertFalse($cookie->isRaw());
|
||||
$this->assertEquals('foo=b%20a%20r; path=/', (string) $cookie);
|
||||
|
||||
$cookie = new Cookie('foo', 'b+a+r', 0, '/', null, false, false, true);
|
||||
$this->assertTrue($cookie->isRaw());
|
||||
$this->assertEquals('foo=b+a+r; path=/', (string) $cookie);
|
||||
}
|
||||
|
||||
public function testGetMaxAge()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar');
|
||||
$this->assertEquals(0, $cookie->getMaxAge());
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', $expire = time() + 100);
|
||||
$this->assertEquals($expire - time(), $cookie->getMaxAge());
|
||||
|
||||
$cookie = new Cookie('foo', 'bar', $expire = time() - 100);
|
||||
$this->assertEquals(0, $cookie->getMaxAge());
|
||||
}
|
||||
|
||||
public function testFromString()
|
||||
{
|
||||
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
|
||||
$this->assertEquals(new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, true), $cookie);
|
||||
|
||||
$cookie = Cookie::fromString('foo=bar', true);
|
||||
$this->assertEquals(new Cookie('foo', 'bar', 0, '/', null, false, false), $cookie);
|
||||
}
|
||||
|
||||
public function testFromStringWithHttpOnly()
|
||||
{
|
||||
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
|
||||
$this->assertTrue($cookie->isHttpOnly());
|
||||
|
||||
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure');
|
||||
$this->assertFalse($cookie->isHttpOnly());
|
||||
}
|
||||
|
||||
public function testSameSiteAttributeIsCaseInsensitive()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar', 0, '/', null, false, true, false, 'Lax');
|
||||
$this->assertEquals('lax', $cookie->getSameSite());
|
||||
}
|
||||
}
|
||||
67
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ExpressionRequestMatcherTest.php
vendored
Normal file
67
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ExpressionRequestMatcherTest.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
use Symfony\Component\HttpFoundation\ExpressionRequestMatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ExpressionRequestMatcherTest extends TestCase
|
||||
{
|
||||
public function testWhenNoExpressionIsSet()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$expressionRequestMatcher = new ExpressionRequestMatcher();
|
||||
$expressionRequestMatcher->matches(new Request());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideExpressions
|
||||
*/
|
||||
public function testMatchesWhenParentMatchesIsTrue($expression, $expected)
|
||||
{
|
||||
$request = Request::create('/foo');
|
||||
$expressionRequestMatcher = new ExpressionRequestMatcher();
|
||||
|
||||
$expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
|
||||
$this->assertSame($expected, $expressionRequestMatcher->matches($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideExpressions
|
||||
*/
|
||||
public function testMatchesWhenParentMatchesIsFalse($expression)
|
||||
{
|
||||
$request = Request::create('/foo');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$expressionRequestMatcher = new ExpressionRequestMatcher();
|
||||
$expressionRequestMatcher->matchAttribute('foo', 'bar');
|
||||
|
||||
$expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
|
||||
$this->assertFalse($expressionRequestMatcher->matches($request));
|
||||
}
|
||||
|
||||
public function provideExpressions()
|
||||
{
|
||||
return [
|
||||
['request.getMethod() == method', true],
|
||||
['request.getPathInfo() == path', true],
|
||||
['request.getHost() == host', true],
|
||||
['request.getClientIp() == ip', true],
|
||||
['request.attributes.all() == attributes', true],
|
||||
['request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', true],
|
||||
['request.getMethod() != method', false],
|
||||
['request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', false],
|
||||
];
|
||||
}
|
||||
}
|
||||
45
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/FakeFile.php
vendored
Normal file
45
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/FakeFile.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\File;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\File as OrigFile;
|
||||
|
||||
class FakeFile extends OrigFile
|
||||
{
|
||||
private $realpath;
|
||||
|
||||
public function __construct($realpath, $path)
|
||||
{
|
||||
$this->realpath = $realpath;
|
||||
parent::__construct($path, false);
|
||||
}
|
||||
|
||||
public function isReadable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRealpath()
|
||||
{
|
||||
return $this->realpath;
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
public function getMTime()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
}
|
||||
180
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/FileTest.php
vendored
Normal file
180
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/FileTest.php
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\File;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
|
||||
class FileTest extends TestCase
|
||||
{
|
||||
protected $file;
|
||||
|
||||
public function testGetMimeTypeUsesMimeTypeGuessers()
|
||||
{
|
||||
$file = new File(__DIR__.'/Fixtures/test.gif');
|
||||
$guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
|
||||
|
||||
MimeTypeGuesser::getInstance()->register($guesser);
|
||||
|
||||
$this->assertEquals('image/gif', $file->getMimeType());
|
||||
}
|
||||
|
||||
public function testGuessExtensionWithoutGuesser()
|
||||
{
|
||||
$file = new File(__DIR__.'/Fixtures/directory/.empty');
|
||||
|
||||
$this->assertNull($file->guessExtension());
|
||||
}
|
||||
|
||||
public function testGuessExtensionIsBasedOnMimeType()
|
||||
{
|
||||
$file = new File(__DIR__.'/Fixtures/test');
|
||||
$guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
|
||||
|
||||
MimeTypeGuesser::getInstance()->register($guesser);
|
||||
|
||||
$this->assertEquals('gif', $file->guessExtension());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension fileinfo
|
||||
*/
|
||||
public function testGuessExtensionWithReset()
|
||||
{
|
||||
$file = new File(__DIR__.'/Fixtures/other-file.example');
|
||||
$guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
|
||||
MimeTypeGuesser::getInstance()->register($guesser);
|
||||
|
||||
$this->assertEquals('gif', $file->guessExtension());
|
||||
|
||||
MimeTypeGuesser::reset();
|
||||
|
||||
$this->assertNull($file->guessExtension());
|
||||
}
|
||||
|
||||
public function testConstructWhenFileNotExists()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
new File(__DIR__.'/Fixtures/not_here');
|
||||
}
|
||||
|
||||
public function testMove()
|
||||
{
|
||||
$path = __DIR__.'/Fixtures/test.copy.gif';
|
||||
$targetDir = __DIR__.'/Fixtures/directory';
|
||||
$targetPath = $targetDir.'/test.copy.gif';
|
||||
@unlink($path);
|
||||
@unlink($targetPath);
|
||||
copy(__DIR__.'/Fixtures/test.gif', $path);
|
||||
|
||||
$file = new File($path);
|
||||
$movedFile = $file->move($targetDir);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $movedFile);
|
||||
|
||||
$this->assertFileExists($targetPath);
|
||||
$this->assertFileDoesNotExist($path);
|
||||
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
|
||||
|
||||
@unlink($targetPath);
|
||||
}
|
||||
|
||||
public function testMoveWithNewName()
|
||||
{
|
||||
$path = __DIR__.'/Fixtures/test.copy.gif';
|
||||
$targetDir = __DIR__.'/Fixtures/directory';
|
||||
$targetPath = $targetDir.'/test.newname.gif';
|
||||
@unlink($path);
|
||||
@unlink($targetPath);
|
||||
copy(__DIR__.'/Fixtures/test.gif', $path);
|
||||
|
||||
$file = new File($path);
|
||||
$movedFile = $file->move($targetDir, 'test.newname.gif');
|
||||
|
||||
$this->assertFileExists($targetPath);
|
||||
$this->assertFileDoesNotExist($path);
|
||||
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
|
||||
|
||||
@unlink($targetPath);
|
||||
}
|
||||
|
||||
public function getFilenameFixtures()
|
||||
{
|
||||
return [
|
||||
['original.gif', 'original.gif'],
|
||||
['..\\..\\original.gif', 'original.gif'],
|
||||
['../../original.gif', 'original.gif'],
|
||||
['файлfile.gif', 'файлfile.gif'],
|
||||
['..\\..\\файлfile.gif', 'файлfile.gif'],
|
||||
['../../файлfile.gif', 'файлfile.gif'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilenameFixtures
|
||||
*/
|
||||
public function testMoveWithNonLatinName($filename, $sanitizedFilename)
|
||||
{
|
||||
$path = __DIR__.'/Fixtures/'.$sanitizedFilename;
|
||||
$targetDir = __DIR__.'/Fixtures/directory/';
|
||||
$targetPath = $targetDir.$sanitizedFilename;
|
||||
@unlink($path);
|
||||
@unlink($targetPath);
|
||||
copy(__DIR__.'/Fixtures/test.gif', $path);
|
||||
|
||||
$file = new File($path);
|
||||
$movedFile = $file->move($targetDir, $filename);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $movedFile);
|
||||
|
||||
$this->assertFileExists($targetPath);
|
||||
$this->assertFileDoesNotExist($path);
|
||||
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
|
||||
|
||||
@unlink($targetPath);
|
||||
}
|
||||
|
||||
public function testMoveToAnUnexistentDirectory()
|
||||
{
|
||||
$sourcePath = __DIR__.'/Fixtures/test.copy.gif';
|
||||
$targetDir = __DIR__.'/Fixtures/directory/sub';
|
||||
$targetPath = $targetDir.'/test.copy.gif';
|
||||
@unlink($sourcePath);
|
||||
@unlink($targetPath);
|
||||
@rmdir($targetDir);
|
||||
copy(__DIR__.'/Fixtures/test.gif', $sourcePath);
|
||||
|
||||
$file = new File($sourcePath);
|
||||
$movedFile = $file->move($targetDir);
|
||||
|
||||
$this->assertFileExists($targetPath);
|
||||
$this->assertFileDoesNotExist($sourcePath);
|
||||
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
|
||||
|
||||
@unlink($sourcePath);
|
||||
@unlink($targetPath);
|
||||
@rmdir($targetDir);
|
||||
}
|
||||
|
||||
protected function createMockGuesser($path, $mimeType)
|
||||
{
|
||||
$guesser = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface')->getMock();
|
||||
$guesser
|
||||
->expects($this->once())
|
||||
->method('guess')
|
||||
->with($this->equalTo($path))
|
||||
->willReturn($mimeType)
|
||||
;
|
||||
|
||||
return $guesser;
|
||||
}
|
||||
}
|
||||
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/-test
vendored
Normal file
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/-test
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 B |
1
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/.unknownextension
vendored
Normal file
1
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/.unknownextension
vendored
Normal file
@@ -0,0 +1 @@
|
||||
f
|
||||
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/case-sensitive-mime-type.xlsm
vendored
Normal file
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/case-sensitive-mime-type.xlsm
vendored
Normal file
Binary file not shown.
0
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/directory/.empty
vendored
Normal file
0
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/directory/.empty
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/directory/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/directory/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
0
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/other-file.example
vendored
Normal file
0
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/other-file.example
vendored
Normal file
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/test
vendored
Normal file
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/test
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 B |
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/test.docx
vendored
Normal file
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/test.docx
vendored
Normal file
Binary file not shown.
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/test.gif
vendored
Normal file
BIN
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/Fixtures/test.gif
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 B |
113
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/MimeType/MimeTypeTest.php
vendored
Normal file
113
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/MimeType/MimeTypeTest.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\File\MimeType;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
|
||||
/**
|
||||
* @requires extension fileinfo
|
||||
*/
|
||||
class MimeTypeTest extends TestCase
|
||||
{
|
||||
public function testGuessWithLeadingDash()
|
||||
{
|
||||
$cwd = getcwd();
|
||||
chdir(__DIR__.'/../Fixtures');
|
||||
try {
|
||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess('-test'));
|
||||
} finally {
|
||||
chdir($cwd);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGuessImageWithoutExtension()
|
||||
{
|
||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
||||
}
|
||||
|
||||
public function testGuessImageWithDirectory()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory');
|
||||
}
|
||||
|
||||
public function testGuessImageWithFileBinaryMimeTypeGuesser()
|
||||
{
|
||||
$guesser = MimeTypeGuesser::getInstance();
|
||||
$guesser->register(new FileBinaryMimeTypeGuesser());
|
||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
||||
}
|
||||
|
||||
public function testGuessImageWithKnownExtension()
|
||||
{
|
||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
|
||||
}
|
||||
|
||||
public function testGuessFileWithUnknownExtension()
|
||||
{
|
||||
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
public function testGuessWithDuplicatedFileType()
|
||||
{
|
||||
if ('application/zip' === MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx')) {
|
||||
$this->addToAssertionCount(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertSame('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx'));
|
||||
}
|
||||
|
||||
public function testGuessWithIncorrectPath()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here');
|
||||
}
|
||||
|
||||
public function testGuessWithNonReadablePath()
|
||||
{
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('Can not verify chmod operations on Windows');
|
||||
}
|
||||
|
||||
if (!getenv('USER') || 'root' === getenv('USER')) {
|
||||
$this->markTestSkipped('This test will fail if run under superuser');
|
||||
}
|
||||
|
||||
$path = __DIR__.'/../Fixtures/to_delete';
|
||||
touch($path);
|
||||
@chmod($path, 0333);
|
||||
|
||||
if ('0333' == substr(sprintf('%o', fileperms($path)), -4)) {
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
|
||||
MimeTypeGuesser::getInstance()->guess($path);
|
||||
} else {
|
||||
$this->markTestSkipped('Can not verify chmod operations, change of file permissions failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
$path = __DIR__.'/../Fixtures/to_delete';
|
||||
if (file_exists($path)) {
|
||||
@chmod($path, 0666);
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/MimeType/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/MimeType/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
298
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/UploadedFileTest.php
vendored
Normal file
298
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/UploadedFileTest.php
vendored
Normal file
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\File;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class UploadedFileTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!ini_get('file_uploads')) {
|
||||
$this->markTestSkipped('file_uploads is disabled in php.ini');
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstructWhenFileNotExists()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||
|
||||
new UploadedFile(
|
||||
__DIR__.'/Fixtures/not_here',
|
||||
'original.gif',
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public function testFileUploadsWithNoMimeType()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
null,
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
\UPLOAD_ERR_OK
|
||||
);
|
||||
|
||||
$this->assertEquals('application/octet-stream', $file->getClientMimeType());
|
||||
|
||||
if (\extension_loaded('fileinfo')) {
|
||||
$this->assertEquals('image/gif', $file->getMimeType());
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileUploadsWithUnknownMimeType()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/.unknownextension',
|
||||
'original.gif',
|
||||
null,
|
||||
filesize(__DIR__.'/Fixtures/.unknownextension'),
|
||||
\UPLOAD_ERR_OK
|
||||
);
|
||||
|
||||
$this->assertEquals('application/octet-stream', $file->getClientMimeType());
|
||||
}
|
||||
|
||||
public function testGuessClientExtension()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
'image/gif',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals('gif', $file->guessClientExtension());
|
||||
}
|
||||
|
||||
public function testGuessClientExtensionWithIncorrectMimeType()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
'image/png',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals('png', $file->guessClientExtension());
|
||||
}
|
||||
|
||||
public function testCaseSensitiveMimeType()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/case-sensitive-mime-type.xlsm',
|
||||
'test.xlsm',
|
||||
'application/vnd.ms-excel.sheet.macroEnabled.12',
|
||||
filesize(__DIR__.'/Fixtures/case-sensitive-mime-type.xlsm'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals('xlsm', $file->guessClientExtension());
|
||||
}
|
||||
|
||||
public function testErrorIsOkByDefault()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
'image/gif',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals(\UPLOAD_ERR_OK, $file->getError());
|
||||
}
|
||||
|
||||
public function testGetClientOriginalName()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
'image/gif',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals('original.gif', $file->getClientOriginalName());
|
||||
}
|
||||
|
||||
public function testGetClientOriginalExtension()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
'image/gif',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals('gif', $file->getClientOriginalExtension());
|
||||
}
|
||||
|
||||
public function testMoveLocalFileIsNotAllowed()
|
||||
{
|
||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileException');
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
'image/gif',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
\UPLOAD_ERR_OK
|
||||
);
|
||||
|
||||
$file->move(__DIR__.'/Fixtures/directory');
|
||||
}
|
||||
|
||||
public function testMoveLocalFileIsAllowedInTestMode()
|
||||
{
|
||||
$path = __DIR__.'/Fixtures/test.copy.gif';
|
||||
$targetDir = __DIR__.'/Fixtures/directory';
|
||||
$targetPath = $targetDir.'/test.copy.gif';
|
||||
@unlink($path);
|
||||
@unlink($targetPath);
|
||||
copy(__DIR__.'/Fixtures/test.gif', $path);
|
||||
|
||||
$file = new UploadedFile(
|
||||
$path,
|
||||
'original.gif',
|
||||
'image/gif',
|
||||
filesize($path),
|
||||
\UPLOAD_ERR_OK,
|
||||
true
|
||||
);
|
||||
|
||||
$movedFile = $file->move(__DIR__.'/Fixtures/directory');
|
||||
|
||||
$this->assertFileExists($targetPath);
|
||||
$this->assertFileDoesNotExist($path);
|
||||
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
|
||||
|
||||
@unlink($targetPath);
|
||||
}
|
||||
|
||||
public function testGetClientOriginalNameSanitizeFilename()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'../../original.gif',
|
||||
'image/gif',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals('original.gif', $file->getClientOriginalName());
|
||||
}
|
||||
|
||||
public function testGetSize()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
'image/gif',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals(filesize(__DIR__.'/Fixtures/test.gif'), $file->getSize());
|
||||
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test',
|
||||
'original.gif',
|
||||
'image/gif'
|
||||
);
|
||||
|
||||
$this->assertEquals(filesize(__DIR__.'/Fixtures/test'), $file->getSize());
|
||||
}
|
||||
|
||||
public function testGetExtension()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals('gif', $file->getExtension());
|
||||
}
|
||||
|
||||
public function testIsValid()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
null,
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
\UPLOAD_ERR_OK,
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertTrue($file->isValid());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider uploadedFileErrorProvider
|
||||
*/
|
||||
public function testIsInvalidOnUploadError($error)
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
null,
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
$error
|
||||
);
|
||||
|
||||
$this->assertFalse($file->isValid());
|
||||
}
|
||||
|
||||
public function uploadedFileErrorProvider()
|
||||
{
|
||||
return [
|
||||
[\UPLOAD_ERR_INI_SIZE],
|
||||
[\UPLOAD_ERR_FORM_SIZE],
|
||||
[\UPLOAD_ERR_PARTIAL],
|
||||
[\UPLOAD_ERR_NO_TMP_DIR],
|
||||
[\UPLOAD_ERR_EXTENSION],
|
||||
];
|
||||
}
|
||||
|
||||
public function testIsInvalidIfNotHttpUpload()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
null,
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
\UPLOAD_ERR_OK
|
||||
);
|
||||
|
||||
$this->assertFalse($file->isValid());
|
||||
}
|
||||
|
||||
public function testGetMaxFilesize()
|
||||
{
|
||||
$size = UploadedFile::getMaxFilesize();
|
||||
|
||||
$this->assertIsInt($size);
|
||||
$this->assertGreaterThan(0, $size);
|
||||
|
||||
if (0 === (int) ini_get('post_max_size') && 0 === (int) ini_get('upload_max_filesize')) {
|
||||
$this->assertSame(\PHP_INT_MAX, $size);
|
||||
} else {
|
||||
$this->assertLessThan(\PHP_INT_MAX, $size);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/File/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
173
modules/ps_metrics/vendor/symfony/http-foundation/Tests/FileBagTest.php
vendored
Normal file
173
modules/ps_metrics/vendor/symfony/http-foundation/Tests/FileBagTest.php
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\FileBag;
|
||||
|
||||
/**
|
||||
* FileBagTest.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||||
*/
|
||||
class FileBagTest extends TestCase
|
||||
{
|
||||
public function testFileMustBeAnArrayOrUploadedFile()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new FileBag(['file' => 'foo']);
|
||||
}
|
||||
|
||||
public function testShouldConvertsUploadedFiles()
|
||||
{
|
||||
$tmpFile = $this->createTempFile();
|
||||
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
||||
|
||||
$bag = new FileBag(['file' => [
|
||||
'name' => basename($tmpFile),
|
||||
'type' => 'text/plain',
|
||||
'tmp_name' => $tmpFile,
|
||||
'error' => 0,
|
||||
'size' => 100,
|
||||
]]);
|
||||
|
||||
$this->assertEquals($file, $bag->get('file'));
|
||||
}
|
||||
|
||||
public function testShouldSetEmptyUploadedFilesToNull()
|
||||
{
|
||||
$bag = new FileBag(['file' => [
|
||||
'name' => '',
|
||||
'type' => '',
|
||||
'tmp_name' => '',
|
||||
'error' => \UPLOAD_ERR_NO_FILE,
|
||||
'size' => 0,
|
||||
]]);
|
||||
|
||||
$this->assertNull($bag->get('file'));
|
||||
}
|
||||
|
||||
public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
|
||||
{
|
||||
$bag = new FileBag(['files' => [
|
||||
'name' => [''],
|
||||
'type' => [''],
|
||||
'tmp_name' => [''],
|
||||
'error' => [\UPLOAD_ERR_NO_FILE],
|
||||
'size' => [0],
|
||||
]]);
|
||||
|
||||
$this->assertSame([], $bag->get('files'));
|
||||
}
|
||||
|
||||
public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray()
|
||||
{
|
||||
$bag = new FileBag(['files' => [
|
||||
'name' => ['file1' => ''],
|
||||
'type' => ['file1' => ''],
|
||||
'tmp_name' => ['file1' => ''],
|
||||
'error' => ['file1' => \UPLOAD_ERR_NO_FILE],
|
||||
'size' => ['file1' => 0],
|
||||
]]);
|
||||
|
||||
$this->assertSame(['file1' => null], $bag->get('files'));
|
||||
}
|
||||
|
||||
public function testShouldConvertUploadedFilesWithPhpBug()
|
||||
{
|
||||
$tmpFile = $this->createTempFile();
|
||||
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
||||
|
||||
$bag = new FileBag([
|
||||
'child' => [
|
||||
'name' => [
|
||||
'file' => basename($tmpFile),
|
||||
],
|
||||
'type' => [
|
||||
'file' => 'text/plain',
|
||||
],
|
||||
'tmp_name' => [
|
||||
'file' => $tmpFile,
|
||||
],
|
||||
'error' => [
|
||||
'file' => 0,
|
||||
],
|
||||
'size' => [
|
||||
'file' => 100,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$files = $bag->all();
|
||||
$this->assertEquals($file, $files['child']['file']);
|
||||
}
|
||||
|
||||
public function testShouldConvertNestedUploadedFilesWithPhpBug()
|
||||
{
|
||||
$tmpFile = $this->createTempFile();
|
||||
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
||||
|
||||
$bag = new FileBag([
|
||||
'child' => [
|
||||
'name' => [
|
||||
'sub' => ['file' => basename($tmpFile)],
|
||||
],
|
||||
'type' => [
|
||||
'sub' => ['file' => 'text/plain'],
|
||||
],
|
||||
'tmp_name' => [
|
||||
'sub' => ['file' => $tmpFile],
|
||||
],
|
||||
'error' => [
|
||||
'sub' => ['file' => 0],
|
||||
],
|
||||
'size' => [
|
||||
'sub' => ['file' => 100],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$files = $bag->all();
|
||||
$this->assertEquals($file, $files['child']['sub']['file']);
|
||||
}
|
||||
|
||||
public function testShouldNotConvertNestedUploadedFiles()
|
||||
{
|
||||
$tmpFile = $this->createTempFile();
|
||||
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
||||
$bag = new FileBag(['image' => ['file' => $file]]);
|
||||
|
||||
$files = $bag->all();
|
||||
$this->assertEquals($file, $files['image']['file']);
|
||||
}
|
||||
|
||||
protected function createTempFile()
|
||||
{
|
||||
return tempnam(sys_get_temp_dir().'/form_test', 'FormTest');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
mkdir(sys_get_temp_dir().'/form_test', 0777, true);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
foreach (glob(sys_get_temp_dir().'/form_test/*') as $file) {
|
||||
@unlink($file);
|
||||
}
|
||||
|
||||
@rmdir(sys_get_temp_dir().'/form_test');
|
||||
}
|
||||
}
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Fixtures/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Fixtures/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
43
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Fixtures/response-functional/common.inc
vendored
Normal file
43
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Fixtures/response-functional/common.inc
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
$parent = __DIR__;
|
||||
while (!@file_exists($parent.'/vendor/autoload.php')) {
|
||||
if (!@file_exists($parent)) {
|
||||
// open_basedir restriction in effect
|
||||
break;
|
||||
}
|
||||
if ($parent === dirname($parent)) {
|
||||
echo "vendor/autoload.php not found\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$parent = dirname($parent);
|
||||
}
|
||||
|
||||
require $parent.'/vendor/autoload.php';
|
||||
|
||||
error_reporting(-1);
|
||||
ini_set('html_errors', 0);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
if (filter_var(ini_get('xdebug.default_enable'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
xdebug_disable();
|
||||
}
|
||||
|
||||
header_remove('X-Powered-By');
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
register_shutdown_function(function () {
|
||||
echo "\n";
|
||||
session_write_close();
|
||||
print_r(headers_list());
|
||||
echo "shutdown\n";
|
||||
});
|
||||
ob_start();
|
||||
|
||||
$r = new Response();
|
||||
$r->headers->set('Date', 'Sat, 12 Nov 1955 20:04:00 GMT');
|
||||
|
||||
return $r;
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
Warning: Expiry date cannot have a year greater than 9999 in %scookie_max_age.php on line 10
|
||||
|
||||
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: foo=bar; expires=Sat, 01-Jan-10000 02:46:40 GMT; Max-Age=%d; path=/
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$r->headers->setCookie(new Cookie('foo', 'bar', 253402310800, '', null, false, false));
|
||||
$r->sendHeaders();
|
||||
|
||||
setcookie('foo2', 'bar', 253402310800, '/');
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
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: ?*():@&+$/%#[]=?*():@&+$/%#[]; path=/
|
||||
[4] => Set-Cookie: ?*():@&+$/%#[]=?*():@&+$/%#[]; path=/
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$str = '?*():@&+$/%#[]';
|
||||
|
||||
$r->headers->setCookie(new Cookie($str, $str, 0, '/', null, false, false, true));
|
||||
$r->sendHeaders();
|
||||
|
||||
setrawcookie($str, $str, 0, '/', null, false, false);
|
||||
@@ -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: CookieSamesiteLaxTest=LaxValue; path=/; httponly; samesite=lax
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$r->headers->setCookie(new Cookie('CookieSamesiteLaxTest', 'LaxValue', 0, '/', null, false, true, false, Cookie::SAMESITE_LAX));
|
||||
$r->sendHeaders();
|
||||
@@ -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
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$r->headers->setCookie(new Cookie('CookieSamesiteStrictTest', 'StrictValue', 0, '/', null, false, true, false, Cookie::SAMESITE_STRICT));
|
||||
$r->sendHeaders();
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
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: %3D%2C%3B%20%09%0D%0A%0B%0C=%3D%2C%3B%20%09%0D%0A%0B%0C; path=/
|
||||
[4] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/
|
||||
[5] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
$str1 = "=,; \t\r\n\v\f";
|
||||
$r->headers->setCookie(new Cookie($str1, $str1, 0, '', null, false, false, false, null));
|
||||
|
||||
$str2 = '?*():@&+$/%#[]';
|
||||
|
||||
$r->headers->setCookie(new Cookie($str2, $str2, 0, '', null, false, false, false, null));
|
||||
$r->sendHeaders();
|
||||
|
||||
setcookie($str2, $str2, 0, '/');
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Fixtures/response-functional/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Fixtures/response-functional/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -0,0 +1,6 @@
|
||||
The cookie name "Hello + world" contains invalid characters.
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
try {
|
||||
$r->headers->setCookie(new Cookie('Hello + world', 'hodor', 0, null, null, null, false, true));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
213
modules/ps_metrics/vendor/symfony/http-foundation/Tests/HeaderBagTest.php
vendored
Normal file
213
modules/ps_metrics/vendor/symfony/http-foundation/Tests/HeaderBagTest.php
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\HeaderBag;
|
||||
|
||||
class HeaderBagTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => 'bar']);
|
||||
$this->assertTrue($bag->has('foo'));
|
||||
}
|
||||
|
||||
public function testToStringNull()
|
||||
{
|
||||
$bag = new HeaderBag();
|
||||
$this->assertEquals('', $bag->__toString());
|
||||
}
|
||||
|
||||
public function testToStringNotNull()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => 'bar']);
|
||||
$this->assertEquals("Foo: bar\r\n", $bag->__toString());
|
||||
}
|
||||
|
||||
public function testKeys()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => 'bar']);
|
||||
$keys = $bag->keys();
|
||||
$this->assertEquals('foo', $keys[0]);
|
||||
}
|
||||
|
||||
public function testGetDate()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => 'Tue, 4 Sep 2012 20:00:00 +0200']);
|
||||
$headerDate = $bag->getDate('foo');
|
||||
$this->assertInstanceOf('DateTime', $headerDate);
|
||||
}
|
||||
|
||||
public function testGetDateNull()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => null]);
|
||||
$headerDate = $bag->getDate('foo');
|
||||
$this->assertNull($headerDate);
|
||||
}
|
||||
|
||||
public function testGetDateException()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$bag = new HeaderBag(['foo' => 'Tue']);
|
||||
$bag->getDate('foo');
|
||||
}
|
||||
|
||||
public function testGetCacheControlHeader()
|
||||
{
|
||||
$bag = new HeaderBag();
|
||||
$bag->addCacheControlDirective('public', '#a');
|
||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||
$this->assertEquals('#a', $bag->getCacheControlDirective('public'));
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => 'bar']);
|
||||
$this->assertEquals(['foo' => ['bar']], $bag->all(), '->all() gets all the input');
|
||||
|
||||
$bag = new HeaderBag(['FOO' => 'BAR']);
|
||||
$this->assertEquals(['foo' => ['BAR']], $bag->all(), '->all() gets all the input key are lower case');
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => 'bar']);
|
||||
|
||||
$bag->replace(['NOPE' => 'BAR']);
|
||||
$this->assertEquals(['nope' => ['BAR']], $bag->all(), '->replace() replaces the input with the argument');
|
||||
$this->assertFalse($bag->has('foo'), '->replace() overrides previously set the input');
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => 'bar', 'fuzz' => 'bizz']);
|
||||
$this->assertEquals('bar', $bag->get('foo'), '->get return current value');
|
||||
$this->assertEquals('bar', $bag->get('FoO'), '->get key in case insensitive');
|
||||
$this->assertEquals(['bar'], $bag->get('foo', 'nope', false), '->get return the value as array');
|
||||
|
||||
// defaults
|
||||
$this->assertNull($bag->get('none'), '->get unknown values returns null');
|
||||
$this->assertEquals('default', $bag->get('none', 'default'), '->get unknown values returns default');
|
||||
$this->assertEquals(['default'], $bag->get('none', 'default', false), '->get unknown values returns default as array');
|
||||
|
||||
$bag->set('foo', 'bor', false);
|
||||
$this->assertEquals('bar', $bag->get('foo'), '->get return first value');
|
||||
$this->assertEquals(['bar', 'bor'], $bag->get('foo', 'nope', false), '->get return all values as array');
|
||||
|
||||
$bag->set('baz', null);
|
||||
$this->assertNull($bag->get('baz', 'nope'), '->get return null although different default value is given');
|
||||
}
|
||||
|
||||
public function testSetAssociativeArray()
|
||||
{
|
||||
$bag = new HeaderBag();
|
||||
$bag->set('foo', ['bad-assoc-index' => 'value']);
|
||||
$this->assertSame('value', $bag->get('foo'));
|
||||
$this->assertEquals(['value'], $bag->get('foo', 'nope', false), 'assoc indices of multi-valued headers are ignored');
|
||||
}
|
||||
|
||||
public function testContains()
|
||||
{
|
||||
$bag = new HeaderBag(['foo' => 'bar', 'fuzz' => 'bizz']);
|
||||
$this->assertTrue($bag->contains('foo', 'bar'), '->contains first value');
|
||||
$this->assertTrue($bag->contains('fuzz', 'bizz'), '->contains second value');
|
||||
$this->assertFalse($bag->contains('nope', 'nope'), '->contains unknown value');
|
||||
$this->assertFalse($bag->contains('foo', 'nope'), '->contains unknown value');
|
||||
|
||||
// Multiple values
|
||||
$bag->set('foo', 'bor', false);
|
||||
$this->assertTrue($bag->contains('foo', 'bar'), '->contains first value');
|
||||
$this->assertTrue($bag->contains('foo', 'bor'), '->contains second value');
|
||||
$this->assertFalse($bag->contains('foo', 'nope'), '->contains unknown value');
|
||||
}
|
||||
|
||||
public function testCacheControlDirectiveAccessors()
|
||||
{
|
||||
$bag = new HeaderBag();
|
||||
$bag->addCacheControlDirective('public');
|
||||
|
||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||
$this->assertTrue($bag->getCacheControlDirective('public'));
|
||||
$this->assertEquals('public', $bag->get('cache-control'));
|
||||
|
||||
$bag->addCacheControlDirective('max-age', 10);
|
||||
$this->assertTrue($bag->hasCacheControlDirective('max-age'));
|
||||
$this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
|
||||
$this->assertEquals('max-age=10, public', $bag->get('cache-control'));
|
||||
|
||||
$bag->removeCacheControlDirective('max-age');
|
||||
$this->assertFalse($bag->hasCacheControlDirective('max-age'));
|
||||
}
|
||||
|
||||
public function testCacheControlDirectiveParsing()
|
||||
{
|
||||
$bag = new HeaderBag(['cache-control' => 'public, max-age=10']);
|
||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||
$this->assertTrue($bag->getCacheControlDirective('public'));
|
||||
|
||||
$this->assertTrue($bag->hasCacheControlDirective('max-age'));
|
||||
$this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
|
||||
|
||||
$bag->addCacheControlDirective('s-maxage', 100);
|
||||
$this->assertEquals('max-age=10, public, s-maxage=100', $bag->get('cache-control'));
|
||||
}
|
||||
|
||||
public function testCacheControlDirectiveParsingQuotedZero()
|
||||
{
|
||||
$bag = new HeaderBag(['cache-control' => 'max-age="0"']);
|
||||
$this->assertTrue($bag->hasCacheControlDirective('max-age'));
|
||||
$this->assertEquals(0, $bag->getCacheControlDirective('max-age'));
|
||||
}
|
||||
|
||||
public function testCacheControlDirectiveOverrideWithReplace()
|
||||
{
|
||||
$bag = new HeaderBag(['cache-control' => 'private, max-age=100']);
|
||||
$bag->replace(['cache-control' => 'public, max-age=10']);
|
||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||
$this->assertTrue($bag->getCacheControlDirective('public'));
|
||||
|
||||
$this->assertTrue($bag->hasCacheControlDirective('max-age'));
|
||||
$this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
|
||||
}
|
||||
|
||||
public function testCacheControlClone()
|
||||
{
|
||||
$headers = ['foo' => 'bar'];
|
||||
$bag1 = new HeaderBag($headers);
|
||||
$bag2 = new HeaderBag($bag1->all());
|
||||
|
||||
$this->assertEquals($bag1->all(), $bag2->all());
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$headers = ['foo' => 'bar', 'hello' => 'world', 'third' => 'charm'];
|
||||
$headerBag = new HeaderBag($headers);
|
||||
|
||||
$i = 0;
|
||||
foreach ($headerBag as $key => $val) {
|
||||
++$i;
|
||||
$this->assertEquals([$headers[$key]], $val);
|
||||
}
|
||||
|
||||
$this->assertEquals(\count($headers), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$headers = ['foo' => 'bar', 'HELLO' => 'WORLD'];
|
||||
$headerBag = new HeaderBag($headers);
|
||||
|
||||
$this->assertCount(\count($headers), $headerBag);
|
||||
}
|
||||
}
|
||||
104
modules/ps_metrics/vendor/symfony/http-foundation/Tests/IpUtilsTest.php
vendored
Normal file
104
modules/ps_metrics/vendor/symfony/http-foundation/Tests/IpUtilsTest.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
|
||||
class IpUtilsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getIpv4Data
|
||||
*/
|
||||
public function testIpv4($matches, $remoteAddr, $cidr)
|
||||
{
|
||||
$this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr));
|
||||
}
|
||||
|
||||
public function getIpv4Data()
|
||||
{
|
||||
return [
|
||||
[true, '192.168.1.1', '192.168.1.1'],
|
||||
[true, '192.168.1.1', '192.168.1.1/1'],
|
||||
[true, '192.168.1.1', '192.168.1.0/24'],
|
||||
[false, '192.168.1.1', '1.2.3.4/1'],
|
||||
[false, '192.168.1.1', '192.168.1.1/33'], // invalid subnet
|
||||
[true, '192.168.1.1', ['1.2.3.4/1', '192.168.1.0/24']],
|
||||
[true, '192.168.1.1', ['192.168.1.0/24', '1.2.3.4/1']],
|
||||
[false, '192.168.1.1', ['1.2.3.4/1', '4.3.2.1/1']],
|
||||
[true, '1.2.3.4', '0.0.0.0/0'],
|
||||
[true, '1.2.3.4', '192.168.1.0/0'],
|
||||
[false, '1.2.3.4', '256.256.256/0'], // invalid CIDR notation
|
||||
[false, 'an_invalid_ip', '192.168.1.0/24'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getIpv6Data
|
||||
*/
|
||||
public function testIpv6($matches, $remoteAddr, $cidr)
|
||||
{
|
||||
if (!\defined('AF_INET6')) {
|
||||
$this->markTestSkipped('Only works when PHP is compiled without the option "disable-ipv6".');
|
||||
}
|
||||
|
||||
$this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr));
|
||||
}
|
||||
|
||||
public function getIpv6Data()
|
||||
{
|
||||
return [
|
||||
[true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'],
|
||||
[false, '2a00:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'],
|
||||
[false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'],
|
||||
[true, '0:0:0:0:0:0:0:1', '::1'],
|
||||
[false, '0:0:603:0:396e:4789:8e99:0001', '::1'],
|
||||
[true, '0:0:603:0:396e:4789:8e99:0001', '::/0'],
|
||||
[true, '0:0:603:0:396e:4789:8e99:0001', '2a01:198:603:0::/0'],
|
||||
[true, '2a01:198:603:0:396e:4789:8e99:890f', ['::1', '2a01:198:603:0::/65']],
|
||||
[true, '2a01:198:603:0:396e:4789:8e99:890f', ['2a01:198:603:0::/65', '::1']],
|
||||
[false, '2a01:198:603:0:396e:4789:8e99:890f', ['::1', '1a01:198:603:0::/65']],
|
||||
[false, '}__test|O:21:"JDatabaseDriverMysqli":3:{s:2', '::1'],
|
||||
[false, '2a01:198:603:0:396e:4789:8e99:890f', 'unknown'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension sockets
|
||||
*/
|
||||
public function testAnIpv6WithOptionDisabledIpv6()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
if (\defined('AF_INET6')) {
|
||||
$this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".');
|
||||
}
|
||||
|
||||
IpUtils::checkIp('2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidIpAddressData
|
||||
*/
|
||||
public function testInvalidIpAddressesDoNotMatch($requestIp, $proxyIp)
|
||||
{
|
||||
$this->assertFalse(IpUtils::checkIp4($requestIp, $proxyIp));
|
||||
}
|
||||
|
||||
public function invalidIpAddressData()
|
||||
{
|
||||
return [
|
||||
'invalid proxy wildcard' => ['192.168.20.13', '*'],
|
||||
'invalid proxy missing netmask' => ['192.168.20.13', '0.0.0.0'],
|
||||
'invalid request IP with invalid proxy wildcard' => ['0.0.0.0', '*'],
|
||||
];
|
||||
}
|
||||
}
|
||||
262
modules/ps_metrics/vendor/symfony/http-foundation/Tests/JsonResponseTest.php
vendored
Normal file
262
modules/ps_metrics/vendor/symfony/http-foundation/Tests/JsonResponseTest.php
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
class JsonResponseTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!\defined('HHVM_VERSION')) {
|
||||
$this->iniSet('serialize_precision', 14);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstructorEmptyCreatesJsonObject()
|
||||
{
|
||||
$response = new JsonResponse();
|
||||
$this->assertSame('{}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testConstructorWithArrayCreatesJsonArray()
|
||||
{
|
||||
$response = new JsonResponse([0, 1, 2, 3]);
|
||||
$this->assertSame('[0,1,2,3]', $response->getContent());
|
||||
}
|
||||
|
||||
public function testConstructorWithAssocArrayCreatesJsonObject()
|
||||
{
|
||||
$response = new JsonResponse(['foo' => 'bar']);
|
||||
$this->assertSame('{"foo":"bar"}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testConstructorWithSimpleTypes()
|
||||
{
|
||||
$response = new JsonResponse('foo');
|
||||
$this->assertSame('"foo"', $response->getContent());
|
||||
|
||||
$response = new JsonResponse(0);
|
||||
$this->assertSame('0', $response->getContent());
|
||||
|
||||
$response = new JsonResponse(0.1);
|
||||
$this->assertEquals(0.1, $response->getContent());
|
||||
$this->assertIsString($response->getContent());
|
||||
|
||||
$response = new JsonResponse(true);
|
||||
$this->assertSame('true', $response->getContent());
|
||||
}
|
||||
|
||||
public function testConstructorWithCustomStatus()
|
||||
{
|
||||
$response = new JsonResponse([], 202);
|
||||
$this->assertSame(202, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testConstructorAddsContentTypeHeader()
|
||||
{
|
||||
$response = new JsonResponse();
|
||||
$this->assertSame('application/json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testConstructorWithCustomHeaders()
|
||||
{
|
||||
$response = new JsonResponse([], 200, ['ETag' => 'foo']);
|
||||
$this->assertSame('application/json', $response->headers->get('Content-Type'));
|
||||
$this->assertSame('foo', $response->headers->get('ETag'));
|
||||
}
|
||||
|
||||
public function testConstructorWithCustomContentType()
|
||||
{
|
||||
$headers = ['Content-Type' => 'application/vnd.acme.blog-v1+json'];
|
||||
|
||||
$response = new JsonResponse([], 200, $headers);
|
||||
$this->assertSame('application/vnd.acme.blog-v1+json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testSetJson()
|
||||
{
|
||||
$response = new JsonResponse('1', 200, [], true);
|
||||
$this->assertEquals('1', $response->getContent());
|
||||
|
||||
$response = new JsonResponse('[1]', 200, [], true);
|
||||
$this->assertEquals('[1]', $response->getContent());
|
||||
|
||||
$response = new JsonResponse(null, 200, []);
|
||||
$response->setJson('true');
|
||||
$this->assertEquals('true', $response->getContent());
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$response = JsonResponse::create(['foo' => 'bar'], 204);
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertEquals('{"foo":"bar"}', $response->getContent());
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testStaticCreateEmptyJsonObject()
|
||||
{
|
||||
$response = JsonResponse::create();
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertSame('{}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testStaticCreateJsonArray()
|
||||
{
|
||||
$response = JsonResponse::create([0, 1, 2, 3]);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertSame('[0,1,2,3]', $response->getContent());
|
||||
}
|
||||
|
||||
public function testStaticCreateJsonObject()
|
||||
{
|
||||
$response = JsonResponse::create(['foo' => 'bar']);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertSame('{"foo":"bar"}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testStaticCreateWithSimpleTypes()
|
||||
{
|
||||
$response = JsonResponse::create('foo');
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertSame('"foo"', $response->getContent());
|
||||
|
||||
$response = JsonResponse::create(0);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertSame('0', $response->getContent());
|
||||
|
||||
$response = JsonResponse::create(0.1);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertEquals(0.1, $response->getContent());
|
||||
$this->assertIsString($response->getContent());
|
||||
|
||||
$response = JsonResponse::create(true);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertSame('true', $response->getContent());
|
||||
}
|
||||
|
||||
public function testStaticCreateWithCustomStatus()
|
||||
{
|
||||
$response = JsonResponse::create([], 202);
|
||||
$this->assertSame(202, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testStaticCreateAddsContentTypeHeader()
|
||||
{
|
||||
$response = JsonResponse::create();
|
||||
$this->assertSame('application/json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testStaticCreateWithCustomHeaders()
|
||||
{
|
||||
$response = JsonResponse::create([], 200, ['ETag' => 'foo']);
|
||||
$this->assertSame('application/json', $response->headers->get('Content-Type'));
|
||||
$this->assertSame('foo', $response->headers->get('ETag'));
|
||||
}
|
||||
|
||||
public function testStaticCreateWithCustomContentType()
|
||||
{
|
||||
$headers = ['Content-Type' => 'application/vnd.acme.blog-v1+json'];
|
||||
|
||||
$response = JsonResponse::create([], 200, $headers);
|
||||
$this->assertSame('application/vnd.acme.blog-v1+json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testSetCallback()
|
||||
{
|
||||
$response = JsonResponse::create(['foo' => 'bar'])->setCallback('callback');
|
||||
|
||||
$this->assertEquals('/**/callback({"foo":"bar"});', $response->getContent());
|
||||
$this->assertEquals('text/javascript', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testJsonEncodeFlags()
|
||||
{
|
||||
$response = new JsonResponse('<>\'&"');
|
||||
|
||||
$this->assertEquals('"\u003C\u003E\u0027\u0026\u0022"', $response->getContent());
|
||||
}
|
||||
|
||||
public function testGetEncodingOptions()
|
||||
{
|
||||
$response = new JsonResponse();
|
||||
|
||||
$this->assertEquals(\JSON_HEX_TAG | \JSON_HEX_APOS | \JSON_HEX_AMP | \JSON_HEX_QUOT, $response->getEncodingOptions());
|
||||
}
|
||||
|
||||
public function testSetEncodingOptions()
|
||||
{
|
||||
$response = new JsonResponse();
|
||||
$response->setData([[1, 2, 3]]);
|
||||
|
||||
$this->assertEquals('[[1,2,3]]', $response->getContent());
|
||||
|
||||
$response->setEncodingOptions(\JSON_FORCE_OBJECT);
|
||||
|
||||
$this->assertEquals('{"0":{"0":1,"1":2,"2":3}}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testItAcceptsJsonAsString()
|
||||
{
|
||||
$response = JsonResponse::fromJsonString('{"foo":"bar"}');
|
||||
$this->assertSame('{"foo":"bar"}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testSetCallbackInvalidIdentifier()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$response = new JsonResponse('foo');
|
||||
$response->setCallback('+invalid');
|
||||
}
|
||||
|
||||
public function testSetContent()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
JsonResponse::create("\xB1\x31");
|
||||
}
|
||||
|
||||
public function testSetContentJsonSerializeError()
|
||||
{
|
||||
$this->expectException('Exception');
|
||||
$this->expectExceptionMessage('This error is expected');
|
||||
if (!interface_exists('JsonSerializable', false)) {
|
||||
$this->markTestSkipped('JsonSerializable is required.');
|
||||
}
|
||||
|
||||
$serializable = new JsonSerializableObject();
|
||||
|
||||
JsonResponse::create($serializable);
|
||||
}
|
||||
|
||||
public function testSetComplexCallback()
|
||||
{
|
||||
$response = JsonResponse::create(['foo' => 'bar']);
|
||||
$response->setCallback('ಠ_ಠ["foo"].bar[0]');
|
||||
|
||||
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({"foo":"bar"});', $response->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
if (interface_exists('JsonSerializable', false)) {
|
||||
class JsonSerializableObject implements \JsonSerializable
|
||||
{
|
||||
public function jsonSerialize()
|
||||
{
|
||||
throw new \Exception('This error is expected');
|
||||
}
|
||||
}
|
||||
}
|
||||
194
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ParameterBagTest.php
vendored
Normal file
194
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ParameterBagTest.php
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
class ParameterBagTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->testAll();
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$bag = new ParameterBag(['foo' => 'bar']);
|
||||
$this->assertEquals(['foo' => 'bar'], $bag->all(), '->all() gets all the input');
|
||||
}
|
||||
|
||||
public function testKeys()
|
||||
{
|
||||
$bag = new ParameterBag(['foo' => 'bar']);
|
||||
$this->assertEquals(['foo'], $bag->keys());
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$bag = new ParameterBag(['foo' => 'bar']);
|
||||
$bag->add(['bar' => 'bas']);
|
||||
$this->assertEquals(['foo' => 'bar', 'bar' => 'bas'], $bag->all());
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$bag = new ParameterBag(['foo' => 'bar']);
|
||||
$bag->add(['bar' => 'bas']);
|
||||
$this->assertEquals(['foo' => 'bar', 'bar' => 'bas'], $bag->all());
|
||||
$bag->remove('bar');
|
||||
$this->assertEquals(['foo' => 'bar'], $bag->all());
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$bag = new ParameterBag(['foo' => 'bar']);
|
||||
|
||||
$bag->replace(['FOO' => 'BAR']);
|
||||
$this->assertEquals(['FOO' => 'BAR'], $bag->all(), '->replace() replaces the input with the argument');
|
||||
$this->assertFalse($bag->has('foo'), '->replace() overrides previously set the input');
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$bag = new ParameterBag(['foo' => 'bar', 'null' => null]);
|
||||
|
||||
$this->assertEquals('bar', $bag->get('foo'), '->get() gets the value of a parameter');
|
||||
$this->assertEquals('default', $bag->get('unknown', 'default'), '->get() returns second argument as default if a parameter is not defined');
|
||||
$this->assertNull($bag->get('null', 'default'), '->get() returns null if null is set');
|
||||
}
|
||||
|
||||
public function testGetDoesNotUseDeepByDefault()
|
||||
{
|
||||
$bag = new ParameterBag(['foo' => ['bar' => 'moo']]);
|
||||
|
||||
$this->assertNull($bag->get('foo[bar]'));
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$bag = new ParameterBag([]);
|
||||
|
||||
$bag->set('foo', 'bar');
|
||||
$this->assertEquals('bar', $bag->get('foo'), '->set() sets the value of parameter');
|
||||
|
||||
$bag->set('foo', 'baz');
|
||||
$this->assertEquals('baz', $bag->get('foo'), '->set() overrides previously set parameter');
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$bag = new ParameterBag(['foo' => 'bar']);
|
||||
|
||||
$this->assertTrue($bag->has('foo'), '->has() returns true if a parameter is defined');
|
||||
$this->assertFalse($bag->has('unknown'), '->has() return false if a parameter is not defined');
|
||||
}
|
||||
|
||||
public function testGetAlpha()
|
||||
{
|
||||
$bag = new ParameterBag(['word' => 'foo_BAR_012']);
|
||||
|
||||
$this->assertEquals('fooBAR', $bag->getAlpha('word'), '->getAlpha() gets only alphabetic characters');
|
||||
$this->assertEquals('', $bag->getAlpha('unknown'), '->getAlpha() returns empty string if a parameter is not defined');
|
||||
}
|
||||
|
||||
public function testGetAlnum()
|
||||
{
|
||||
$bag = new ParameterBag(['word' => 'foo_BAR_012']);
|
||||
|
||||
$this->assertEquals('fooBAR012', $bag->getAlnum('word'), '->getAlnum() gets only alphanumeric characters');
|
||||
$this->assertEquals('', $bag->getAlnum('unknown'), '->getAlnum() returns empty string if a parameter is not defined');
|
||||
}
|
||||
|
||||
public function testGetDigits()
|
||||
{
|
||||
$bag = new ParameterBag(['word' => 'foo_BAR_012']);
|
||||
|
||||
$this->assertEquals('012', $bag->getDigits('word'), '->getDigits() gets only digits as string');
|
||||
$this->assertEquals('', $bag->getDigits('unknown'), '->getDigits() returns empty string if a parameter is not defined');
|
||||
}
|
||||
|
||||
public function testGetInt()
|
||||
{
|
||||
$bag = new ParameterBag(['digits' => '0123']);
|
||||
|
||||
$this->assertEquals(123, $bag->getInt('digits'), '->getInt() gets a value of parameter as integer');
|
||||
$this->assertEquals(0, $bag->getInt('unknown'), '->getInt() returns zero if a parameter is not defined');
|
||||
}
|
||||
|
||||
public function testFilter()
|
||||
{
|
||||
$bag = new ParameterBag([
|
||||
'digits' => '0123ab',
|
||||
'email' => 'example@example.com',
|
||||
'url' => 'http://example.com/foo',
|
||||
'dec' => '256',
|
||||
'hex' => '0x100',
|
||||
'array' => ['bang'],
|
||||
]);
|
||||
|
||||
$this->assertEmpty($bag->filter('nokey'), '->filter() should return empty by default if no key is found');
|
||||
|
||||
$this->assertEquals('0123', $bag->filter('digits', '', \FILTER_SANITIZE_NUMBER_INT), '->filter() gets a value of parameter as integer filtering out invalid characters');
|
||||
|
||||
$this->assertEquals('example@example.com', $bag->filter('email', '', \FILTER_VALIDATE_EMAIL), '->filter() gets a value of parameter as email');
|
||||
|
||||
$this->assertEquals('http://example.com/foo', $bag->filter('url', '', \FILTER_VALIDATE_URL, ['flags' => \FILTER_FLAG_PATH_REQUIRED]), '->filter() gets a value of parameter as URL with a path');
|
||||
|
||||
// This test is repeated for code-coverage
|
||||
$this->assertEquals('http://example.com/foo', $bag->filter('url', '', \FILTER_VALIDATE_URL, \FILTER_FLAG_PATH_REQUIRED), '->filter() gets a value of parameter as URL with a path');
|
||||
|
||||
$this->assertFalse($bag->filter('dec', '', \FILTER_VALIDATE_INT, [
|
||||
'flags' => \FILTER_FLAG_ALLOW_HEX,
|
||||
'options' => ['min_range' => 1, 'max_range' => 0xff],
|
||||
]), '->filter() gets a value of parameter as integer between boundaries');
|
||||
|
||||
$this->assertFalse($bag->filter('hex', '', \FILTER_VALIDATE_INT, [
|
||||
'flags' => \FILTER_FLAG_ALLOW_HEX,
|
||||
'options' => ['min_range' => 1, 'max_range' => 0xff],
|
||||
]), '->filter() gets a value of parameter as integer between boundaries');
|
||||
|
||||
$this->assertEquals(['bang'], $bag->filter('array', ''), '->filter() gets a value of parameter as an array');
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$parameters = ['foo' => 'bar', 'hello' => 'world'];
|
||||
$bag = new ParameterBag($parameters);
|
||||
|
||||
$i = 0;
|
||||
foreach ($bag as $key => $val) {
|
||||
++$i;
|
||||
$this->assertEquals($parameters[$key], $val);
|
||||
}
|
||||
|
||||
$this->assertEquals(\count($parameters), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$parameters = ['foo' => 'bar', 'hello' => 'world'];
|
||||
$bag = new ParameterBag($parameters);
|
||||
|
||||
$this->assertCount(\count($parameters), $bag);
|
||||
}
|
||||
|
||||
public function testGetBoolean()
|
||||
{
|
||||
$parameters = ['string_true' => 'true', 'string_false' => 'false'];
|
||||
$bag = new ParameterBag($parameters);
|
||||
|
||||
$this->assertTrue($bag->getBoolean('string_true'), '->getBoolean() gets the string true as boolean true');
|
||||
$this->assertFalse($bag->getBoolean('string_false'), '->getBoolean() gets the string false as boolean false');
|
||||
$this->assertFalse($bag->getBoolean('unknown'), '->getBoolean() returns false if a parameter is not defined');
|
||||
}
|
||||
}
|
||||
92
modules/ps_metrics/vendor/symfony/http-foundation/Tests/RedirectResponseTest.php
vendored
Normal file
92
modules/ps_metrics/vendor/symfony/http-foundation/Tests/RedirectResponseTest.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
class RedirectResponseTest extends TestCase
|
||||
{
|
||||
public function testGenerateMetaRedirect()
|
||||
{
|
||||
$response = new RedirectResponse('foo.bar');
|
||||
|
||||
$this->assertMatchesRegularExpression('#<meta http-equiv="refresh" content="\d+;url=\'foo\.bar\'" />#', preg_replace('/\s+/', ' ', $response->getContent()));
|
||||
}
|
||||
|
||||
public function testRedirectResponseConstructorNullUrl()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new RedirectResponse(null);
|
||||
}
|
||||
|
||||
public function testRedirectResponseConstructorWrongStatusCode()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new RedirectResponse('foo.bar', 404);
|
||||
}
|
||||
|
||||
public function testGenerateLocationHeader()
|
||||
{
|
||||
$response = new RedirectResponse('foo.bar');
|
||||
|
||||
$this->assertTrue($response->headers->has('Location'));
|
||||
$this->assertEquals('foo.bar', $response->headers->get('Location'));
|
||||
}
|
||||
|
||||
public function testGetTargetUrl()
|
||||
{
|
||||
$response = new RedirectResponse('foo.bar');
|
||||
|
||||
$this->assertEquals('foo.bar', $response->getTargetUrl());
|
||||
}
|
||||
|
||||
public function testSetTargetUrl()
|
||||
{
|
||||
$response = new RedirectResponse('foo.bar');
|
||||
$response->setTargetUrl('baz.beep');
|
||||
|
||||
$this->assertEquals('baz.beep', $response->getTargetUrl());
|
||||
}
|
||||
|
||||
public function testSetTargetUrlNull()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$response = new RedirectResponse('foo.bar');
|
||||
$response->setTargetUrl(null);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$response = RedirectResponse::create('foo', 301);
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
|
||||
$this->assertEquals(301, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testCacheHeaders()
|
||||
{
|
||||
$response = new RedirectResponse('foo.bar', 301);
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$response = new RedirectResponse('foo.bar', 301, ['cache-control' => 'max-age=86400']);
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));
|
||||
|
||||
$response = new RedirectResponse('foo.bar', 301, ['Cache-Control' => 'max-age=86400']);
|
||||
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));
|
||||
|
||||
$response = new RedirectResponse('foo.bar', 302);
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective('no-cache'));
|
||||
}
|
||||
}
|
||||
151
modules/ps_metrics/vendor/symfony/http-foundation/Tests/RequestMatcherTest.php
vendored
Normal file
151
modules/ps_metrics/vendor/symfony/http-foundation/Tests/RequestMatcherTest.php
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestMatcher;
|
||||
|
||||
class RequestMatcherTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getMethodData
|
||||
*/
|
||||
public function testMethod($requestMethod, $matcherMethod, $isMatch)
|
||||
{
|
||||
$matcher = new RequestMatcher();
|
||||
$matcher->matchMethod($matcherMethod);
|
||||
$request = Request::create('', $requestMethod);
|
||||
$this->assertSame($isMatch, $matcher->matches($request));
|
||||
|
||||
$matcher = new RequestMatcher(null, null, $matcherMethod);
|
||||
$request = Request::create('', $requestMethod);
|
||||
$this->assertSame($isMatch, $matcher->matches($request));
|
||||
}
|
||||
|
||||
public function getMethodData()
|
||||
{
|
||||
return [
|
||||
['get', 'get', true],
|
||||
['get', ['get', 'post'], true],
|
||||
['get', 'post', false],
|
||||
['get', 'GET', true],
|
||||
['get', ['GET', 'POST'], true],
|
||||
['get', 'POST', false],
|
||||
];
|
||||
}
|
||||
|
||||
public function testScheme()
|
||||
{
|
||||
$httpRequest = $request = $request = Request::create('');
|
||||
$httpsRequest = $request = $request = Request::create('', 'get', [], [], [], ['HTTPS' => 'on']);
|
||||
|
||||
$matcher = new RequestMatcher();
|
||||
$matcher->matchScheme('https');
|
||||
$this->assertFalse($matcher->matches($httpRequest));
|
||||
$this->assertTrue($matcher->matches($httpsRequest));
|
||||
|
||||
$matcher->matchScheme('http');
|
||||
$this->assertFalse($matcher->matches($httpsRequest));
|
||||
$this->assertTrue($matcher->matches($httpRequest));
|
||||
|
||||
$matcher = new RequestMatcher();
|
||||
$this->assertTrue($matcher->matches($httpsRequest));
|
||||
$this->assertTrue($matcher->matches($httpRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getHostData
|
||||
*/
|
||||
public function testHost($pattern, $isMatch)
|
||||
{
|
||||
$matcher = new RequestMatcher();
|
||||
$request = Request::create('', 'get', [], [], [], ['HTTP_HOST' => 'foo.example.com']);
|
||||
|
||||
$matcher->matchHost($pattern);
|
||||
$this->assertSame($isMatch, $matcher->matches($request));
|
||||
|
||||
$matcher = new RequestMatcher(null, $pattern);
|
||||
$this->assertSame($isMatch, $matcher->matches($request));
|
||||
}
|
||||
|
||||
public function getHostData()
|
||||
{
|
||||
return [
|
||||
['.*\.example\.com', true],
|
||||
['\.example\.com$', true],
|
||||
['^.*\.example\.com$', true],
|
||||
['.*\.sensio\.com', false],
|
||||
['.*\.example\.COM', true],
|
||||
['\.example\.COM$', true],
|
||||
['^.*\.example\.COM$', true],
|
||||
['.*\.sensio\.COM', false],
|
||||
];
|
||||
}
|
||||
|
||||
public function testPath()
|
||||
{
|
||||
$matcher = new RequestMatcher();
|
||||
|
||||
$request = Request::create('/admin/foo');
|
||||
|
||||
$matcher->matchPath('/admin/.*');
|
||||
$this->assertTrue($matcher->matches($request));
|
||||
|
||||
$matcher->matchPath('/admin');
|
||||
$this->assertTrue($matcher->matches($request));
|
||||
|
||||
$matcher->matchPath('^/admin/.*$');
|
||||
$this->assertTrue($matcher->matches($request));
|
||||
|
||||
$matcher->matchMethod('/blog/.*');
|
||||
$this->assertFalse($matcher->matches($request));
|
||||
}
|
||||
|
||||
public function testPathWithLocaleIsNotSupported()
|
||||
{
|
||||
$matcher = new RequestMatcher();
|
||||
$request = Request::create('/en/login');
|
||||
$request->setLocale('en');
|
||||
|
||||
$matcher->matchPath('^/{_locale}/login$');
|
||||
$this->assertFalse($matcher->matches($request));
|
||||
}
|
||||
|
||||
public function testPathWithEncodedCharacters()
|
||||
{
|
||||
$matcher = new RequestMatcher();
|
||||
$request = Request::create('/admin/fo%20o');
|
||||
$matcher->matchPath('^/admin/fo o*$');
|
||||
$this->assertTrue($matcher->matches($request));
|
||||
}
|
||||
|
||||
public function testAttributes()
|
||||
{
|
||||
$matcher = new RequestMatcher();
|
||||
|
||||
$request = Request::create('/admin/foo');
|
||||
$request->attributes->set('foo', 'foo_bar');
|
||||
|
||||
$matcher->matchAttribute('foo', 'foo_.*');
|
||||
$this->assertTrue($matcher->matches($request));
|
||||
|
||||
$matcher->matchAttribute('foo', 'foo');
|
||||
$this->assertTrue($matcher->matches($request));
|
||||
|
||||
$matcher->matchAttribute('foo', '^foo_bar$');
|
||||
$this->assertTrue($matcher->matches($request));
|
||||
|
||||
$matcher->matchAttribute('foo', 'babar');
|
||||
$this->assertFalse($matcher->matches($request));
|
||||
}
|
||||
}
|
||||
70
modules/ps_metrics/vendor/symfony/http-foundation/Tests/RequestStackTest.php
vendored
Normal file
70
modules/ps_metrics/vendor/symfony/http-foundation/Tests/RequestStackTest.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class RequestStackTest extends TestCase
|
||||
{
|
||||
public function testGetCurrentRequest()
|
||||
{
|
||||
$requestStack = new RequestStack();
|
||||
$this->assertNull($requestStack->getCurrentRequest());
|
||||
|
||||
$request = Request::create('/foo');
|
||||
|
||||
$requestStack->push($request);
|
||||
$this->assertSame($request, $requestStack->getCurrentRequest());
|
||||
|
||||
$this->assertSame($request, $requestStack->pop());
|
||||
$this->assertNull($requestStack->getCurrentRequest());
|
||||
|
||||
$this->assertNull($requestStack->pop());
|
||||
}
|
||||
|
||||
public function testGetMasterRequest()
|
||||
{
|
||||
$requestStack = new RequestStack();
|
||||
$this->assertNull($requestStack->getMasterRequest());
|
||||
|
||||
$masterRequest = Request::create('/foo');
|
||||
$subRequest = Request::create('/bar');
|
||||
|
||||
$requestStack->push($masterRequest);
|
||||
$requestStack->push($subRequest);
|
||||
|
||||
$this->assertSame($masterRequest, $requestStack->getMasterRequest());
|
||||
}
|
||||
|
||||
public function testGetParentRequest()
|
||||
{
|
||||
$requestStack = new RequestStack();
|
||||
$this->assertNull($requestStack->getParentRequest());
|
||||
|
||||
$masterRequest = Request::create('/foo');
|
||||
|
||||
$requestStack->push($masterRequest);
|
||||
$this->assertNull($requestStack->getParentRequest());
|
||||
|
||||
$firstSubRequest = Request::create('/bar');
|
||||
|
||||
$requestStack->push($firstSubRequest);
|
||||
$this->assertSame($masterRequest, $requestStack->getParentRequest());
|
||||
|
||||
$secondSubRequest = Request::create('/baz');
|
||||
|
||||
$requestStack->push($secondSubRequest);
|
||||
$this->assertSame($firstSubRequest, $requestStack->getParentRequest());
|
||||
}
|
||||
}
|
||||
2451
modules/ps_metrics/vendor/symfony/http-foundation/Tests/RequestTest.php
vendored
Normal file
2451
modules/ps_metrics/vendor/symfony/http-foundation/Tests/RequestTest.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
62
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ResponseFunctionalTest.php
vendored
Normal file
62
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ResponseFunctionalTest.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
class ResponseFunctionalTest extends TestCase
|
||||
{
|
||||
private static $server;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$spec = [
|
||||
1 => ['file', '/dev/null', 'w'],
|
||||
2 => ['file', '/dev/null', 'w'],
|
||||
];
|
||||
if (!self::$server = @proc_open('exec php -S localhost:8054', $spec, $pipes, __DIR__.'/Fixtures/response-functional')) {
|
||||
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 testCookie($fixture)
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 80000 && 'cookie_max_age' === $fixture) {
|
||||
$this->markTestSkipped('This fixture produces a fatal error on PHP 8.');
|
||||
}
|
||||
|
||||
$result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture));
|
||||
$this->assertStringMatchesFormatFile(__DIR__.sprintf('/Fixtures/response-functional/%s.expected', $fixture), $result);
|
||||
}
|
||||
|
||||
public function provideCookie()
|
||||
{
|
||||
foreach (glob(__DIR__.'/Fixtures/response-functional/*.php') as $file) {
|
||||
yield [pathinfo($file, \PATHINFO_FILENAME)];
|
||||
}
|
||||
}
|
||||
}
|
||||
367
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ResponseHeaderBagTest.php
vendored
Normal file
367
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ResponseHeaderBagTest.php
vendored
Normal file
@@ -0,0 +1,367 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class ResponseHeaderBagTest extends TestCase
|
||||
{
|
||||
public function testAllPreserveCase()
|
||||
{
|
||||
$headers = [
|
||||
'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([]);
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['Cache-Control' => 'public']);
|
||||
$this->assertEquals('public', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['ETag' => 'abcde']);
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('private'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
$this->assertFalse($bag->hasCacheControlDirective('max-age'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['Expires' => 'Wed, 16 Feb 2011 14:17:43 GMT']);
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag([
|
||||
'Expires' => 'Wed, 16 Feb 2011 14:17:43 GMT',
|
||||
'Cache-Control' => 'max-age=3600',
|
||||
]);
|
||||
$this->assertEquals('max-age=3600, private', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['Last-Modified' => 'abcde']);
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['Etag' => 'abcde', 'Last-Modified' => 'abcde']);
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['cache-control' => 'max-age=100']);
|
||||
$this->assertEquals('max-age=100, private', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['cache-control' => 's-maxage=100']);
|
||||
$this->assertEquals('s-maxage=100', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['cache-control' => 'private, max-age=100']);
|
||||
$this->assertEquals('max-age=100, private', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(['cache-control' => 'public, max-age=100']);
|
||||
$this->assertEquals('max-age=100, public', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Last-Modified', 'abcde');
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Cache-Control', ['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 = ['foo' => 'bar'];
|
||||
$bag1 = new ResponseHeaderBag($headers);
|
||||
$bag2 = new ResponseHeaderBag($bag1->allPreserveCase());
|
||||
$this->assertEquals($bag1->allPreserveCase(), $bag2->allPreserveCase());
|
||||
}
|
||||
|
||||
public function testToStringIncludesCookieHeaders()
|
||||
{
|
||||
$bag = new ResponseHeaderBag([]);
|
||||
$bag->setCookie(new Cookie('foo', 'bar'));
|
||||
|
||||
$this->assertSetCookieHeader('foo=bar; path=/; httponly', $bag);
|
||||
|
||||
$bag->clearCookie('foo');
|
||||
|
||||
$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()
|
||||
{
|
||||
$bag = new ResponseHeaderBag([]);
|
||||
|
||||
$bag->clearCookie('foo', '/', null, true, false);
|
||||
|
||||
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure', $bag);
|
||||
}
|
||||
|
||||
public function testClearCookieSamesite()
|
||||
{
|
||||
$bag = new ResponseHeaderBag([]);
|
||||
|
||||
$bag->clearCookie('foo', '/', null, true, false, 'none');
|
||||
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure; samesite=none', $bag);
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$bag = new ResponseHeaderBag([]);
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag->replace(['Cache-Control' => 'public']);
|
||||
$this->assertEquals('public', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||
}
|
||||
|
||||
public function testReplaceWithRemove()
|
||||
{
|
||||
$bag = new ResponseHeaderBag([]);
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag->remove('Cache-Control');
|
||||
$bag->replace([]);
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
}
|
||||
|
||||
public function testCookiesWithSameNames()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/foo', 'foo.bar'));
|
||||
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/bar', 'foo.bar'));
|
||||
$bag->setCookie(new Cookie('foo', 'bar', 0, '/path/bar', 'bar.foo'));
|
||||
$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([
|
||||
'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));
|
||||
|
||||
$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->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->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->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->assertArrayNotHasKey('foo.bar', $cookies);
|
||||
}
|
||||
|
||||
public function testRemoveCookieWithNullRemove()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->setCookie(new Cookie('foo', 'bar', 0));
|
||||
$bag->setCookie(new Cookie('bar', 'foo', 0));
|
||||
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$this->assertArrayHasKey('/', $cookies['']);
|
||||
|
||||
$bag->removeCookie('foo', null);
|
||||
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||
$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([new Cookie('foo', 'bar', 0, '/', null, false, false, true)], $bag->getCookies());
|
||||
|
||||
$bag->set('set-cookie', 'foo2=bar2', false);
|
||||
$this->assertEquals([
|
||||
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([], $bag->getCookies());
|
||||
}
|
||||
|
||||
public function testGetCookiesWithInvalidArgument()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$bag = new ResponseHeaderBag();
|
||||
|
||||
$bag->getCookies('invalid_argument');
|
||||
}
|
||||
|
||||
public function testMakeDispositionInvalidDisposition()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$headers = new ResponseHeaderBag();
|
||||
|
||||
$headers->makeDisposition('invalid', 'foo.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideMakeDisposition
|
||||
*/
|
||||
public function testMakeDisposition($disposition, $filename, $filenameFallback, $expected)
|
||||
{
|
||||
$headers = new ResponseHeaderBag();
|
||||
|
||||
$this->assertEquals($expected, $headers->makeDisposition($disposition, $filename, $filenameFallback));
|
||||
}
|
||||
|
||||
public function testToStringDoesntMessUpHeaders()
|
||||
{
|
||||
$headers = new ResponseHeaderBag();
|
||||
|
||||
$headers->set('Location', 'http://www.symfony.com');
|
||||
$headers->set('Content-type', 'text/html');
|
||||
|
||||
(string) $headers;
|
||||
|
||||
$allHeaders = $headers->allPreserveCase();
|
||||
$this->assertEquals(['http://www.symfony.com'], $allHeaders['Location']);
|
||||
$this->assertEquals(['text/html'], $allHeaders['Content-type']);
|
||||
}
|
||||
|
||||
public function provideMakeDisposition()
|
||||
{
|
||||
return [
|
||||
['attachment', 'foo.html', 'foo.html', 'attachment; filename="foo.html"'],
|
||||
['attachment', 'foo.html', '', 'attachment; filename="foo.html"'],
|
||||
['attachment', 'foo bar.html', '', 'attachment; filename="foo bar.html"'],
|
||||
['attachment', 'foo "bar".html', '', 'attachment; filename="foo \\"bar\\".html"'],
|
||||
['attachment', 'foo%20bar.html', 'foo bar.html', 'attachment; filename="foo bar.html"; filename*=utf-8\'\'foo%2520bar.html'],
|
||||
['attachment', 'föö.html', 'foo.html', 'attachment; filename="foo.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideMakeDispositionFail
|
||||
*/
|
||||
public function testMakeDispositionFail($disposition, $filename)
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$headers = new ResponseHeaderBag();
|
||||
|
||||
$headers->makeDisposition($disposition, $filename);
|
||||
}
|
||||
|
||||
public function provideMakeDispositionFail()
|
||||
{
|
||||
return [
|
||||
['attachment', 'foo%20bar.html'],
|
||||
['attachment', 'foo/bar.html'],
|
||||
['attachment', '/foo.html'],
|
||||
['attachment', 'foo\bar.html'],
|
||||
['attachment', '\foo.html'],
|
||||
['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(['Date' => $someDate]);
|
||||
|
||||
$this->assertEquals($someDate, $bag->get('Date'));
|
||||
}
|
||||
|
||||
public function testDateHeaderWillBeRecreatedWhenRemoved()
|
||||
{
|
||||
$someDate = 'Thu, 23 Mar 2017 09:15:12 GMT';
|
||||
$bag = new ResponseHeaderBag(['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([]);
|
||||
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
}
|
||||
|
||||
private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
|
||||
{
|
||||
$this->assertMatchesRegularExpression('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
|
||||
}
|
||||
}
|
||||
1012
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ResponseTest.php
vendored
Normal file
1012
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ResponseTest.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
89
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ResponseTestCase.php
vendored
Normal file
89
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ResponseTestCase.php
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
abstract class ResponseTestCase extends TestCase
|
||||
{
|
||||
public function testNoCacheControlHeaderOnAttachmentUsingHTTPSAndMSIE()
|
||||
{
|
||||
// Check for HTTPS and IE 8
|
||||
$request = new Request();
|
||||
$request->server->set('HTTPS', true);
|
||||
$request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
|
||||
|
||||
$response = $this->provideResponse();
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertFalse($response->headers->has('Cache-Control'));
|
||||
|
||||
// Check for IE 10 and HTTPS
|
||||
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)');
|
||||
|
||||
$response = $this->provideResponse();
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertTrue($response->headers->has('Cache-Control'));
|
||||
|
||||
// Check for IE 9 and HTTPS
|
||||
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)');
|
||||
|
||||
$response = $this->provideResponse();
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertTrue($response->headers->has('Cache-Control'));
|
||||
|
||||
// Check for IE 9 and HTTP
|
||||
$request->server->set('HTTPS', false);
|
||||
|
||||
$response = $this->provideResponse();
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertTrue($response->headers->has('Cache-Control'));
|
||||
|
||||
// Check for IE 8 and HTTP
|
||||
$request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
|
||||
|
||||
$response = $this->provideResponse();
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertTrue($response->headers->has('Cache-Control'));
|
||||
|
||||
// Check for non-IE and HTTPS
|
||||
$request->server->set('HTTPS', true);
|
||||
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17');
|
||||
|
||||
$response = $this->provideResponse();
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertTrue($response->headers->has('Cache-Control'));
|
||||
|
||||
// Check for non-IE and HTTP
|
||||
$request->server->set('HTTPS', false);
|
||||
|
||||
$response = $this->provideResponse();
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertTrue($response->headers->has('Cache-Control'));
|
||||
}
|
||||
|
||||
abstract protected function provideResponse();
|
||||
}
|
||||
170
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ServerBagTest.php
vendored
Normal file
170
modules/ps_metrics/vendor/symfony/http-foundation/Tests/ServerBagTest.php
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\ServerBag;
|
||||
|
||||
/**
|
||||
* ServerBagTest.
|
||||
*
|
||||
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||||
*/
|
||||
class ServerBagTest extends TestCase
|
||||
{
|
||||
public function testShouldExtractHeadersFromServerArray()
|
||||
{
|
||||
$server = [
|
||||
'SOME_SERVER_VARIABLE' => 'value',
|
||||
'SOME_SERVER_VARIABLE2' => 'value',
|
||||
'ROOT' => 'value',
|
||||
'HTTP_CONTENT_TYPE' => 'text/html',
|
||||
'HTTP_CONTENT_LENGTH' => '0',
|
||||
'HTTP_ETAG' => 'asdf',
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => 'bar',
|
||||
];
|
||||
|
||||
$bag = new ServerBag($server);
|
||||
|
||||
$this->assertEquals([
|
||||
'CONTENT_TYPE' => 'text/html',
|
||||
'CONTENT_LENGTH' => '0',
|
||||
'ETAG' => 'asdf',
|
||||
'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => 'bar',
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpPasswordIsOptional()
|
||||
{
|
||||
$bag = new ServerBag(['PHP_AUTH_USER' => 'foo']);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => '',
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpBasicAuthWithPhpCgi()
|
||||
{
|
||||
$bag = new ServerBag(['HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:bar')]);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => 'bar',
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpBasicAuthWithPhpCgiBogus()
|
||||
{
|
||||
$bag = new ServerBag(['HTTP_AUTHORIZATION' => 'Basic_'.base64_encode('foo:bar')]);
|
||||
|
||||
// Username and passwords should not be set as the header is bogus
|
||||
$headers = $bag->getHeaders();
|
||||
$this->assertArrayNotHasKey('PHP_AUTH_USER', $headers);
|
||||
$this->assertArrayNotHasKey('PHP_AUTH_PW', $headers);
|
||||
}
|
||||
|
||||
public function testHttpBasicAuthWithPhpCgiRedirect()
|
||||
{
|
||||
$bag = new ServerBag(['REDIRECT_HTTP_AUTHORIZATION' => 'Basic '.base64_encode('username:pass:word')]);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => 'Basic '.base64_encode('username:pass:word'),
|
||||
'PHP_AUTH_USER' => 'username',
|
||||
'PHP_AUTH_PW' => 'pass:word',
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpBasicAuthWithPhpCgiEmptyPassword()
|
||||
{
|
||||
$bag = new ServerBag(['HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:')]);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => '',
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpDigestAuthWithPhpCgi()
|
||||
{
|
||||
$digest = 'Digest username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"';
|
||||
$bag = new ServerBag(['HTTP_AUTHORIZATION' => $digest]);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => $digest,
|
||||
'PHP_AUTH_DIGEST' => $digest,
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpDigestAuthWithPhpCgiBogus()
|
||||
{
|
||||
$digest = 'Digest_username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"';
|
||||
$bag = new ServerBag(['HTTP_AUTHORIZATION' => $digest]);
|
||||
|
||||
// Username and passwords should not be set as the header is bogus
|
||||
$headers = $bag->getHeaders();
|
||||
$this->assertArrayNotHasKey('PHP_AUTH_USER', $headers);
|
||||
$this->assertArrayNotHasKey('PHP_AUTH_PW', $headers);
|
||||
}
|
||||
|
||||
public function testHttpDigestAuthWithPhpCgiRedirect()
|
||||
{
|
||||
$digest = 'Digest username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"';
|
||||
$bag = new ServerBag(['REDIRECT_HTTP_AUTHORIZATION' => $digest]);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => $digest,
|
||||
'PHP_AUTH_DIGEST' => $digest,
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testOAuthBearerAuth()
|
||||
{
|
||||
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
|
||||
$bag = new ServerBag(['HTTP_AUTHORIZATION' => $headerContent]);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => $headerContent,
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testOAuthBearerAuthWithRedirect()
|
||||
{
|
||||
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
|
||||
$bag = new ServerBag(['REDIRECT_HTTP_AUTHORIZATION' => $headerContent]);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => $headerContent,
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/symfony/symfony/issues/17345
|
||||
*/
|
||||
public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet()
|
||||
{
|
||||
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
|
||||
$bag = new ServerBag(['PHP_AUTH_USER' => 'foo', 'HTTP_AUTHORIZATION' => $headerContent]);
|
||||
|
||||
$this->assertEquals([
|
||||
'AUTHORIZATION' => $headerContent,
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => '',
|
||||
], $bag->getHeaders());
|
||||
}
|
||||
}
|
||||
186
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Attribute/AttributeBagTest.php
vendored
Normal file
186
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Attribute/AttributeBagTest.php
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Attribute;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
|
||||
/**
|
||||
* Tests AttributeBag.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class AttributeBagTest extends TestCase
|
||||
{
|
||||
private $array = [];
|
||||
|
||||
/**
|
||||
* @var AttributeBag
|
||||
*/
|
||||
private $bag;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->array = [
|
||||
'hello' => 'world',
|
||||
'always' => 'be happy',
|
||||
'user.login' => 'drak',
|
||||
'csrf.token' => [
|
||||
'a' => '1234',
|
||||
'b' => '4321',
|
||||
],
|
||||
'category' => [
|
||||
'fishing' => [
|
||||
'first' => 'cod',
|
||||
'second' => 'sole',
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->bag = new AttributeBag('_sf2');
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->bag = null;
|
||||
$this->array = [];
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$bag = new AttributeBag();
|
||||
$bag->initialize($this->array);
|
||||
$this->assertEquals($this->array, $bag->all());
|
||||
$array = ['should' => 'change'];
|
||||
$bag->initialize($array);
|
||||
$this->assertEquals($array, $bag->all());
|
||||
}
|
||||
|
||||
public function testGetStorageKey()
|
||||
{
|
||||
$this->assertEquals('_sf2', $this->bag->getStorageKey());
|
||||
$attributeBag = new AttributeBag('test');
|
||||
$this->assertEquals('test', $attributeBag->getStorageKey());
|
||||
}
|
||||
|
||||
public function testGetSetName()
|
||||
{
|
||||
$this->assertEquals('attributes', $this->bag->getName());
|
||||
$this->bag->setName('foo');
|
||||
$this->assertEquals('foo', $this->bag->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testHas($key, $value, $exists)
|
||||
{
|
||||
$this->assertEquals($exists, $this->bag->has($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testGet($key, $value, $expected)
|
||||
{
|
||||
$this->assertEquals($value, $this->bag->get($key));
|
||||
}
|
||||
|
||||
public function testGetDefaults()
|
||||
{
|
||||
$this->assertNull($this->bag->get('user2.login'));
|
||||
$this->assertEquals('default', $this->bag->get('user2.login', 'default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testSet($key, $value, $expected)
|
||||
{
|
||||
$this->bag->set($key, $value);
|
||||
$this->assertEquals($value, $this->bag->get($key));
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$this->assertEquals($this->array, $this->bag->all());
|
||||
|
||||
$this->bag->set('hello', 'fabien');
|
||||
$array = $this->array;
|
||||
$array['hello'] = 'fabien';
|
||||
$this->assertEquals($array, $this->bag->all());
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = 'jack';
|
||||
$array['foo.bar'] = 'beep';
|
||||
$this->bag->replace($array);
|
||||
$this->assertEquals($array, $this->bag->all());
|
||||
$this->assertNull($this->bag->get('hello'));
|
||||
$this->assertNull($this->bag->get('always'));
|
||||
$this->assertNull($this->bag->get('user.login'));
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$this->assertEquals('world', $this->bag->get('hello'));
|
||||
$this->bag->remove('hello');
|
||||
$this->assertNull($this->bag->get('hello'));
|
||||
|
||||
$this->assertEquals('be happy', $this->bag->get('always'));
|
||||
$this->bag->remove('always');
|
||||
$this->assertNull($this->bag->get('always'));
|
||||
|
||||
$this->assertEquals('drak', $this->bag->get('user.login'));
|
||||
$this->bag->remove('user.login');
|
||||
$this->assertNull($this->bag->get('user.login'));
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->bag->clear();
|
||||
$this->assertEquals([], $this->bag->all());
|
||||
}
|
||||
|
||||
public function attributesProvider()
|
||||
{
|
||||
return [
|
||||
['hello', 'world', true],
|
||||
['always', 'be happy', true],
|
||||
['user.login', 'drak', true],
|
||||
['csrf.token', ['a' => '1234', 'b' => '4321'], true],
|
||||
['category', ['fishing' => ['first' => 'cod', 'second' => 'sole']], true],
|
||||
['user2.login', null, false],
|
||||
['never', null, false],
|
||||
['bye', null, false],
|
||||
['bye/for/now', null, false],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($this->bag as $key => $val) {
|
||||
$this->assertEquals($this->array[$key], $val);
|
||||
++$i;
|
||||
}
|
||||
|
||||
$this->assertEquals(\count($this->array), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$this->assertCount(\count($this->array), $this->bag);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Attribute;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
|
||||
|
||||
/**
|
||||
* Tests NamespacedAttributeBag.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NamespacedAttributeBagTest extends TestCase
|
||||
{
|
||||
private $array = [];
|
||||
|
||||
/**
|
||||
* @var NamespacedAttributeBag
|
||||
*/
|
||||
private $bag;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->array = [
|
||||
'hello' => 'world',
|
||||
'always' => 'be happy',
|
||||
'user.login' => 'drak',
|
||||
'csrf.token' => [
|
||||
'a' => '1234',
|
||||
'b' => '4321',
|
||||
],
|
||||
'category' => [
|
||||
'fishing' => [
|
||||
'first' => 'cod',
|
||||
'second' => 'sole',
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->bag = new NamespacedAttributeBag('_sf2', '/');
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->bag = null;
|
||||
$this->array = [];
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$bag = new NamespacedAttributeBag();
|
||||
$bag->initialize($this->array);
|
||||
$this->assertEquals($this->array, $this->bag->all());
|
||||
$array = ['should' => 'not stick'];
|
||||
$bag->initialize($array);
|
||||
|
||||
// should have remained the same
|
||||
$this->assertEquals($this->array, $this->bag->all());
|
||||
}
|
||||
|
||||
public function testGetStorageKey()
|
||||
{
|
||||
$this->assertEquals('_sf2', $this->bag->getStorageKey());
|
||||
$attributeBag = new NamespacedAttributeBag('test');
|
||||
$this->assertEquals('test', $attributeBag->getStorageKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testHas($key, $value, $exists)
|
||||
{
|
||||
$this->assertEquals($exists, $this->bag->has($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testHasNoSideEffect($key, $value, $expected)
|
||||
{
|
||||
$expected = json_encode($this->bag->all());
|
||||
$this->bag->has($key);
|
||||
|
||||
$this->assertEquals($expected, json_encode($this->bag->all()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testGet($key, $value, $expected)
|
||||
{
|
||||
$this->assertEquals($value, $this->bag->get($key));
|
||||
}
|
||||
|
||||
public function testGetDefaults()
|
||||
{
|
||||
$this->assertNull($this->bag->get('user2.login'));
|
||||
$this->assertEquals('default', $this->bag->get('user2.login', 'default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testGetNoSideEffect($key, $value, $expected)
|
||||
{
|
||||
$expected = json_encode($this->bag->all());
|
||||
$this->bag->get($key);
|
||||
|
||||
$this->assertEquals($expected, json_encode($this->bag->all()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider attributesProvider
|
||||
*/
|
||||
public function testSet($key, $value, $expected)
|
||||
{
|
||||
$this->bag->set($key, $value);
|
||||
$this->assertEquals($value, $this->bag->get($key));
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$this->assertEquals($this->array, $this->bag->all());
|
||||
|
||||
$this->bag->set('hello', 'fabien');
|
||||
$array = $this->array;
|
||||
$array['hello'] = 'fabien';
|
||||
$this->assertEquals($array, $this->bag->all());
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$array = [];
|
||||
$array['name'] = 'jack';
|
||||
$array['foo.bar'] = 'beep';
|
||||
$this->bag->replace($array);
|
||||
$this->assertEquals($array, $this->bag->all());
|
||||
$this->assertNull($this->bag->get('hello'));
|
||||
$this->assertNull($this->bag->get('always'));
|
||||
$this->assertNull($this->bag->get('user.login'));
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$this->assertEquals('world', $this->bag->get('hello'));
|
||||
$this->bag->remove('hello');
|
||||
$this->assertNull($this->bag->get('hello'));
|
||||
|
||||
$this->assertEquals('be happy', $this->bag->get('always'));
|
||||
$this->bag->remove('always');
|
||||
$this->assertNull($this->bag->get('always'));
|
||||
|
||||
$this->assertEquals('drak', $this->bag->get('user.login'));
|
||||
$this->bag->remove('user.login');
|
||||
$this->assertNull($this->bag->get('user.login'));
|
||||
}
|
||||
|
||||
public function testRemoveExistingNamespacedAttribute()
|
||||
{
|
||||
$this->assertSame('cod', $this->bag->remove('category/fishing/first'));
|
||||
}
|
||||
|
||||
public function testRemoveNonexistingNamespacedAttribute()
|
||||
{
|
||||
$this->assertNull($this->bag->remove('foo/bar/baz'));
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->bag->clear();
|
||||
$this->assertEquals([], $this->bag->all());
|
||||
}
|
||||
|
||||
public function attributesProvider()
|
||||
{
|
||||
return [
|
||||
['hello', 'world', true],
|
||||
['always', 'be happy', true],
|
||||
['user.login', 'drak', true],
|
||||
['csrf.token', ['a' => '1234', 'b' => '4321'], true],
|
||||
['csrf.token/a', '1234', true],
|
||||
['csrf.token/b', '4321', true],
|
||||
['category', ['fishing' => ['first' => 'cod', 'second' => 'sole']], true],
|
||||
['category/fishing', ['first' => 'cod', 'second' => 'sole'], true],
|
||||
['category/fishing/missing/first', null, false],
|
||||
['category/fishing/first', 'cod', true],
|
||||
['category/fishing/second', 'sole', true],
|
||||
['category/fishing/missing/second', null, false],
|
||||
['user2.login', null, false],
|
||||
['never', null, false],
|
||||
['bye', null, false],
|
||||
['bye/for/now', null, false],
|
||||
];
|
||||
}
|
||||
}
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Attribute/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Attribute/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
161
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Flash/AutoExpireFlashBagTest.php
vendored
Normal file
161
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Flash/AutoExpireFlashBagTest.php
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Flash;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag as FlashBag;
|
||||
|
||||
/**
|
||||
* AutoExpireFlashBagTest.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class AutoExpireFlashBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag
|
||||
*/
|
||||
private $bag;
|
||||
|
||||
protected $array = [];
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->bag = new FlashBag();
|
||||
$this->array = ['new' => ['notice' => ['A previous flash message']]];
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->bag = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$bag = new FlashBag();
|
||||
$array = ['new' => ['notice' => ['A previous flash message']]];
|
||||
$bag->initialize($array);
|
||||
$this->assertEquals(['A previous flash message'], $bag->peek('notice'));
|
||||
$array = ['new' => [
|
||||
'notice' => ['Something else'],
|
||||
'error' => ['a'],
|
||||
]];
|
||||
$bag->initialize($array);
|
||||
$this->assertEquals(['Something else'], $bag->peek('notice'));
|
||||
$this->assertEquals(['a'], $bag->peek('error'));
|
||||
}
|
||||
|
||||
public function testGetStorageKey()
|
||||
{
|
||||
$this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
|
||||
$attributeBag = new FlashBag('test');
|
||||
$this->assertEquals('test', $attributeBag->getStorageKey());
|
||||
}
|
||||
|
||||
public function testGetSetName()
|
||||
{
|
||||
$this->assertEquals('flashes', $this->bag->getName());
|
||||
$this->bag->setName('foo');
|
||||
$this->assertEquals('foo', $this->bag->getName());
|
||||
}
|
||||
|
||||
public function testPeek()
|
||||
{
|
||||
$this->assertEquals([], $this->bag->peek('non_existing'));
|
||||
$this->assertEquals(['default'], $this->bag->peek('non_existing', ['default']));
|
||||
$this->assertEquals(['A previous flash message'], $this->bag->peek('notice'));
|
||||
$this->assertEquals(['A previous flash message'], $this->bag->peek('notice'));
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->assertEquals(['A previous flash message'], $this->bag->peek('notice'));
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$this->assertFalse($this->bag->has('nothing'));
|
||||
$this->assertTrue($this->bag->has('notice'));
|
||||
}
|
||||
|
||||
public function testKeys()
|
||||
{
|
||||
$this->assertEquals(['notice'], $this->bag->keys());
|
||||
}
|
||||
|
||||
public function testPeekAll()
|
||||
{
|
||||
$array = [
|
||||
'new' => [
|
||||
'notice' => 'Foo',
|
||||
'error' => 'Bar',
|
||||
],
|
||||
];
|
||||
|
||||
$this->bag->initialize($array);
|
||||
$this->assertEquals([
|
||||
'notice' => 'Foo',
|
||||
'error' => 'Bar',
|
||||
], $this->bag->peekAll()
|
||||
);
|
||||
|
||||
$this->assertEquals([
|
||||
'notice' => 'Foo',
|
||||
'error' => 'Bar',
|
||||
], $this->bag->peekAll()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->assertEquals([], $this->bag->get('non_existing'));
|
||||
$this->assertEquals(['default'], $this->bag->get('non_existing', ['default']));
|
||||
$this->assertEquals(['A previous flash message'], $this->bag->get('notice'));
|
||||
$this->assertEquals([], $this->bag->get('notice'));
|
||||
}
|
||||
|
||||
public function testSetAll()
|
||||
{
|
||||
$this->bag->setAll(['a' => 'first', 'b' => 'second']);
|
||||
$this->assertFalse($this->bag->has('a'));
|
||||
$this->assertFalse($this->bag->has('b'));
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->bag->set('error', 'Bar');
|
||||
$this->assertEquals([
|
||||
'notice' => ['A previous flash message'],
|
||||
], $this->bag->all()
|
||||
);
|
||||
|
||||
$this->assertEquals([], $this->bag->all());
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->assertEquals(['notice' => ['A previous flash message']], $this->bag->clear());
|
||||
}
|
||||
|
||||
public function testDoNotRemoveTheNewFlashesWhenDisplayingTheExistingOnes()
|
||||
{
|
||||
$this->bag->add('success', 'Something');
|
||||
$this->bag->all();
|
||||
|
||||
$this->assertEquals(['new' => ['success' => ['Something']], 'display' => []], $this->array);
|
||||
}
|
||||
}
|
||||
157
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Flash/FlashBagTest.php
vendored
Normal file
157
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Flash/FlashBagTest.php
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Flash;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
|
||||
/**
|
||||
* FlashBagTest.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class FlashBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface
|
||||
*/
|
||||
private $bag;
|
||||
|
||||
protected $array = [];
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->bag = new FlashBag();
|
||||
$this->array = ['notice' => ['A previous flash message']];
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->bag = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$bag = new FlashBag();
|
||||
$bag->initialize($this->array);
|
||||
$this->assertEquals($this->array, $bag->peekAll());
|
||||
$array = ['should' => ['change']];
|
||||
$bag->initialize($array);
|
||||
$this->assertEquals($array, $bag->peekAll());
|
||||
}
|
||||
|
||||
public function testGetStorageKey()
|
||||
{
|
||||
$this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
|
||||
$attributeBag = new FlashBag('test');
|
||||
$this->assertEquals('test', $attributeBag->getStorageKey());
|
||||
}
|
||||
|
||||
public function testGetSetName()
|
||||
{
|
||||
$this->assertEquals('flashes', $this->bag->getName());
|
||||
$this->bag->setName('foo');
|
||||
$this->assertEquals('foo', $this->bag->getName());
|
||||
}
|
||||
|
||||
public function testPeek()
|
||||
{
|
||||
$this->assertEquals([], $this->bag->peek('non_existing'));
|
||||
$this->assertEquals(['default'], $this->bag->peek('not_existing', ['default']));
|
||||
$this->assertEquals(['A previous flash message'], $this->bag->peek('notice'));
|
||||
$this->assertEquals(['A previous flash message'], $this->bag->peek('notice'));
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$tab = ['bar' => 'baz'];
|
||||
$this->bag->add('string_message', 'lorem');
|
||||
$this->bag->add('object_message', new \stdClass());
|
||||
$this->bag->add('array_message', $tab);
|
||||
|
||||
$this->assertEquals(['lorem'], $this->bag->get('string_message'));
|
||||
$this->assertEquals([new \stdClass()], $this->bag->get('object_message'));
|
||||
$this->assertEquals([$tab], $this->bag->get('array_message'));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->assertEquals([], $this->bag->get('non_existing'));
|
||||
$this->assertEquals(['default'], $this->bag->get('not_existing', ['default']));
|
||||
$this->assertEquals(['A previous flash message'], $this->bag->get('notice'));
|
||||
$this->assertEquals([], $this->bag->get('notice'));
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->bag->set('error', 'Bar');
|
||||
$this->assertEquals([
|
||||
'notice' => ['Foo'],
|
||||
'error' => ['Bar'], ], $this->bag->all()
|
||||
);
|
||||
|
||||
$this->assertEquals([], $this->bag->all());
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->bag->set('notice', 'Bar');
|
||||
$this->assertEquals(['Bar'], $this->bag->peek('notice'));
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$this->assertFalse($this->bag->has('nothing'));
|
||||
$this->assertTrue($this->bag->has('notice'));
|
||||
}
|
||||
|
||||
public function testKeys()
|
||||
{
|
||||
$this->assertEquals(['notice'], $this->bag->keys());
|
||||
}
|
||||
|
||||
public function testSetAll()
|
||||
{
|
||||
$this->bag->add('one_flash', 'Foo');
|
||||
$this->bag->add('another_flash', 'Bar');
|
||||
$this->assertTrue($this->bag->has('one_flash'));
|
||||
$this->assertTrue($this->bag->has('another_flash'));
|
||||
$this->bag->setAll(['unique_flash' => 'FooBar']);
|
||||
$this->assertFalse($this->bag->has('one_flash'));
|
||||
$this->assertFalse($this->bag->has('another_flash'));
|
||||
$this->assertSame(['unique_flash' => 'FooBar'], $this->bag->all());
|
||||
$this->assertSame([], $this->bag->all());
|
||||
}
|
||||
|
||||
public function testPeekAll()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->bag->set('error', 'Bar');
|
||||
$this->assertEquals([
|
||||
'notice' => ['Foo'],
|
||||
'error' => ['Bar'],
|
||||
], $this->bag->peekAll()
|
||||
);
|
||||
$this->assertTrue($this->bag->has('notice'));
|
||||
$this->assertTrue($this->bag->has('error'));
|
||||
$this->assertEquals([
|
||||
'notice' => ['Foo'],
|
||||
'error' => ['Bar'],
|
||||
], $this->bag->peekAll()
|
||||
);
|
||||
}
|
||||
}
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Flash/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Flash/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
288
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/SessionTest.php
vendored
Normal file
288
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/SessionTest.php
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionBagProxy;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
/**
|
||||
* SessionTest.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Robert Schönthal <seroscho@googlemail.com>
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class SessionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->storage = new MockArraySessionStorage();
|
||||
$this->session = new Session($this->storage, new AttributeBag(), new FlashBag());
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->storage = null;
|
||||
$this->session = null;
|
||||
}
|
||||
|
||||
public function testStart()
|
||||
{
|
||||
$this->assertEquals('', $this->session->getId());
|
||||
$this->assertTrue($this->session->start());
|
||||
$this->assertNotEquals('', $this->session->getId());
|
||||
}
|
||||
|
||||
public function testIsStarted()
|
||||
{
|
||||
$this->assertFalse($this->session->isStarted());
|
||||
$this->session->start();
|
||||
$this->assertTrue($this->session->isStarted());
|
||||
}
|
||||
|
||||
public function testSetId()
|
||||
{
|
||||
$this->assertEquals('', $this->session->getId());
|
||||
$this->session->setId('0123456789abcdef');
|
||||
$this->session->start();
|
||||
$this->assertEquals('0123456789abcdef', $this->session->getId());
|
||||
}
|
||||
|
||||
public function testSetIdAfterStart()
|
||||
{
|
||||
$this->session->start();
|
||||
$id = $this->session->getId();
|
||||
|
||||
$e = null;
|
||||
try {
|
||||
$this->session->setId($id);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
$this->assertNull($e);
|
||||
|
||||
try {
|
||||
$this->session->setId('different');
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
$this->assertInstanceOf('\LogicException', $e);
|
||||
}
|
||||
|
||||
public function testSetName()
|
||||
{
|
||||
$this->assertEquals('MOCKSESSID', $this->session->getName());
|
||||
$this->session->setName('session.test.com');
|
||||
$this->session->start();
|
||||
$this->assertEquals('session.test.com', $this->session->getName());
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
// tests defaults
|
||||
$this->assertNull($this->session->get('foo'));
|
||||
$this->assertEquals(1, $this->session->get('foo', 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider setProvider
|
||||
*/
|
||||
public function testSet($key, $value)
|
||||
{
|
||||
$this->session->set($key, $value);
|
||||
$this->assertEquals($value, $this->session->get($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider setProvider
|
||||
*/
|
||||
public function testHas($key, $value)
|
||||
{
|
||||
$this->session->set($key, $value);
|
||||
$this->assertTrue($this->session->has($key));
|
||||
$this->assertFalse($this->session->has($key.'non_value'));
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$this->session->replace(['happiness' => 'be good', 'symfony' => 'awesome']);
|
||||
$this->assertEquals(['happiness' => 'be good', 'symfony' => 'awesome'], $this->session->all());
|
||||
$this->session->replace([]);
|
||||
$this->assertEquals([], $this->session->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider setProvider
|
||||
*/
|
||||
public function testAll($key, $value, $result)
|
||||
{
|
||||
$this->session->set($key, $value);
|
||||
$this->assertEquals($result, $this->session->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider setProvider
|
||||
*/
|
||||
public function testClear($key, $value)
|
||||
{
|
||||
$this->session->set('hi', 'fabien');
|
||||
$this->session->set($key, $value);
|
||||
$this->session->clear();
|
||||
$this->assertEquals([], $this->session->all());
|
||||
}
|
||||
|
||||
public function setProvider()
|
||||
{
|
||||
return [
|
||||
['foo', 'bar', ['foo' => 'bar']],
|
||||
['foo.bar', 'too much beer', ['foo.bar' => 'too much beer']],
|
||||
['great', 'symfony is great', ['great' => 'symfony is great']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider setProvider
|
||||
*/
|
||||
public function testRemove($key, $value)
|
||||
{
|
||||
$this->session->set('hi.world', 'have a nice day');
|
||||
$this->session->set($key, $value);
|
||||
$this->session->remove($key);
|
||||
$this->assertEquals(['hi.world' => 'have a nice day'], $this->session->all());
|
||||
}
|
||||
|
||||
public function testInvalidate()
|
||||
{
|
||||
$this->session->set('invalidate', 123);
|
||||
$this->session->invalidate();
|
||||
$this->assertEquals([], $this->session->all());
|
||||
}
|
||||
|
||||
public function testMigrate()
|
||||
{
|
||||
$this->session->set('migrate', 321);
|
||||
$this->session->migrate();
|
||||
$this->assertEquals(321, $this->session->get('migrate'));
|
||||
}
|
||||
|
||||
public function testMigrateDestroy()
|
||||
{
|
||||
$this->session->set('migrate', 333);
|
||||
$this->session->migrate(true);
|
||||
$this->assertEquals(333, $this->session->get('migrate'));
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$this->session->start();
|
||||
$this->session->save();
|
||||
|
||||
$this->assertFalse($this->session->isStarted());
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
$this->assertEquals('', $this->session->getId());
|
||||
$this->session->start();
|
||||
$this->assertNotEquals('', $this->session->getId());
|
||||
}
|
||||
|
||||
public function testGetFlashBag()
|
||||
{
|
||||
$this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface', $this->session->getFlashBag());
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$attributes = ['hello' => 'world', 'symfony' => 'rocks'];
|
||||
foreach ($attributes as $key => $val) {
|
||||
$this->session->set($key, $val);
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach ($this->session as $key => $val) {
|
||||
$this->assertEquals($attributes[$key], $val);
|
||||
++$i;
|
||||
}
|
||||
|
||||
$this->assertEquals(\count($attributes), $i);
|
||||
}
|
||||
|
||||
public function testGetCount()
|
||||
{
|
||||
$this->session->set('hello', 'world');
|
||||
$this->session->set('symfony', 'rocks');
|
||||
|
||||
$this->assertCount(2, $this->session);
|
||||
}
|
||||
|
||||
public function testGetMeta()
|
||||
{
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\MetadataBag', $this->session->getMetadataBag());
|
||||
}
|
||||
|
||||
public function testIsEmpty()
|
||||
{
|
||||
$this->assertTrue($this->session->isEmpty());
|
||||
|
||||
$this->session->set('hello', 'world');
|
||||
$this->assertFalse($this->session->isEmpty());
|
||||
|
||||
$this->session->remove('hello');
|
||||
$this->assertTrue($this->session->isEmpty());
|
||||
|
||||
$flash = $this->session->getFlashBag();
|
||||
$flash->set('hello', 'world');
|
||||
$this->assertFalse($this->session->isEmpty());
|
||||
|
||||
$flash->get('hello');
|
||||
$this->assertTrue($this->session->isEmpty());
|
||||
}
|
||||
|
||||
public function testGetBagWithBagImplementingGetBag()
|
||||
{
|
||||
$bag = new AttributeBag();
|
||||
$bag->setName('foo');
|
||||
|
||||
$storage = new MockArraySessionStorage();
|
||||
$storage->registerBag($bag);
|
||||
|
||||
$this->assertSame($bag, (new Session($storage))->getBag('foo'));
|
||||
}
|
||||
|
||||
public function testGetBagWithBagNotImplementingGetBag()
|
||||
{
|
||||
$data = [];
|
||||
|
||||
$bag = new AttributeBag();
|
||||
$bag->setName('foo');
|
||||
|
||||
$storage = new MockArraySessionStorage();
|
||||
$storage->registerBag(new SessionBagProxy($bag, $data, $usageIndex));
|
||||
|
||||
$this->assertSame($bag, (new Session($storage))->getBag('foo'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
class AbstractSessionHandlerTest extends TestCase
|
||||
{
|
||||
private static $server;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$spec = [
|
||||
1 => ['file', '/dev/null', 'w'],
|
||||
2 => ['file', '/dev/null', 'w'],
|
||||
];
|
||||
if (!self::$server = @proc_open('exec php -S localhost:8053', $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 provideSession
|
||||
*/
|
||||
public function testSession($fixture)
|
||||
{
|
||||
$context = ['http' => ['header' => "Cookie: sid=123abc\r\n"]];
|
||||
$context = stream_context_create($context);
|
||||
$result = file_get_contents(sprintf('http://localhost:8053/%s.php', $fixture), false, $context);
|
||||
|
||||
$this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result);
|
||||
}
|
||||
|
||||
public function provideSession()
|
||||
{
|
||||
foreach (glob(__DIR__.'/Fixtures/*.php') as $file) {
|
||||
yield [pathinfo($file, \PATHINFO_FILENAME)];
|
||||
}
|
||||
}
|
||||
}
|
||||
151
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/common.inc
vendored
Normal file
151
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/common.inc
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
|
||||
|
||||
$parent = __DIR__;
|
||||
while (!@file_exists($parent.'/vendor/autoload.php')) {
|
||||
if (!@file_exists($parent)) {
|
||||
// open_basedir restriction in effect
|
||||
break;
|
||||
}
|
||||
if ($parent === dirname($parent)) {
|
||||
echo "vendor/autoload.php not found\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$parent = dirname($parent);
|
||||
}
|
||||
|
||||
require $parent.'/vendor/autoload.php';
|
||||
|
||||
error_reporting(-1);
|
||||
ini_set('html_errors', 0);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('session.gc_probability', 0);
|
||||
ini_set('session.serialize_handler', 'php');
|
||||
ini_set('session.cookie_lifetime', 0);
|
||||
ini_set('session.cookie_domain', '');
|
||||
ini_set('session.cookie_secure', '');
|
||||
ini_set('session.cookie_httponly', '');
|
||||
ini_set('session.use_cookies', 1);
|
||||
ini_set('session.use_only_cookies', 1);
|
||||
ini_set('session.cache_expire', 180);
|
||||
ini_set('session.cookie_path', '/');
|
||||
ini_set('session.cookie_domain', '');
|
||||
ini_set('session.cookie_secure', 1);
|
||||
ini_set('session.cookie_httponly', 1);
|
||||
ini_set('session.use_strict_mode', 1);
|
||||
ini_set('session.lazy_write', 1);
|
||||
ini_set('session.name', 'sid');
|
||||
ini_set('session.save_path', __DIR__);
|
||||
ini_set('session.cache_limiter', '');
|
||||
|
||||
header_remove('X-Powered-By');
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
register_shutdown_function(function () {
|
||||
echo "\n";
|
||||
session_write_close();
|
||||
print_r(headers_list());
|
||||
echo "shutdown\n";
|
||||
});
|
||||
ob_start();
|
||||
|
||||
class TestSessionHandler extends AbstractSessionHandler
|
||||
{
|
||||
private $data;
|
||||
|
||||
public function __construct($data = '')
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function open($path, $name)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::open($path, $name);
|
||||
}
|
||||
|
||||
public function validateId($sessionId)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::validateId($sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($sessionId)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::read($sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateTimestamp($sessionId, $data)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($sessionId, $data)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::write($sessionId, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function destroy($sessionId)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return parent::destroy($sessionId);
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function gc($maxLifetime)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function doRead($sessionId)
|
||||
{
|
||||
echo __FUNCTION__.': ', $this->data, "\n";
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
protected function doWrite($sessionId, $data)
|
||||
{
|
||||
echo __FUNCTION__.': ', $data, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function doDestroy($sessionId)
|
||||
{
|
||||
echo __FUNCTION__, "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
|
||||
write
|
||||
destroy
|
||||
doDestroy
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
[2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
unset($_SESSION['abc']);
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -0,0 +1,14 @@
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
123
|
||||
updateTimestamp
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
echo $_SESSION['abc'];
|
||||
@@ -0,0 +1,25 @@
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
destroy
|
||||
doDestroy
|
||||
close
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
|
||||
write
|
||||
doWrite: abc|i:123;
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
session_regenerate_id(true);
|
||||
|
||||
ob_start(function ($buffer) { return str_replace(session_id(), 'random_session_id', $buffer); });
|
||||
@@ -0,0 +1,21 @@
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead:
|
||||
read
|
||||
Array
|
||||
(
|
||||
[0] => bar
|
||||
)
|
||||
$_SESSION is not empty
|
||||
write
|
||||
destroy
|
||||
close
|
||||
$_SESSION is empty
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=0, private, must-revalidate
|
||||
[2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
|
||||
$storage = new NativeSessionStorage();
|
||||
$storage->setSaveHandler(new TestSessionHandler());
|
||||
$flash = new FlashBag();
|
||||
$storage->registerBag($flash);
|
||||
$storage->start();
|
||||
|
||||
$flash->add('foo', 'bar');
|
||||
|
||||
print_r($flash->get('foo'));
|
||||
echo empty($_SESSION) ? '$_SESSION is empty' : '$_SESSION is not empty';
|
||||
echo "\n";
|
||||
|
||||
$storage->save();
|
||||
|
||||
echo empty($_SESSION) ? '$_SESSION is empty' : '$_SESSION is not empty';
|
||||
|
||||
ob_start(function ($buffer) { return str_replace(session_id(), 'random_session_id', $buffer); });
|
||||
@@ -0,0 +1,15 @@
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
|
||||
updateTimestamp
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
[2] => Set-Cookie: abc=def
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
setcookie('abc', 'def');
|
||||
@@ -0,0 +1,25 @@
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
updateTimestamp
|
||||
close
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
|
||||
write
|
||||
destroy
|
||||
doDestroy
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=10800, private, must-revalidate
|
||||
[2] => Set-Cookie: abc=def
|
||||
[3] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
setcookie('abc', 'def');
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
session_write_close();
|
||||
session_start();
|
||||
|
||||
$_SESSION['abc'] = 234;
|
||||
unset($_SESSION['abc']);
|
||||
@@ -0,0 +1,16 @@
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead:
|
||||
read
|
||||
|
||||
write
|
||||
doWrite: foo|s:3:"bar";
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=0, private, must-revalidate
|
||||
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly; SameSite=lax
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
|
||||
$storage = new NativeSessionStorage(['cookie_samesite' => 'lax']);
|
||||
$storage->setSaveHandler(new TestSessionHandler());
|
||||
$storage->start();
|
||||
|
||||
$_SESSION = ['foo' => 'bar'];
|
||||
|
||||
ob_start(function ($buffer) { return str_replace(session_id(), 'random_session_id', $buffer); });
|
||||
@@ -0,0 +1,23 @@
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead:
|
||||
read
|
||||
destroy
|
||||
close
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead:
|
||||
read
|
||||
|
||||
write
|
||||
doWrite: foo|s:3:"bar";
|
||||
close
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=0, private, must-revalidate
|
||||
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly; SameSite=lax
|
||||
)
|
||||
shutdown
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
|
||||
$storage = new NativeSessionStorage(['cookie_samesite' => 'lax']);
|
||||
$storage->setSaveHandler(new TestSessionHandler());
|
||||
$storage->start();
|
||||
|
||||
$_SESSION = ['foo' => 'bar'];
|
||||
|
||||
$storage->regenerate(true);
|
||||
|
||||
ob_start(function ($buffer) { return preg_replace('~_sf2_meta.*$~m', '', str_replace(session_id(), 'random_session_id', $buffer)); });
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler;
|
||||
|
||||
/**
|
||||
* @requires extension memcache
|
||||
* @group time-sensitive
|
||||
* @group legacy
|
||||
*/
|
||||
class MemcacheSessionHandlerTest extends TestCase
|
||||
{
|
||||
const PREFIX = 'prefix_';
|
||||
const TTL = 1000;
|
||||
|
||||
/**
|
||||
* @var MemcacheSessionHandler
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
protected $memcache;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcache class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
$this->memcache = $this->getMockBuilder('Memcache')->getMock();
|
||||
$this->storage = new MemcacheSessionHandler(
|
||||
$this->memcache,
|
||||
['prefix' => self::PREFIX, 'expiretime' => self::TTL]
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->memcache = null;
|
||||
$this->storage = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testOpenSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->open('', ''));
|
||||
}
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->close());
|
||||
}
|
||||
|
||||
public function testReadSession()
|
||||
{
|
||||
$this->memcache
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with(self::PREFIX.'id')
|
||||
;
|
||||
|
||||
$this->assertEquals('', $this->storage->read('id'));
|
||||
}
|
||||
|
||||
public function testWriteSession()
|
||||
{
|
||||
$this->memcache
|
||||
->expects($this->once())
|
||||
->method('set')
|
||||
->with(self::PREFIX.'id', 'data', 0, $this->equalTo(time() + self::TTL, 2))
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->write('id', 'data'));
|
||||
}
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->memcache
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with(self::PREFIX.'id')
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->destroy('id'));
|
||||
}
|
||||
|
||||
public function testGcSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->gc(123));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getOptionFixtures
|
||||
*/
|
||||
public function testSupportedOptions($options, $supported)
|
||||
{
|
||||
try {
|
||||
new MemcacheSessionHandler($this->memcache, $options);
|
||||
$this->assertTrue($supported);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertFalse($supported);
|
||||
}
|
||||
}
|
||||
|
||||
public function getOptionFixtures()
|
||||
{
|
||||
return [
|
||||
[['prefix' => 'session'], true],
|
||||
[['expiretime' => 100], true],
|
||||
[['prefix' => 'session', 'expiretime' => 200], true],
|
||||
[['expiretime' => 100, 'foo' => 'bar'], false],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$method = new \ReflectionMethod($this->storage, 'getMemcache');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\Memcache', $method->invoke($this->storage));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler;
|
||||
|
||||
/**
|
||||
* @requires extension memcached
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class MemcachedSessionHandlerTest extends TestCase
|
||||
{
|
||||
const PREFIX = 'prefix_';
|
||||
const TTL = 1000;
|
||||
|
||||
/**
|
||||
* @var MemcachedSessionHandler
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
protected $memcached;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('PHPUnit_MockObject cannot mock the Memcached class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
|
||||
if (version_compare(phpversion('memcached'), '2.2.0', '>=') && version_compare(phpversion('memcached'), '3.0.0b1', '<')) {
|
||||
$this->markTestSkipped('Tests can only be run with memcached extension 2.1.0 or lower, or 3.0.0b1 or higher');
|
||||
}
|
||||
|
||||
$this->memcached = $this->getMockBuilder('Memcached')->getMock();
|
||||
$this->storage = new MemcachedSessionHandler(
|
||||
$this->memcached,
|
||||
['prefix' => self::PREFIX, 'expiretime' => self::TTL]
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->memcached = null;
|
||||
$this->storage = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testOpenSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->open('', ''));
|
||||
}
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$this->memcached
|
||||
->expects($this->once())
|
||||
->method('quit')
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->close());
|
||||
}
|
||||
|
||||
public function testReadSession()
|
||||
{
|
||||
$this->memcached
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with(self::PREFIX.'id')
|
||||
;
|
||||
|
||||
$this->assertEquals('', $this->storage->read('id'));
|
||||
}
|
||||
|
||||
public function testWriteSession()
|
||||
{
|
||||
$this->memcached
|
||||
->expects($this->once())
|
||||
->method('set')
|
||||
->with(self::PREFIX.'id', 'data', $this->equalTo(time() + self::TTL, 2))
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->write('id', 'data'));
|
||||
}
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->memcached
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with(self::PREFIX.'id')
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->destroy('id'));
|
||||
}
|
||||
|
||||
public function testGcSession()
|
||||
{
|
||||
$this->assertTrue($this->storage->gc(123));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getOptionFixtures
|
||||
*/
|
||||
public function testSupportedOptions($options, $supported)
|
||||
{
|
||||
try {
|
||||
new MemcachedSessionHandler($this->memcached, $options);
|
||||
$this->assertTrue($supported);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertFalse($supported);
|
||||
}
|
||||
}
|
||||
|
||||
public function getOptionFixtures()
|
||||
{
|
||||
return [
|
||||
[['prefix' => 'session'], true],
|
||||
[['expiretime' => 100], true],
|
||||
[['prefix' => 'session', 'expiretime' => 200], true],
|
||||
[['expiretime' => 100, 'foo' => 'bar'], false],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$method = new \ReflectionMethod($this->storage, 'getMemcached');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\Memcached', $method->invoke($this->storage));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler;
|
||||
|
||||
/**
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
* @group time-sensitive
|
||||
* @group legacy
|
||||
*/
|
||||
class MongoDbSessionHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MockObject
|
||||
*/
|
||||
private $mongo;
|
||||
private $storage;
|
||||
public $options;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (\extension_loaded('mongodb')) {
|
||||
if (!class_exists('MongoDB\Client')) {
|
||||
$this->markTestSkipped('The mongodb/mongodb package is required.');
|
||||
}
|
||||
} elseif (!\extension_loaded('mongo')) {
|
||||
$this->markTestSkipped('The Mongo or MongoDB extension is required.');
|
||||
}
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$mongoClass = 'MongoDB\Client';
|
||||
} else {
|
||||
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? 'Mongo' : 'MongoClient';
|
||||
}
|
||||
|
||||
$this->mongo = $this->getMockBuilder($mongoClass)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->options = [
|
||||
'id_field' => '_id',
|
||||
'data_field' => 'data',
|
||||
'time_field' => 'time',
|
||||
'expiry_field' => 'expires_at',
|
||||
'database' => 'sf2-test',
|
||||
'collection' => 'session-test',
|
||||
];
|
||||
|
||||
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
|
||||
}
|
||||
|
||||
public function testConstructorShouldThrowExceptionForInvalidMongo()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new MongoDbSessionHandler(new \stdClass(), $this->options);
|
||||
}
|
||||
|
||||
public function testConstructorShouldThrowExceptionForMissingOptions()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new MongoDbSessionHandler($this->mongo, []);
|
||||
}
|
||||
|
||||
public function testOpenMethodAlwaysReturnTrue()
|
||||
{
|
||||
$this->assertTrue($this->storage->open('test', 'test'), 'The "open" method should always return true');
|
||||
}
|
||||
|
||||
public function testCloseMethodAlwaysReturnTrue()
|
||||
{
|
||||
$this->assertTrue($this->storage->close(), 'The "close" method should always return true');
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->willReturn($collection);
|
||||
|
||||
// defining the timeout before the actual method call
|
||||
// allows to test for "greater than" values in the $criteria
|
||||
$testTimeout = time() + 1;
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method('findOne')
|
||||
->willReturnCallback(function ($criteria) use ($testTimeout) {
|
||||
$this->assertArrayHasKey($this->options['id_field'], $criteria);
|
||||
$this->assertEquals('foo', $criteria[$this->options['id_field']]);
|
||||
|
||||
$this->assertArrayHasKey($this->options['expiry_field'], $criteria);
|
||||
$this->assertArrayHasKey('$gte', $criteria[$this->options['expiry_field']]);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$gte']);
|
||||
$this->assertGreaterThanOrEqual(round((string) $criteria[$this->options['expiry_field']]['$gte'] / 1000), $testTimeout);
|
||||
} else {
|
||||
$this->assertInstanceOf('MongoDate', $criteria[$this->options['expiry_field']]['$gte']);
|
||||
$this->assertGreaterThanOrEqual($criteria[$this->options['expiry_field']]['$gte']->sec, $testTimeout);
|
||||
}
|
||||
|
||||
$fields = [
|
||||
$this->options['id_field'] => 'foo',
|
||||
];
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$fields[$this->options['data_field']] = new \MongoDB\BSON\Binary('bar', \MongoDB\BSON\Binary::TYPE_OLD_BINARY);
|
||||
$fields[$this->options['id_field']] = new \MongoDB\BSON\UTCDateTime(time() * 1000);
|
||||
} else {
|
||||
$fields[$this->options['data_field']] = new \MongoBinData('bar', \MongoBinData::BYTE_ARRAY);
|
||||
$fields[$this->options['id_field']] = new \MongoDate();
|
||||
}
|
||||
|
||||
return $fields;
|
||||
});
|
||||
|
||||
$this->assertEquals('bar', $this->storage->read('foo'));
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->willReturn($collection);
|
||||
|
||||
$data = [];
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->willReturnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$this->assertEquals([$this->options['id_field'] => 'foo'], $criteria);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals(['upsert' => true], $options);
|
||||
} else {
|
||||
$this->assertEquals(['upsert' => true, 'multiple' => false], $options);
|
||||
}
|
||||
|
||||
$data = $updateData['$set'];
|
||||
});
|
||||
|
||||
$expectedExpiry = time() + (int) ini_get('session.gc_maxlifetime');
|
||||
$this->assertTrue($this->storage->write('foo', 'bar'));
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->getData());
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['expiry_field']]);
|
||||
$this->assertGreaterThanOrEqual($expectedExpiry, round((string) $data[$this->options['expiry_field']] / 1000));
|
||||
} else {
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
|
||||
$this->assertGreaterThanOrEqual($expectedExpiry, $data[$this->options['expiry_field']]->sec);
|
||||
}
|
||||
}
|
||||
|
||||
public function testWriteWhenUsingExpiresField()
|
||||
{
|
||||
$this->options = [
|
||||
'id_field' => '_id',
|
||||
'data_field' => 'data',
|
||||
'time_field' => 'time',
|
||||
'database' => 'sf2-test',
|
||||
'collection' => 'session-test',
|
||||
'expiry_field' => 'expiresAt',
|
||||
];
|
||||
|
||||
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
|
||||
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->willReturn($collection);
|
||||
|
||||
$data = [];
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->willReturnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$this->assertEquals([$this->options['id_field'] => 'foo'], $criteria);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals(['upsert' => true], $options);
|
||||
} else {
|
||||
$this->assertEquals(['upsert' => true, 'multiple' => false], $options);
|
||||
}
|
||||
|
||||
$data = $updateData['$set'];
|
||||
});
|
||||
|
||||
$this->assertTrue($this->storage->write('foo', 'bar'));
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->getData());
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['expiry_field']]);
|
||||
} else {
|
||||
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
|
||||
$this->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testReplaceSessionData()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->willReturn($collection);
|
||||
|
||||
$data = [];
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->exactly(2))
|
||||
->method($methodName)
|
||||
->willReturnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$data = $updateData;
|
||||
});
|
||||
|
||||
$this->storage->write('foo', 'bar');
|
||||
$this->storage->write('foo', 'foobar');
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals('foobar', $data['$set'][$this->options['data_field']]->getData());
|
||||
} else {
|
||||
$this->assertEquals('foobar', $data['$set'][$this->options['data_field']]->bin);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->willReturn($collection);
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'deleteOne' : 'remove';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->with([$this->options['id_field'] => 'foo']);
|
||||
|
||||
$this->assertTrue($this->storage->destroy('foo'));
|
||||
}
|
||||
|
||||
public function testGc()
|
||||
{
|
||||
$collection = $this->createMongoCollectionMock();
|
||||
|
||||
$this->mongo->expects($this->once())
|
||||
->method('selectCollection')
|
||||
->with($this->options['database'], $this->options['collection'])
|
||||
->willReturn($collection);
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'deleteMany' : 'remove';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->willReturnCallback(function ($criteria) {
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$lt']);
|
||||
$this->assertGreaterThanOrEqual(time() - 1, round((string) $criteria[$this->options['expiry_field']]['$lt'] / 1000));
|
||||
} else {
|
||||
$this->assertInstanceOf('MongoDate', $criteria[$this->options['expiry_field']]['$lt']);
|
||||
$this->assertGreaterThanOrEqual(time() - 1, $criteria[$this->options['expiry_field']]['$lt']->sec);
|
||||
}
|
||||
});
|
||||
|
||||
$this->assertTrue($this->storage->gc(1));
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$method = new \ReflectionMethod($this->storage, 'getMongo');
|
||||
$method->setAccessible(true);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$mongoClass = 'MongoDB\Client';
|
||||
} else {
|
||||
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? 'Mongo' : 'MongoClient';
|
||||
}
|
||||
|
||||
$this->assertInstanceOf($mongoClass, $method->invoke($this->storage));
|
||||
}
|
||||
|
||||
private function createMongoCollectionMock()
|
||||
{
|
||||
$collectionClass = 'MongoCollection';
|
||||
if (phpversion('mongodb')) {
|
||||
$collectionClass = 'MongoDB\Collection';
|
||||
}
|
||||
|
||||
$collection = $this->getMockBuilder($collectionClass)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for NativeFileSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class NativeFileSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$storage = new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler(sys_get_temp_dir()));
|
||||
|
||||
$this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
|
||||
$this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
|
||||
$this->assertEquals('TESTING', ini_get('session.name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider savePathDataProvider
|
||||
*/
|
||||
public function testConstructSavePath($savePath, $expectedSavePath, $path)
|
||||
{
|
||||
new NativeFileSessionHandler($savePath);
|
||||
$this->assertEquals($expectedSavePath, ini_get('session.save_path'));
|
||||
$this->assertDirectoryExists(realpath($path));
|
||||
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
public function savePathDataProvider()
|
||||
{
|
||||
$base = sys_get_temp_dir();
|
||||
|
||||
return [
|
||||
["$base/foo", "$base/foo", "$base/foo"],
|
||||
["5;$base/foo", "5;$base/foo", "$base/foo"],
|
||||
["5;0600;$base/foo", "5;0600;$base/foo", "$base/foo"],
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructException()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new NativeFileSessionHandler('something;invalid;with;too-many-args');
|
||||
}
|
||||
|
||||
public function testConstructDefault()
|
||||
{
|
||||
$path = ini_get('session.save_path');
|
||||
new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler());
|
||||
|
||||
$this->assertEquals($path, ini_get('session.save_path'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
|
||||
|
||||
/**
|
||||
* Test class for NativeSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @group legacy
|
||||
*/
|
||||
class NativeSessionHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedDeprecation The Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the \SessionHandler class instead.
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$handler = new NativeSessionHandler();
|
||||
|
||||
$this->assertInstanceOf('SessionHandler', $handler);
|
||||
$this->assertTrue($handler instanceof NativeSessionHandler);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for NullSessionHandler.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class NullSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testSaveHandlers()
|
||||
{
|
||||
$this->getStorage();
|
||||
$this->assertEquals('user', ini_get('session.save_handler'));
|
||||
}
|
||||
|
||||
public function testSession()
|
||||
{
|
||||
session_id('nullsessionstorage');
|
||||
$storage = $this->getStorage();
|
||||
$session = new Session($storage);
|
||||
$this->assertNull($session->get('something'));
|
||||
$session->set('something', 'unique');
|
||||
$this->assertEquals('unique', $session->get('something'));
|
||||
}
|
||||
|
||||
public function testNothingIsPersisted()
|
||||
{
|
||||
session_id('nullsessionstorage');
|
||||
$storage = $this->getStorage();
|
||||
$session = new Session($storage);
|
||||
$session->start();
|
||||
$this->assertEquals('nullsessionstorage', $session->getId());
|
||||
$this->assertNull($session->get('something'));
|
||||
}
|
||||
|
||||
public function getStorage()
|
||||
{
|
||||
return new NativeSessionStorage([], new NullSessionHandler());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
|
||||
|
||||
/**
|
||||
* @requires extension pdo_sqlite
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class PdoSessionHandlerTest extends TestCase
|
||||
{
|
||||
private $dbFile;
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// make sure the temporary database file is deleted when it has been created (even when a test fails)
|
||||
if ($this->dbFile) {
|
||||
@unlink($this->dbFile);
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected function getPersistentSqliteDsn()
|
||||
{
|
||||
$this->dbFile = tempnam(sys_get_temp_dir(), 'sf2_sqlite_sessions');
|
||||
|
||||
return 'sqlite:'.$this->dbFile;
|
||||
}
|
||||
|
||||
protected function getMemorySqlitePdo()
|
||||
{
|
||||
$pdo = new \PDO('sqlite::memory:');
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
$storage->createTable();
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
public function testWrongPdoErrMode()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$pdo = $this->getMemorySqlitePdo();
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
|
||||
|
||||
new PdoSessionHandler($pdo);
|
||||
}
|
||||
|
||||
public function testInexistentTable()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo(), ['db_table' => 'inexistent_table']);
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
}
|
||||
|
||||
public function testCreateTableTwice()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->createTable();
|
||||
}
|
||||
|
||||
public function testWithLazyDsnConnection()
|
||||
{
|
||||
$dsn = $this->getPersistentSqliteDsn();
|
||||
|
||||
$storage = new PdoSessionHandler($dsn);
|
||||
$storage->createTable();
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
$this->assertSame('', $data, 'New session returns empty string data');
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('id');
|
||||
$storage->close();
|
||||
$this->assertSame('data', $data, 'Written value can be read back correctly');
|
||||
}
|
||||
|
||||
public function testWithLazySavePathConnection()
|
||||
{
|
||||
$dsn = $this->getPersistentSqliteDsn();
|
||||
|
||||
// Open is called with what ini_set('session.save_path', $dsn) would mean
|
||||
$storage = new PdoSessionHandler(null);
|
||||
$storage->open($dsn, 'sid');
|
||||
$storage->createTable();
|
||||
$data = $storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
$this->assertSame('', $data, 'New session returns empty string data');
|
||||
|
||||
$storage->open($dsn, 'sid');
|
||||
$data = $storage->read('id');
|
||||
$storage->close();
|
||||
$this->assertSame('data', $data, 'Written value can be read back correctly');
|
||||
}
|
||||
|
||||
public function testReadWriteReadWithNullByte()
|
||||
{
|
||||
$sessionData = 'da'."\0".'ta';
|
||||
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->open('', 'sid');
|
||||
$readData = $storage->read('id');
|
||||
$storage->write('id', $sessionData);
|
||||
$storage->close();
|
||||
$this->assertSame('', $readData, 'New session returns empty string data');
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$readData = $storage->read('id');
|
||||
$storage->close();
|
||||
$this->assertSame($sessionData, $readData, 'Written value can be read back correctly');
|
||||
}
|
||||
|
||||
public function testReadConvertsStreamToString()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('PHPUnit_MockObject cannot mock the PDOStatement class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
|
||||
}
|
||||
|
||||
$pdo = new MockPdo('pgsql');
|
||||
$pdo->prepareResult = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
|
||||
$content = 'foobar';
|
||||
$stream = $this->createStream($content);
|
||||
|
||||
$pdo->prepareResult->expects($this->once())->method('fetchAll')
|
||||
->willReturn([[$stream, 42, time()]]);
|
||||
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
$result = $storage->read('foo');
|
||||
|
||||
$this->assertSame($content, $result);
|
||||
}
|
||||
|
||||
public function testReadLockedConvertsStreamToString()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('PHPUnit_MockObject cannot mock the PDOStatement class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
|
||||
}
|
||||
if (filter_var(ini_get('session.use_strict_mode'), \FILTER_VALIDATE_BOOLEAN)) {
|
||||
$this->markTestSkipped('Strict mode needs no locking for new sessions.');
|
||||
}
|
||||
|
||||
$pdo = new MockPdo('pgsql');
|
||||
$selectStmt = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
$insertStmt = $this->getMockBuilder('PDOStatement')->getMock();
|
||||
|
||||
$pdo->prepareResult = function ($statement) use ($selectStmt, $insertStmt) {
|
||||
return 0 === strpos($statement, 'INSERT') ? $insertStmt : $selectStmt;
|
||||
};
|
||||
|
||||
$content = 'foobar';
|
||||
$stream = $this->createStream($content);
|
||||
$exception = null;
|
||||
|
||||
$selectStmt->expects($this->atLeast(2))->method('fetchAll')
|
||||
->willReturnCallback(function () use (&$exception, $stream) {
|
||||
return $exception ? [[$stream, 42, time()]] : [];
|
||||
});
|
||||
|
||||
$insertStmt->expects($this->once())->method('execute')
|
||||
->willReturnCallback(function () use (&$exception) {
|
||||
throw $exception = new \PDOException('', '23');
|
||||
});
|
||||
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
$result = $storage->read('foo');
|
||||
|
||||
$this->assertSame($content, $result);
|
||||
}
|
||||
|
||||
public function testReadingRequiresExactlySameId()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->open('', 'sid');
|
||||
$storage->write('id', 'data');
|
||||
$storage->write('test', 'data');
|
||||
$storage->write('space ', 'data');
|
||||
$storage->close();
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$readDataCaseSensitive = $storage->read('ID');
|
||||
$readDataNoCharFolding = $storage->read('tést');
|
||||
$readDataKeepSpace = $storage->read('space ');
|
||||
$readDataExtraSpace = $storage->read('space ');
|
||||
$storage->close();
|
||||
|
||||
$this->assertSame('', $readDataCaseSensitive, 'Retrieval by ID should be case-sensitive (collation setting)');
|
||||
$this->assertSame('', $readDataNoCharFolding, 'Retrieval by ID should not do character folding (collation setting)');
|
||||
$this->assertSame('data', $readDataKeepSpace, 'Retrieval by ID requires spaces as-is');
|
||||
$this->assertSame('', $readDataExtraSpace, 'Retrieval by ID requires spaces as-is');
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates session_regenerate_id(true) which will require an INSERT or UPDATE (replace).
|
||||
*/
|
||||
public function testWriteDifferentSessionIdThanRead()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->destroy('id');
|
||||
$storage->write('new_id', 'data_of_new_session_id');
|
||||
$storage->close();
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('new_id');
|
||||
$storage->close();
|
||||
|
||||
$this->assertSame('data_of_new_session_id', $data, 'Data of regenerated session id is available');
|
||||
}
|
||||
|
||||
public function testWrongUsageStillWorks()
|
||||
{
|
||||
// wrong method sequence that should no happen, but still works
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
$storage->write('id', 'data');
|
||||
$storage->write('other_id', 'other_data');
|
||||
$storage->destroy('inexistent');
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('id');
|
||||
$otherData = $storage->read('other_id');
|
||||
$storage->close();
|
||||
|
||||
$this->assertSame('data', $data);
|
||||
$this->assertSame('other_data', $otherData);
|
||||
}
|
||||
|
||||
public function testSessionDestroy()
|
||||
{
|
||||
$pdo = $this->getMemorySqlitePdo();
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
$this->assertEquals(1, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn());
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->destroy('id');
|
||||
$storage->close();
|
||||
$this->assertEquals(0, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn());
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('id');
|
||||
$storage->close();
|
||||
$this->assertSame('', $data, 'Destroyed session returns empty string');
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testSessionGC()
|
||||
{
|
||||
$previousLifeTime = ini_set('session.gc_maxlifetime', 1000);
|
||||
$pdo = $this->getMemorySqlitePdo();
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('gc_id');
|
||||
ini_set('session.gc_maxlifetime', -1); // test that you can set lifetime of a session after it has been read
|
||||
$storage->write('gc_id', 'data');
|
||||
$storage->close();
|
||||
$this->assertEquals(2, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'No session pruned because gc not called');
|
||||
|
||||
$storage->open('', 'sid');
|
||||
$data = $storage->read('gc_id');
|
||||
$storage->gc(-1);
|
||||
$storage->close();
|
||||
|
||||
ini_set('session.gc_maxlifetime', $previousLifeTime);
|
||||
|
||||
$this->assertSame('', $data, 'Session already considered garbage, so not returning data even if it is not pruned yet');
|
||||
$this->assertEquals(1, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'Expired session is pruned');
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
|
||||
|
||||
$method = new \ReflectionMethod($storage, 'getConnection');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\PDO', $method->invoke($storage));
|
||||
}
|
||||
|
||||
public function testGetConnectionConnectsIfNeeded()
|
||||
{
|
||||
$storage = new PdoSessionHandler('sqlite::memory:');
|
||||
|
||||
$method = new \ReflectionMethod($storage, 'getConnection');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\PDO', $method->invoke($storage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideUrlDsnPairs
|
||||
*/
|
||||
public function testUrlDsn($url, $expectedDsn, $expectedUser = null, $expectedPassword = null)
|
||||
{
|
||||
$storage = new PdoSessionHandler($url);
|
||||
$reflection = new \ReflectionClass(PdoSessionHandler::class);
|
||||
|
||||
foreach (['dsn' => $expectedDsn, 'username' => $expectedUser, 'password' => $expectedPassword] as $property => $expectedValue) {
|
||||
if (!isset($expectedValue)) {
|
||||
continue;
|
||||
}
|
||||
$property = $reflection->getProperty($property);
|
||||
$property->setAccessible(true);
|
||||
$this->assertSame($expectedValue, $property->getValue($storage));
|
||||
}
|
||||
}
|
||||
|
||||
public function provideUrlDsnPairs()
|
||||
{
|
||||
yield ['mysql://localhost/test', 'mysql:host=localhost;dbname=test;'];
|
||||
yield ['mysql://localhost:56/test', 'mysql:host=localhost;port=56;dbname=test;'];
|
||||
yield ['mysql2://root:pwd@localhost/test', 'mysql:host=localhost;dbname=test;', 'root', 'pwd'];
|
||||
yield ['postgres://localhost/test', 'pgsql:host=localhost;dbname=test;'];
|
||||
yield ['postgresql://localhost:5634/test', 'pgsql:host=localhost;port=5634;dbname=test;'];
|
||||
yield ['postgres://root:pwd@localhost/test', 'pgsql:host=localhost;dbname=test;', 'root', 'pwd'];
|
||||
yield 'sqlite relative path' => ['sqlite://localhost/tmp/test', 'sqlite:tmp/test'];
|
||||
yield 'sqlite absolute path' => ['sqlite://localhost//tmp/test', 'sqlite:/tmp/test'];
|
||||
yield 'sqlite relative path without host' => ['sqlite:///tmp/test', 'sqlite:tmp/test'];
|
||||
yield 'sqlite absolute path without host' => ['sqlite3:////tmp/test', 'sqlite:/tmp/test'];
|
||||
yield ['sqlite://localhost/:memory:', 'sqlite::memory:'];
|
||||
yield ['mssql://localhost/test', 'sqlsrv:server=localhost;Database=test'];
|
||||
yield ['mssql://localhost:56/test', 'sqlsrv:server=localhost,56;Database=test'];
|
||||
}
|
||||
|
||||
private function createStream($content)
|
||||
{
|
||||
$stream = tmpfile();
|
||||
fwrite($stream, $content);
|
||||
fseek($stream, 0);
|
||||
|
||||
return $stream;
|
||||
}
|
||||
}
|
||||
|
||||
class MockPdo extends \PDO
|
||||
{
|
||||
public $prepareResult;
|
||||
private $driverName;
|
||||
private $errorMode;
|
||||
|
||||
public function __construct($driverName = null, $errorMode = null)
|
||||
{
|
||||
$this->driverName = $driverName;
|
||||
$this->errorMode = null !== $errorMode ?: \PDO::ERRMODE_EXCEPTION;
|
||||
}
|
||||
|
||||
public function getAttribute($attribute)
|
||||
{
|
||||
if (\PDO::ATTR_ERRMODE === $attribute) {
|
||||
return $this->errorMode;
|
||||
}
|
||||
|
||||
if (\PDO::ATTR_DRIVER_NAME === $attribute) {
|
||||
return $this->driverName;
|
||||
}
|
||||
|
||||
return parent::getAttribute($attribute);
|
||||
}
|
||||
|
||||
public function prepare($statement, $driverOptions = [])
|
||||
{
|
||||
return \is_callable($this->prepareResult)
|
||||
? \call_user_func($this->prepareResult, $statement, $driverOptions)
|
||||
: $this->prepareResult;
|
||||
}
|
||||
|
||||
public function beginTransaction()
|
||||
{
|
||||
}
|
||||
|
||||
public function rollBack()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
|
||||
|
||||
class StrictSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testOpen()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('open')
|
||||
->with('path', 'name')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertInstanceOf('SessionUpdateTimestampHandlerInterface', $proxy);
|
||||
$this->assertInstanceOf(AbstractSessionHandler::class, $proxy);
|
||||
$this->assertTrue($proxy->open('path', 'name'));
|
||||
}
|
||||
|
||||
public function testCloseSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('close')
|
||||
->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->close());
|
||||
}
|
||||
|
||||
public function testValidateIdOK()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('data');
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->validateId('id'));
|
||||
}
|
||||
|
||||
public function testValidateIdKO()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('');
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertFalse($proxy->validateId('id'));
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('data');
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertSame('data', $proxy->read('id'));
|
||||
}
|
||||
|
||||
public function testReadWithValidateIdOK()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('data');
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->validateId('id'));
|
||||
$this->assertSame('data', $proxy->read('id'));
|
||||
}
|
||||
|
||||
public function testReadWithValidateIdMismatch()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->exactly(2))->method('read')
|
||||
->withConsecutive(['id1'], ['id2'])
|
||||
->will($this->onConsecutiveCalls('data1', 'data2'));
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->validateId('id1'));
|
||||
$this->assertSame('data2', $proxy->read('id2'));
|
||||
}
|
||||
|
||||
public function testUpdateTimestamp()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('write')
|
||||
->with('id', 'data')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->updateTimestamp('id', 'data'));
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('write')
|
||||
->with('id', 'data')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->write('id', 'data'));
|
||||
}
|
||||
|
||||
public function testWriteEmptyNewSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('');
|
||||
$handler->expects($this->never())->method('write');
|
||||
$handler->expects($this->once())->method('destroy')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertFalse($proxy->validateId('id'));
|
||||
$this->assertSame('', $proxy->read('id'));
|
||||
$this->assertTrue($proxy->write('id', ''));
|
||||
}
|
||||
|
||||
public function testWriteEmptyExistingSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('data');
|
||||
$handler->expects($this->never())->method('write');
|
||||
$handler->expects($this->once())->method('destroy')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertSame('data', $proxy->read('id'));
|
||||
$this->assertTrue($proxy->write('id', ''));
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('destroy')
|
||||
->with('id')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->destroy('id'));
|
||||
}
|
||||
|
||||
public function testDestroyNewSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('');
|
||||
$handler->expects($this->once())->method('destroy')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertSame('', $proxy->read('id'));
|
||||
$this->assertTrue($proxy->destroy('id'));
|
||||
}
|
||||
|
||||
public function testDestroyNonEmptyNewSession()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('read')
|
||||
->with('id')->willReturn('');
|
||||
$handler->expects($this->once())->method('write')
|
||||
->with('id', 'data')->willReturn(true);
|
||||
$handler->expects($this->once())->method('destroy')
|
||||
->with('id')->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertSame('', $proxy->read('id'));
|
||||
$this->assertTrue($proxy->write('id', 'data'));
|
||||
$this->assertTrue($proxy->destroy('id'));
|
||||
}
|
||||
|
||||
public function testGc()
|
||||
{
|
||||
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$handler->expects($this->once())->method('gc')
|
||||
->with(123)->willReturn(true);
|
||||
$proxy = new StrictSessionHandler($handler);
|
||||
|
||||
$this->assertTrue($proxy->gc(123));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler;
|
||||
|
||||
/**
|
||||
* @author Adrien Brault <adrien.brault@gmail.com>
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
class WriteCheckSessionHandlerTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('close')
|
||||
->with()
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$this->assertTrue($writeCheckSessionHandler->close());
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('write')
|
||||
->with('foo', 'bar')
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
|
||||
}
|
||||
|
||||
public function testSkippedWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('read')
|
||||
->with('foo')
|
||||
->willReturn('bar')
|
||||
;
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->never())
|
||||
->method('write')
|
||||
;
|
||||
|
||||
$this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
|
||||
$this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
|
||||
}
|
||||
|
||||
public function testNonSkippedWrite()
|
||||
{
|
||||
$wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('read')
|
||||
->with('foo')
|
||||
->willReturn('bar')
|
||||
;
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('write')
|
||||
->with('foo', 'baZZZ')
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
|
||||
$this->assertTrue($writeCheckSessionHandler->write('foo', 'baZZZ'));
|
||||
}
|
||||
}
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/Handler/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/Handler/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
139
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/MetadataBagTest.php
vendored
Normal file
139
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/MetadataBagTest.php
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
|
||||
|
||||
/**
|
||||
* Test class for MetadataBag.
|
||||
*
|
||||
* @group time-sensitive
|
||||
*/
|
||||
class MetadataBagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MetadataBag
|
||||
*/
|
||||
protected $bag;
|
||||
|
||||
protected $array = [];
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->bag = new MetadataBag();
|
||||
$this->array = [MetadataBag::CREATED => 1234567, MetadataBag::UPDATED => 12345678, MetadataBag::LIFETIME => 0];
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->array = [];
|
||||
$this->bag = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$sessionMetadata = [];
|
||||
|
||||
$bag1 = new MetadataBag();
|
||||
$bag1->initialize($sessionMetadata);
|
||||
$this->assertGreaterThanOrEqual(time(), $bag1->getCreated());
|
||||
$this->assertEquals($bag1->getCreated(), $bag1->getLastUsed());
|
||||
|
||||
sleep(1);
|
||||
$bag2 = new MetadataBag();
|
||||
$bag2->initialize($sessionMetadata);
|
||||
$this->assertEquals($bag1->getCreated(), $bag2->getCreated());
|
||||
$this->assertEquals($bag1->getLastUsed(), $bag2->getLastUsed());
|
||||
$this->assertEquals($bag2->getCreated(), $bag2->getLastUsed());
|
||||
|
||||
sleep(1);
|
||||
$bag3 = new MetadataBag();
|
||||
$bag3->initialize($sessionMetadata);
|
||||
$this->assertEquals($bag1->getCreated(), $bag3->getCreated());
|
||||
$this->assertGreaterThan($bag2->getLastUsed(), $bag3->getLastUsed());
|
||||
$this->assertNotEquals($bag3->getCreated(), $bag3->getLastUsed());
|
||||
}
|
||||
|
||||
public function testGetSetName()
|
||||
{
|
||||
$this->assertEquals('__metadata', $this->bag->getName());
|
||||
$this->bag->setName('foo');
|
||||
$this->assertEquals('foo', $this->bag->getName());
|
||||
}
|
||||
|
||||
public function testGetStorageKey()
|
||||
{
|
||||
$this->assertEquals('_sf2_meta', $this->bag->getStorageKey());
|
||||
}
|
||||
|
||||
public function testGetLifetime()
|
||||
{
|
||||
$bag = new MetadataBag();
|
||||
$array = [MetadataBag::CREATED => 1234567, MetadataBag::UPDATED => 12345678, MetadataBag::LIFETIME => 1000];
|
||||
$bag->initialize($array);
|
||||
$this->assertEquals(1000, $bag->getLifetime());
|
||||
}
|
||||
|
||||
public function testGetCreated()
|
||||
{
|
||||
$this->assertEquals(1234567, $this->bag->getCreated());
|
||||
}
|
||||
|
||||
public function testGetLastUsed()
|
||||
{
|
||||
$this->assertLessThanOrEqual(time(), $this->bag->getLastUsed());
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->bag->clear();
|
||||
|
||||
// the clear method has no side effects, we just want to ensure it doesn't trigger any exceptions
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testSkipLastUsedUpdate()
|
||||
{
|
||||
$bag = new MetadataBag('', 30);
|
||||
$timeStamp = time();
|
||||
|
||||
$created = $timeStamp - 15;
|
||||
$sessionMetadata = [
|
||||
MetadataBag::CREATED => $created,
|
||||
MetadataBag::UPDATED => $created,
|
||||
MetadataBag::LIFETIME => 1000,
|
||||
];
|
||||
$bag->initialize($sessionMetadata);
|
||||
|
||||
$this->assertEquals($created, $sessionMetadata[MetadataBag::UPDATED]);
|
||||
}
|
||||
|
||||
public function testDoesNotSkipLastUsedUpdate()
|
||||
{
|
||||
$bag = new MetadataBag('', 30);
|
||||
$timeStamp = time();
|
||||
|
||||
$created = $timeStamp - 45;
|
||||
$sessionMetadata = [
|
||||
MetadataBag::CREATED => $created,
|
||||
MetadataBag::UPDATED => $created,
|
||||
MetadataBag::LIFETIME => 1000,
|
||||
];
|
||||
$bag->initialize($sessionMetadata);
|
||||
|
||||
$this->assertEquals($timeStamp, $sessionMetadata[MetadataBag::UPDATED]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for MockArraySessionStorage.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class MockArraySessionStorageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MockArraySessionStorage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
/**
|
||||
* @var AttributeBag
|
||||
*/
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* @var FlashBag
|
||||
*/
|
||||
private $flashes;
|
||||
|
||||
private $data;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->attributes = new AttributeBag();
|
||||
$this->flashes = new FlashBag();
|
||||
|
||||
$this->data = [
|
||||
$this->attributes->getStorageKey() => ['foo' => 'bar'],
|
||||
$this->flashes->getStorageKey() => ['notice' => 'hello'],
|
||||
];
|
||||
|
||||
$this->storage = new MockArraySessionStorage();
|
||||
$this->storage->registerBag($this->flashes);
|
||||
$this->storage->registerBag($this->attributes);
|
||||
$this->storage->setSessionData($this->data);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->data = null;
|
||||
$this->flashes = null;
|
||||
$this->attributes = null;
|
||||
$this->storage = null;
|
||||
}
|
||||
|
||||
public function testStart()
|
||||
{
|
||||
$this->assertEquals('', $this->storage->getId());
|
||||
$this->storage->start();
|
||||
$id = $this->storage->getId();
|
||||
$this->assertNotEquals('', $id);
|
||||
$this->storage->start();
|
||||
$this->assertEquals($id, $this->storage->getId());
|
||||
}
|
||||
|
||||
public function testRegenerate()
|
||||
{
|
||||
$this->storage->start();
|
||||
$id = $this->storage->getId();
|
||||
$this->storage->regenerate();
|
||||
$this->assertNotEquals($id, $this->storage->getId());
|
||||
$this->assertEquals(['foo' => 'bar'], $this->storage->getBag('attributes')->all());
|
||||
$this->assertEquals(['notice' => 'hello'], $this->storage->getBag('flashes')->peekAll());
|
||||
|
||||
$id = $this->storage->getId();
|
||||
$this->storage->regenerate(true);
|
||||
$this->assertNotEquals($id, $this->storage->getId());
|
||||
$this->assertEquals(['foo' => 'bar'], $this->storage->getBag('attributes')->all());
|
||||
$this->assertEquals(['notice' => 'hello'], $this->storage->getBag('flashes')->peekAll());
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
$this->assertEquals('', $this->storage->getId());
|
||||
$this->storage->start();
|
||||
$this->assertNotEquals('', $this->storage->getId());
|
||||
}
|
||||
|
||||
public function testClearClearsBags()
|
||||
{
|
||||
$this->storage->clear();
|
||||
|
||||
$this->assertSame([], $this->storage->getBag('attributes')->all());
|
||||
$this->assertSame([], $this->storage->getBag('flashes')->peekAll());
|
||||
}
|
||||
|
||||
public function testClearStartsSession()
|
||||
{
|
||||
$this->storage->clear();
|
||||
|
||||
$this->assertTrue($this->storage->isStarted());
|
||||
}
|
||||
|
||||
public function testClearWithNoBagsStartsSession()
|
||||
{
|
||||
$storage = new MockArraySessionStorage();
|
||||
|
||||
$storage->clear();
|
||||
|
||||
$this->assertTrue($storage->isStarted());
|
||||
}
|
||||
|
||||
public function testUnstartedSave()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$this->storage->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for MockFileSessionStorage.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class MockFileSessionStorageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sessionDir;
|
||||
|
||||
/**
|
||||
* @var MockFileSessionStorage
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->sessionDir = sys_get_temp_dir().'/sf2test';
|
||||
$this->storage = $this->getStorage();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
array_map('unlink', glob($this->sessionDir.'/*'));
|
||||
if (is_dir($this->sessionDir)) {
|
||||
@rmdir($this->sessionDir);
|
||||
}
|
||||
$this->sessionDir = null;
|
||||
$this->storage = null;
|
||||
}
|
||||
|
||||
public function testStart()
|
||||
{
|
||||
$this->assertEquals('', $this->storage->getId());
|
||||
$this->assertTrue($this->storage->start());
|
||||
$id = $this->storage->getId();
|
||||
$this->assertNotEquals('', $this->storage->getId());
|
||||
$this->assertTrue($this->storage->start());
|
||||
$this->assertEquals($id, $this->storage->getId());
|
||||
}
|
||||
|
||||
public function testRegenerate()
|
||||
{
|
||||
$this->storage->start();
|
||||
$this->storage->getBag('attributes')->set('regenerate', 1234);
|
||||
$this->storage->regenerate();
|
||||
$this->assertEquals(1234, $this->storage->getBag('attributes')->get('regenerate'));
|
||||
$this->storage->regenerate(true);
|
||||
$this->assertEquals(1234, $this->storage->getBag('attributes')->get('regenerate'));
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
$this->assertEquals('', $this->storage->getId());
|
||||
$this->storage->start();
|
||||
$this->assertNotEquals('', $this->storage->getId());
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$this->storage->start();
|
||||
$id = $this->storage->getId();
|
||||
$this->assertNotEquals('108', $this->storage->getBag('attributes')->get('new'));
|
||||
$this->assertFalse($this->storage->getBag('flashes')->has('newkey'));
|
||||
$this->storage->getBag('attributes')->set('new', '108');
|
||||
$this->storage->getBag('flashes')->set('newkey', 'test');
|
||||
$this->storage->save();
|
||||
|
||||
$storage = $this->getStorage();
|
||||
$storage->setId($id);
|
||||
$storage->start();
|
||||
$this->assertEquals('108', $storage->getBag('attributes')->get('new'));
|
||||
$this->assertTrue($storage->getBag('flashes')->has('newkey'));
|
||||
$this->assertEquals(['test'], $storage->getBag('flashes')->peek('newkey'));
|
||||
}
|
||||
|
||||
public function testMultipleInstances()
|
||||
{
|
||||
$storage1 = $this->getStorage();
|
||||
$storage1->start();
|
||||
$storage1->getBag('attributes')->set('foo', 'bar');
|
||||
$storage1->save();
|
||||
|
||||
$storage2 = $this->getStorage();
|
||||
$storage2->setId($storage1->getId());
|
||||
$storage2->start();
|
||||
$this->assertEquals('bar', $storage2->getBag('attributes')->get('foo'), 'values persist between instances');
|
||||
}
|
||||
|
||||
public function testSaveWithoutStart()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$storage1 = $this->getStorage();
|
||||
$storage1->save();
|
||||
}
|
||||
|
||||
private function getStorage()
|
||||
{
|
||||
$storage = new MockFileSessionStorage($this->sessionDir);
|
||||
$storage->registerBag(new FlashBag());
|
||||
$storage->registerBag(new AttributeBag());
|
||||
|
||||
return $storage;
|
||||
}
|
||||
}
|
||||
303
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/NativeSessionStorageTest.php
vendored
Normal file
303
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/NativeSessionStorageTest.php
vendored
Normal file
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
|
||||
/**
|
||||
* Test class for NativeSessionStorage.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* These tests require separate processes.
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class NativeSessionStorageTest extends TestCase
|
||||
{
|
||||
private $savePath;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->iniSet('session.save_handler', 'files');
|
||||
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sftest');
|
||||
if (!is_dir($this->savePath)) {
|
||||
mkdir($this->savePath);
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
session_write_close();
|
||||
array_map('unlink', glob($this->savePath.'/*'));
|
||||
if (is_dir($this->savePath)) {
|
||||
@rmdir($this->savePath);
|
||||
}
|
||||
|
||||
$this->savePath = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NativeSessionStorage
|
||||
*/
|
||||
protected function getStorage(array $options = [])
|
||||
{
|
||||
$storage = new NativeSessionStorage($options);
|
||||
$storage->registerBag(new AttributeBag());
|
||||
|
||||
return $storage;
|
||||
}
|
||||
|
||||
public function testBag()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$bag = new FlashBag();
|
||||
$storage->registerBag($bag);
|
||||
$this->assertSame($bag, $storage->getBag($bag->getName()));
|
||||
}
|
||||
|
||||
public function testRegisterBagException()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$storage = $this->getStorage();
|
||||
$storage->getBag('non_existing');
|
||||
}
|
||||
|
||||
public function testRegisterBagForAStartedSessionThrowsException()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$storage = $this->getStorage();
|
||||
$storage->start();
|
||||
$storage->registerBag(new AttributeBag());
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$this->assertSame('', $storage->getId(), 'Empty ID before starting session');
|
||||
|
||||
$storage->start();
|
||||
$id = $storage->getId();
|
||||
$this->assertIsString($id);
|
||||
$this->assertNotSame('', $id);
|
||||
|
||||
$storage->save();
|
||||
$this->assertSame($id, $storage->getId(), 'ID stays after saving session');
|
||||
}
|
||||
|
||||
public function testRegenerate()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$storage->start();
|
||||
$id = $storage->getId();
|
||||
$storage->getBag('attributes')->set('lucky', 7);
|
||||
$storage->regenerate();
|
||||
$this->assertNotEquals($id, $storage->getId());
|
||||
$this->assertEquals(7, $storage->getBag('attributes')->get('lucky'));
|
||||
}
|
||||
|
||||
public function testRegenerateDestroy()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$storage->start();
|
||||
$id = $storage->getId();
|
||||
$storage->getBag('attributes')->set('legs', 11);
|
||||
$storage->regenerate(true);
|
||||
$this->assertNotEquals($id, $storage->getId());
|
||||
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
|
||||
}
|
||||
|
||||
public function testRegenerateWithCustomLifetime()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$storage->start();
|
||||
$id = $storage->getId();
|
||||
$lifetime = 999999;
|
||||
$storage->getBag('attributes')->set('legs', 11);
|
||||
$storage->regenerate(false, $lifetime);
|
||||
$this->assertNotEquals($id, $storage->getId());
|
||||
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
|
||||
$this->assertEquals($lifetime, ini_get('session.cookie_lifetime'));
|
||||
}
|
||||
|
||||
public function testSessionGlobalIsUpToDateAfterIdRegeneration()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$storage->start();
|
||||
$storage->getBag('attributes')->set('lucky', 7);
|
||||
$storage->regenerate();
|
||||
$storage->getBag('attributes')->set('lucky', 42);
|
||||
|
||||
$this->assertEquals(42, $_SESSION['_sf2_attributes']['lucky']);
|
||||
}
|
||||
|
||||
public function testRegenerationFailureDoesNotFlagStorageAsStarted()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$this->assertFalse($storage->regenerate());
|
||||
$this->assertFalse($storage->isStarted());
|
||||
}
|
||||
|
||||
public function testDefaultSessionCacheLimiter()
|
||||
{
|
||||
$this->iniSet('session.cache_limiter', 'nocache');
|
||||
|
||||
new NativeSessionStorage();
|
||||
$this->assertEquals('', ini_get('session.cache_limiter'));
|
||||
}
|
||||
|
||||
public function testExplicitSessionCacheLimiter()
|
||||
{
|
||||
$this->iniSet('session.cache_limiter', 'nocache');
|
||||
|
||||
new NativeSessionStorage(['cache_limiter' => 'public']);
|
||||
$this->assertEquals('public', ini_get('session.cache_limiter'));
|
||||
}
|
||||
|
||||
public function testCookieOptions()
|
||||
{
|
||||
$options = [
|
||||
'cookie_lifetime' => 123456,
|
||||
'cookie_path' => '/my/cookie/path',
|
||||
'cookie_domain' => 'symfony.example.com',
|
||||
'cookie_secure' => true,
|
||||
'cookie_httponly' => false,
|
||||
];
|
||||
|
||||
if (\PHP_VERSION_ID >= 70300) {
|
||||
$options['cookie_samesite'] = 'lax';
|
||||
}
|
||||
|
||||
$this->getStorage($options);
|
||||
$temp = session_get_cookie_params();
|
||||
$gco = [];
|
||||
|
||||
foreach ($temp as $key => $value) {
|
||||
$gco['cookie_'.$key] = $value;
|
||||
}
|
||||
|
||||
$this->assertEquals($options, $gco);
|
||||
}
|
||||
|
||||
public function testSessionOptions()
|
||||
{
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('HHVM is not handled in this test case.');
|
||||
}
|
||||
|
||||
$options = [
|
||||
'url_rewriter.tags' => 'a=href',
|
||||
'cache_expire' => '200',
|
||||
];
|
||||
|
||||
$this->getStorage($options);
|
||||
|
||||
$this->assertSame('a=href', ini_get('url_rewriter.tags'));
|
||||
$this->assertSame('200', ini_get('session.cache_expire'));
|
||||
}
|
||||
|
||||
public function testSetSaveHandlerException()
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$storage = $this->getStorage();
|
||||
$storage->setSaveHandler(new \stdClass());
|
||||
}
|
||||
|
||||
public function testSetSaveHandler()
|
||||
{
|
||||
$this->iniSet('session.save_handler', 'files');
|
||||
$storage = $this->getStorage();
|
||||
$storage->setSaveHandler();
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(null);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(new SessionHandlerProxy(new NativeFileSessionHandler()));
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(new NativeFileSessionHandler());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
$storage->setSaveHandler(new NullSessionHandler());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
|
||||
}
|
||||
|
||||
public function testStarted()
|
||||
{
|
||||
$this->expectException('RuntimeException');
|
||||
$storage = $this->getStorage();
|
||||
|
||||
$this->assertFalse($storage->getSaveHandler()->isActive());
|
||||
$this->assertFalse($storage->isStarted());
|
||||
|
||||
session_start();
|
||||
$this->assertTrue(isset($_SESSION));
|
||||
$this->assertTrue($storage->getSaveHandler()->isActive());
|
||||
|
||||
// PHP session might have started, but the storage driver has not, so false is correct here
|
||||
$this->assertFalse($storage->isStarted());
|
||||
|
||||
$key = $storage->getMetadataBag()->getStorageKey();
|
||||
$this->assertArrayNotHasKey($key, $_SESSION);
|
||||
$storage->start();
|
||||
}
|
||||
|
||||
public function testRestart()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$storage->start();
|
||||
$id = $storage->getId();
|
||||
$storage->getBag('attributes')->set('lucky', 7);
|
||||
$storage->save();
|
||||
$storage->start();
|
||||
$this->assertSame($id, $storage->getId(), 'Same session ID after restarting');
|
||||
$this->assertSame(7, $storage->getBag('attributes')->get('lucky'), 'Data still available');
|
||||
}
|
||||
|
||||
public function testCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
|
||||
{
|
||||
session_start();
|
||||
$this->getStorage();
|
||||
|
||||
// Assert no exception has been thrown by `getStorage()`
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testSetSessionOptionsOnceSessionStartedIsIgnored()
|
||||
{
|
||||
session_start();
|
||||
$this->getStorage([
|
||||
'name' => 'something-else',
|
||||
]);
|
||||
|
||||
// Assert no exception has been thrown by `getStorage()`
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function testGetBagsOnceSessionStartedIsIgnored()
|
||||
{
|
||||
session_start();
|
||||
$bag = new AttributeBag();
|
||||
$bag->setName('flashes');
|
||||
|
||||
$storage = $this->getStorage();
|
||||
$storage->registerBag($bag);
|
||||
|
||||
$this->assertEquals($storage->getBag('flashes'), $bag);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
|
||||
|
||||
/**
|
||||
* Test class for PhpSessionStorage.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* These tests require separate processes.
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class PhpBridgeSessionStorageTest extends TestCase
|
||||
{
|
||||
private $savePath;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->iniSet('session.save_handler', 'files');
|
||||
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
|
||||
if (!is_dir($this->savePath)) {
|
||||
mkdir($this->savePath);
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
session_write_close();
|
||||
array_map('unlink', glob($this->savePath.'/*'));
|
||||
if (is_dir($this->savePath)) {
|
||||
@rmdir($this->savePath);
|
||||
}
|
||||
|
||||
$this->savePath = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PhpBridgeSessionStorage
|
||||
*/
|
||||
protected function getStorage()
|
||||
{
|
||||
$storage = new PhpBridgeSessionStorage();
|
||||
$storage->registerBag(new AttributeBag());
|
||||
|
||||
return $storage;
|
||||
}
|
||||
|
||||
public function testPhpSession()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
|
||||
$this->assertFalse($storage->getSaveHandler()->isActive());
|
||||
$this->assertFalse($storage->isStarted());
|
||||
|
||||
session_start();
|
||||
$this->assertTrue(isset($_SESSION));
|
||||
// in PHP 5.4 we can reliably detect a session started
|
||||
$this->assertTrue($storage->getSaveHandler()->isActive());
|
||||
// PHP session might have started, but the storage driver has not, so false is correct here
|
||||
$this->assertFalse($storage->isStarted());
|
||||
|
||||
$key = $storage->getMetadataBag()->getStorageKey();
|
||||
$this->assertArrayNotHasKey($key, $_SESSION);
|
||||
$storage->start();
|
||||
$this->assertArrayHasKey($key, $_SESSION);
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
session_start();
|
||||
$_SESSION['drak'] = 'loves symfony';
|
||||
$storage->getBag('attributes')->set('symfony', 'greatness');
|
||||
$key = $storage->getBag('attributes')->getStorageKey();
|
||||
$this->assertEquals(['symfony' => 'greatness'], $_SESSION[$key]);
|
||||
$this->assertEquals('loves symfony', $_SESSION['drak']);
|
||||
$storage->clear();
|
||||
$this->assertEquals([], $_SESSION[$key]);
|
||||
$this->assertEquals('loves symfony', $_SESSION['drak']);
|
||||
}
|
||||
}
|
||||
113
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php
vendored
Normal file
113
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
|
||||
/**
|
||||
* Test class for AbstractProxy.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class AbstractProxyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var AbstractProxy
|
||||
*/
|
||||
protected $proxy;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->proxy = $this->getMockForAbstractClass(AbstractProxy::class);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->proxy = null;
|
||||
}
|
||||
|
||||
public function testGetSaveHandlerName()
|
||||
{
|
||||
$this->assertNull($this->proxy->getSaveHandlerName());
|
||||
}
|
||||
|
||||
public function testIsSessionHandlerInterface()
|
||||
{
|
||||
$this->assertFalse($this->proxy->isSessionHandlerInterface());
|
||||
$sh = new SessionHandlerProxy(new \SessionHandler());
|
||||
$this->assertTrue($sh->isSessionHandlerInterface());
|
||||
}
|
||||
|
||||
public function testIsWrapper()
|
||||
{
|
||||
$this->assertFalse($this->proxy->isWrapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testIsActive()
|
||||
{
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
session_start();
|
||||
$this->assertTrue($this->proxy->isActive());
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testName()
|
||||
{
|
||||
$this->assertEquals(session_name(), $this->proxy->getName());
|
||||
$this->proxy->setName('foo');
|
||||
$this->assertEquals('foo', $this->proxy->getName());
|
||||
$this->assertEquals(session_name(), $this->proxy->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testNameException()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
session_start();
|
||||
$this->proxy->setName('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testId()
|
||||
{
|
||||
$this->assertEquals(session_id(), $this->proxy->getId());
|
||||
$this->proxy->setId('foo');
|
||||
$this->assertEquals('foo', $this->proxy->getId());
|
||||
$this->assertEquals(session_id(), $this->proxy->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testIdException()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
session_start();
|
||||
$this->proxy->setId('foo');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy;
|
||||
|
||||
/**
|
||||
* Test class for NativeProxy.
|
||||
*
|
||||
* @group legacy
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NativeProxyTest extends TestCase
|
||||
{
|
||||
public function testIsWrapper()
|
||||
{
|
||||
$proxy = new NativeProxy();
|
||||
$this->assertFalse($proxy->isWrapper());
|
||||
}
|
||||
|
||||
public function testGetSaveHandlerName()
|
||||
{
|
||||
$name = ini_get('session.save_handler');
|
||||
$proxy = new NativeProxy();
|
||||
$this->assertEquals($name, $proxy->getSaveHandlerName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
|
||||
|
||||
/**
|
||||
* Tests for SessionHandlerProxy class.
|
||||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class SessionHandlerProxyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\Matcher
|
||||
*/
|
||||
private $mock;
|
||||
|
||||
/**
|
||||
* @var SessionHandlerProxy
|
||||
*/
|
||||
private $proxy;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->mock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
|
||||
$this->proxy = new SessionHandlerProxy($this->mock);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->mock = null;
|
||||
$this->proxy = null;
|
||||
}
|
||||
|
||||
public function testOpenTrue()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('open')
|
||||
->willReturn(true);
|
||||
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
$this->proxy->open('name', 'id');
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
}
|
||||
|
||||
public function testOpenFalse()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('open')
|
||||
->willReturn(false);
|
||||
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
$this->proxy->open('name', 'id');
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
}
|
||||
|
||||
public function testClose()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('close')
|
||||
->willReturn(true);
|
||||
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
$this->proxy->close();
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
}
|
||||
|
||||
public function testCloseFalse()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('close')
|
||||
->willReturn(false);
|
||||
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
$this->proxy->close();
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('read');
|
||||
|
||||
$this->proxy->read('id');
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('write');
|
||||
|
||||
$this->proxy->write('id', 'data');
|
||||
}
|
||||
|
||||
public function testDestroy()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('destroy');
|
||||
|
||||
$this->proxy->destroy('id');
|
||||
}
|
||||
|
||||
public function testGc()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('gc');
|
||||
|
||||
$this->proxy->gc(86400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit 5.1
|
||||
*/
|
||||
public function testValidateId()
|
||||
{
|
||||
$mock = $this->getMockBuilder(TestSessionHandler::class)->getMock();
|
||||
$mock->expects($this->once())
|
||||
->method('validateId');
|
||||
|
||||
$proxy = new SessionHandlerProxy($mock);
|
||||
$proxy->validateId('id');
|
||||
|
||||
$this->assertTrue($this->proxy->validateId('id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit 5.1
|
||||
*/
|
||||
public function testUpdateTimestamp()
|
||||
{
|
||||
$mock = $this->getMockBuilder(TestSessionHandler::class)->getMock();
|
||||
$mock->expects($this->once())
|
||||
->method('updateTimestamp')
|
||||
->willReturn(false);
|
||||
|
||||
$proxy = new SessionHandlerProxy($mock);
|
||||
$proxy->updateTimestamp('id', 'data');
|
||||
|
||||
$this->mock->expects($this->once())
|
||||
->method('write');
|
||||
|
||||
$this->proxy->updateTimestamp('id', 'data');
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TestSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
|
||||
{
|
||||
}
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/Storage/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/Session/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
140
modules/ps_metrics/vendor/symfony/http-foundation/Tests/StreamedResponseTest.php
vendored
Normal file
140
modules/ps_metrics/vendor/symfony/http-foundation/Tests/StreamedResponseTest.php
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class StreamedResponseTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; }, 404, ['Content-Type' => 'text/plain']);
|
||||
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
$this->assertEquals('text/plain', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testPrepareWith11Protocol()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; });
|
||||
$request = Request::create('/');
|
||||
$request->server->set('SERVER_PROTOCOL', 'HTTP/1.1');
|
||||
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertEquals('1.1', $response->getProtocolVersion());
|
||||
$this->assertNotEquals('chunked', $response->headers->get('Transfer-Encoding'), 'Apache assumes responses with a Transfer-Encoding header set to chunked to already be encoded.');
|
||||
}
|
||||
|
||||
public function testPrepareWith10Protocol()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; });
|
||||
$request = Request::create('/');
|
||||
$request->server->set('SERVER_PROTOCOL', 'HTTP/1.0');
|
||||
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertEquals('1.0', $response->getProtocolVersion());
|
||||
$this->assertNull($response->headers->get('Transfer-Encoding'));
|
||||
}
|
||||
|
||||
public function testPrepareWithHeadRequest()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; }, 200, ['Content-Length' => '123']);
|
||||
$request = Request::create('/', 'HEAD');
|
||||
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertSame('123', $response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
public function testPrepareWithCacheHeaders()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; }, 200, ['Cache-Control' => 'max-age=600, public']);
|
||||
$request = Request::create('/', 'GET');
|
||||
|
||||
$response->prepare($request);
|
||||
$this->assertEquals('max-age=600, public', $response->headers->get('Cache-Control'));
|
||||
}
|
||||
|
||||
public function testSendContent()
|
||||
{
|
||||
$called = 0;
|
||||
|
||||
$response = new StreamedResponse(function () use (&$called) { ++$called; });
|
||||
|
||||
$response->sendContent();
|
||||
$this->assertEquals(1, $called);
|
||||
|
||||
$response->sendContent();
|
||||
$this->assertEquals(1, $called);
|
||||
}
|
||||
|
||||
public function testSendContentWithNonCallable()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$response = new StreamedResponse(null);
|
||||
$response->sendContent();
|
||||
}
|
||||
|
||||
public function testSetContent()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$response = new StreamedResponse(function () { echo 'foo'; });
|
||||
$response->setContent('foo');
|
||||
}
|
||||
|
||||
public function testGetContent()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; });
|
||||
$this->assertFalse($response->getContent());
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$response = StreamedResponse::create(function () {}, 204);
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testReturnThis()
|
||||
{
|
||||
$response = new StreamedResponse(function () {});
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
|
||||
|
||||
$response = new StreamedResponse(function () {});
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
|
||||
}
|
||||
|
||||
public function testSetNotModified()
|
||||
{
|
||||
$response = new StreamedResponse(function () { echo 'foo'; });
|
||||
$modified = $response->setNotModified();
|
||||
$this->assertObjectHasAttribute('headers', $modified);
|
||||
$this->assertObjectHasAttribute('content', $modified);
|
||||
$this->assertObjectHasAttribute('version', $modified);
|
||||
$this->assertObjectHasAttribute('statusCode', $modified);
|
||||
$this->assertObjectHasAttribute('statusText', $modified);
|
||||
$this->assertObjectHasAttribute('charset', $modified);
|
||||
$this->assertEquals(304, $modified->getStatusCode());
|
||||
|
||||
ob_start();
|
||||
$modified->sendContent();
|
||||
$string = ob_get_clean();
|
||||
$this->assertEmpty($string);
|
||||
}
|
||||
}
|
||||
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/index.php
vendored
Normal file
11
modules/ps_metrics/vendor/symfony/http-foundation/Tests/index.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user