Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
113
vendor/symfony/http-foundation/Tests/AcceptHeaderItemTest.php
vendored
Normal file
113
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 array(
|
||||
array(
|
||||
'text/html',
|
||||
'text/html', array(),
|
||||
),
|
||||
array(
|
||||
'"this;should,not=matter"',
|
||||
'this;should,not=matter', array(),
|
||||
),
|
||||
array(
|
||||
"text/plain; charset=utf-8;param=\"this;should,not=matter\";\tfootnotes=true",
|
||||
'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'),
|
||||
),
|
||||
array(
|
||||
'"this;should,not=matter";charset=utf-8',
|
||||
'this;should,not=matter', array('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 array(
|
||||
array(
|
||||
'text/html', array(),
|
||||
'text/html',
|
||||
),
|
||||
array(
|
||||
'text/plain', array('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', array());
|
||||
$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', array());
|
||||
$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', array());
|
||||
$this->assertEquals(array(), $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(array('test' => 'value'), $item->getAttributes());
|
||||
$this->assertTrue($item->hasAttribute('test'));
|
||||
$this->assertEquals('value', $item->getAttribute('test'));
|
||||
$this->assertEquals('value', $item->getAttribute('test', 'default'));
|
||||
}
|
||||
}
|
103
vendor/symfony/http-foundation/Tests/AcceptHeaderTest.php
vendored
Normal file
103
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 array(
|
||||
array('', array()),
|
||||
array('gzip', array(new AcceptHeaderItem('gzip'))),
|
||||
array('gzip,deflate,sdch', array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch'))),
|
||||
array("gzip, deflate\t,sdch", array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch'))),
|
||||
array('"this;should,not=matter"', array(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 array(
|
||||
array(array(), ''),
|
||||
array(array(new AcceptHeaderItem('gzip')), 'gzip'),
|
||||
array(array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')), 'gzip,deflate,sdch'),
|
||||
array(array(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 array(
|
||||
array('fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4', '/fr.*/', array('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 array(
|
||||
'quality has priority' => array('*;q=0.3,ISO-8859-1,utf-8;q=0.7', array('ISO-8859-1', 'utf-8', '*')),
|
||||
'order matters when q is equal' => array('*;q=0.3,ISO-8859-1;q=0.7,utf-8;q=0.7', array('ISO-8859-1', 'utf-8', '*')),
|
||||
'order matters when q is equal2' => array('*;q=0.3,utf-8;q=0.7,ISO-8859-1;q=0.7', array('utf-8', 'ISO-8859-1', '*')),
|
||||
);
|
||||
}
|
||||
}
|
93
vendor/symfony/http-foundation/Tests/ApacheRequestTest.php
vendored
Normal file
93
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 array(
|
||||
array(
|
||||
array(
|
||||
'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',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'REQUEST_URI' => '/foo/bar',
|
||||
'SCRIPT_NAME' => '/foo/app_dev.php',
|
||||
),
|
||||
'/foo/bar',
|
||||
'/foo',
|
||||
'/bar',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'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',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'REQUEST_URI' => '/foo/bar',
|
||||
'SCRIPT_NAME' => '/app_dev.php',
|
||||
),
|
||||
'/foo/bar',
|
||||
'',
|
||||
'/foo/bar',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'REQUEST_URI' => '/app_dev.php',
|
||||
'SCRIPT_NAME' => '/app_dev.php',
|
||||
),
|
||||
'/app_dev.php',
|
||||
'/app_dev.php',
|
||||
'/',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'REQUEST_URI' => '/',
|
||||
'SCRIPT_NAME' => '/app_dev.php',
|
||||
),
|
||||
'/',
|
||||
'',
|
||||
'/',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
365
vendor/symfony/http-foundation/Tests/BinaryFileResponseTest.php
vendored
Normal file
365
vendor/symfony/http-foundation/Tests/BinaryFileResponseTest.php
vendored
Normal file
|
@ -0,0 +1,365 @@
|
|||
<?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, array('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, array(), 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, array(), true, 'attachment');
|
||||
|
||||
@unlink(sys_get_temp_dir().'/fööö.html');
|
||||
|
||||
$this->assertSame('fööö.html', $response->getFile()->getFilename());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testSetContent()
|
||||
{
|
||||
$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, array('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($length, $response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideRanges
|
||||
*/
|
||||
public function testRequestsWithoutEtag($requestRange, $offset, $length, $responseRange)
|
||||
{
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('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 array(
|
||||
array('bytes=1-4', 1, 4, 'bytes 1-4/35'),
|
||||
array('bytes=-5', 30, 5, 'bytes 30-34/35'),
|
||||
array('bytes=30-', 30, 5, 'bytes 30-34/35'),
|
||||
array('bytes=30-30', 30, 1, 'bytes 30-30/35'),
|
||||
array('bytes=30-34', 30, 5, 'bytes 30-34/35'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testRangeRequestsWithoutLastModifiedDate()
|
||||
{
|
||||
// prevent auto last modified
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('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, array('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 array(
|
||||
array('bytes=0-'),
|
||||
array('bytes=0-34'),
|
||||
array('bytes=-35'),
|
||||
// Syntactical invalid range-request should also return the full resource
|
||||
array('bytes=20-10'),
|
||||
array('bytes=50-40'),
|
||||
);
|
||||
}
|
||||
|
||||
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, array('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 array(
|
||||
array('bytes=-40'),
|
||||
array('bytes=30-40'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideXSendfileFiles
|
||||
*/
|
||||
public function testXSendfile($file)
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('X-Sendfile-Type', 'X-Sendfile');
|
||||
|
||||
BinaryFileResponse::trustXSendfileTypeHeader();
|
||||
$response = BinaryFileResponse::create($file, 200, array('Content-Type' => 'application/octet-stream'));
|
||||
$response->prepare($request);
|
||||
|
||||
$this->expectOutputString('');
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertContains('README.md', $response->headers->get('X-Sendfile'));
|
||||
}
|
||||
|
||||
public function provideXSendfileFiles()
|
||||
{
|
||||
return array(
|
||||
array(__DIR__.'/../README.md'),
|
||||
array('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, array('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, array('Content-Type' => 'application/octet-stream'));
|
||||
$response->deleteFileAfterSend(true);
|
||||
|
||||
$response->prepare($request);
|
||||
$response->sendContent();
|
||||
|
||||
$this->assertFileNotExists($path);
|
||||
}
|
||||
|
||||
public function testAcceptRangeOnUnsafeMethods()
|
||||
{
|
||||
$request = Request::create('/', 'POST');
|
||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('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, array('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 array(
|
||||
array('/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'),
|
||||
array('/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testStream()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$response = new BinaryFileResponse(new Stream(__DIR__.'/../README.md'), 200, array('Content-Type' => 'text/plain'));
|
||||
$response->prepare($request);
|
||||
|
||||
$this->assertNull($response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
protected function provideResponse()
|
||||
{
|
||||
return new BinaryFileResponse(__DIR__.'/../README.md', 200, array('Content-Type' => 'application/octet-stream'));
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
$path = __DIR__.'/../Fixtures/to_delete';
|
||||
if (file_exists($path)) {
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
}
|
235
vendor/symfony/http-foundation/Tests/CookieTest.php
vendored
Normal file
235
vendor/symfony/http-foundation/Tests/CookieTest.php
vendored
Normal file
|
@ -0,0 +1,235 @@
|
|||
<?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 invalidNames()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(',MyName'),
|
||||
array(';MyName'),
|
||||
array(' MyName'),
|
||||
array("\tMyName"),
|
||||
array("\rMyName"),
|
||||
array("\nMyName"),
|
||||
array("\013MyName"),
|
||||
array("\014MyName"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidNames
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInstantiationThrowsExceptionIfCookieNameContainsInvalidCharacters($name)
|
||||
{
|
||||
new Cookie($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidExpiration()
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.5
|
||||
*/
|
||||
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->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date', 1);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
69
vendor/symfony/http-foundation/Tests/ExpressionRequestMatcherTest.php
vendored
Normal file
69
vendor/symfony/http-foundation/Tests/ExpressionRequestMatcherTest.php
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?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
|
||||
{
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testWhenNoExpressionIsSet()
|
||||
{
|
||||
$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 array(
|
||||
array('request.getMethod() == method', true),
|
||||
array('request.getPathInfo() == path', true),
|
||||
array('request.getHost() == host', true),
|
||||
array('request.getClientIp() == ip', true),
|
||||
array('request.attributes.all() == attributes', true),
|
||||
array('request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', true),
|
||||
array('request.getMethod() != method', false),
|
||||
array('request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', false),
|
||||
);
|
||||
}
|
||||
}
|
45
vendor/symfony/http-foundation/Tests/File/FakeFile.php
vendored
Normal file
45
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
vendor/symfony/http-foundation/Tests/File/FileTest.php
vendored
Normal file
180
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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('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->assertFileNotExists($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->assertFileNotExists($path);
|
||||
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
|
||||
|
||||
@unlink($targetPath);
|
||||
}
|
||||
|
||||
public function getFilenameFixtures()
|
||||
{
|
||||
return array(
|
||||
array('original.gif', 'original.gif'),
|
||||
array('..\\..\\original.gif', 'original.gif'),
|
||||
array('../../original.gif', 'original.gif'),
|
||||
array('файлfile.gif', 'файлfile.gif'),
|
||||
array('..\\..\\файлfile.gif', 'файлfile.gif'),
|
||||
array('../../файл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->assertFileNotExists($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->assertFileNotExists($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))
|
||||
->will($this->returnValue($mimeType))
|
||||
;
|
||||
|
||||
return $guesser;
|
||||
}
|
||||
}
|
1
vendor/symfony/http-foundation/Tests/File/Fixtures/.unknownextension
vendored
Normal file
1
vendor/symfony/http-foundation/Tests/File/Fixtures/.unknownextension
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
f
|
0
vendor/symfony/http-foundation/Tests/File/Fixtures/directory/.empty
vendored
Normal file
0
vendor/symfony/http-foundation/Tests/File/Fixtures/directory/.empty
vendored
Normal file
0
vendor/symfony/http-foundation/Tests/File/Fixtures/other-file.example
vendored
Normal file
0
vendor/symfony/http-foundation/Tests/File/Fixtures/other-file.example
vendored
Normal file
BIN
vendor/symfony/http-foundation/Tests/File/Fixtures/test
vendored
Normal file
BIN
vendor/symfony/http-foundation/Tests/File/Fixtures/test
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 B |
BIN
vendor/symfony/http-foundation/Tests/File/Fixtures/test.gif
vendored
Normal file
BIN
vendor/symfony/http-foundation/Tests/File/Fixtures/test.gif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 B |
90
vendor/symfony/http-foundation/Tests/File/MimeType/MimeTypeTest.php
vendored
Normal file
90
vendor/symfony/http-foundation/Tests/File/MimeType/MimeTypeTest.php
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?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
|
||||
{
|
||||
protected $path;
|
||||
|
||||
public function testGuessImageWithoutExtension()
|
||||
{
|
||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
||||
}
|
||||
|
||||
public function testGuessImageWithDirectory()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('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'));
|
||||
}
|
||||
|
||||
public function testGuessWithIncorrectPath()
|
||||
{
|
||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('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);
|
||||
}
|
||||
}
|
||||
}
|
273
vendor/symfony/http-foundation/Tests/File/UploadedFileTest.php
vendored
Normal file
273
vendor/symfony/http-foundation/Tests/File/UploadedFileTest.php
vendored
Normal file
|
@ -0,0 +1,273 @@
|
|||
<?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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('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/jpeg',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals('jpeg', $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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||
*/
|
||||
public function testMoveLocalFileIsNotAllowed()
|
||||
{
|
||||
$file = new UploadedFile(
|
||||
__DIR__.'/Fixtures/test.gif',
|
||||
'original.gif',
|
||||
'image/gif',
|
||||
filesize(__DIR__.'/Fixtures/test.gif'),
|
||||
UPLOAD_ERR_OK
|
||||
);
|
||||
|
||||
$movedFile = $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->assertFileNotExists($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 array(
|
||||
array(UPLOAD_ERR_INI_SIZE),
|
||||
array(UPLOAD_ERR_FORM_SIZE),
|
||||
array(UPLOAD_ERR_PARTIAL),
|
||||
array(UPLOAD_ERR_NO_TMP_DIR),
|
||||
array(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());
|
||||
}
|
||||
}
|
175
vendor/symfony/http-foundation/Tests/FileBagTest.php
vendored
Normal file
175
vendor/symfony/http-foundation/Tests/FileBagTest.php
vendored
Normal file
|
@ -0,0 +1,175 @@
|
|||
<?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
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testFileMustBeAnArrayOrUploadedFile()
|
||||
{
|
||||
new FileBag(array('file' => 'foo'));
|
||||
}
|
||||
|
||||
public function testShouldConvertsUploadedFiles()
|
||||
{
|
||||
$tmpFile = $this->createTempFile();
|
||||
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
||||
|
||||
$bag = new FileBag(array('file' => array(
|
||||
'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(array('file' => array(
|
||||
'name' => '',
|
||||
'type' => '',
|
||||
'tmp_name' => '',
|
||||
'error' => UPLOAD_ERR_NO_FILE,
|
||||
'size' => 0,
|
||||
)));
|
||||
|
||||
$this->assertNull($bag->get('file'));
|
||||
}
|
||||
|
||||
public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
|
||||
{
|
||||
$bag = new FileBag(array('files' => array(
|
||||
'name' => array(''),
|
||||
'type' => array(''),
|
||||
'tmp_name' => array(''),
|
||||
'error' => array(UPLOAD_ERR_NO_FILE),
|
||||
'size' => array(0),
|
||||
)));
|
||||
|
||||
$this->assertSame(array(), $bag->get('files'));
|
||||
}
|
||||
|
||||
public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray()
|
||||
{
|
||||
$bag = new FileBag(array('files' => array(
|
||||
'name' => array('file1' => ''),
|
||||
'type' => array('file1' => ''),
|
||||
'tmp_name' => array('file1' => ''),
|
||||
'error' => array('file1' => UPLOAD_ERR_NO_FILE),
|
||||
'size' => array('file1' => 0),
|
||||
)));
|
||||
|
||||
$this->assertSame(array('file1' => null), $bag->get('files'));
|
||||
}
|
||||
|
||||
public function testShouldConvertUploadedFilesWithPhpBug()
|
||||
{
|
||||
$tmpFile = $this->createTempFile();
|
||||
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
||||
|
||||
$bag = new FileBag(array(
|
||||
'child' => array(
|
||||
'name' => array(
|
||||
'file' => basename($tmpFile),
|
||||
),
|
||||
'type' => array(
|
||||
'file' => 'text/plain',
|
||||
),
|
||||
'tmp_name' => array(
|
||||
'file' => $tmpFile,
|
||||
),
|
||||
'error' => array(
|
||||
'file' => 0,
|
||||
),
|
||||
'size' => array(
|
||||
'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(array(
|
||||
'child' => array(
|
||||
'name' => array(
|
||||
'sub' => array('file' => basename($tmpFile)),
|
||||
),
|
||||
'type' => array(
|
||||
'sub' => array('file' => 'text/plain'),
|
||||
),
|
||||
'tmp_name' => array(
|
||||
'sub' => array('file' => $tmpFile),
|
||||
),
|
||||
'error' => array(
|
||||
'sub' => array('file' => 0),
|
||||
),
|
||||
'size' => array(
|
||||
'sub' => array('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(array('image' => array('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');
|
||||
}
|
||||
}
|
43
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/common.inc
vendored
Normal file
43
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 (ini_get('xdebug.default_enable')) {
|
||||
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;
|
11
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_max_age.expected
vendored
Normal file
11
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_max_age.expected
vendored
Normal file
|
@ -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
|
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_max_age.php
vendored
Normal file
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_max_age.php
vendored
Normal file
|
@ -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, '/');
|
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.expected
vendored
Normal file
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.expected
vendored
Normal file
|
@ -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
|
12
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.php
vendored
Normal file
12
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_raw_urlencode.php
vendored
Normal file
|
@ -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
|
8
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_samesite_lax.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_samesite_lax.php
vendored
Normal file
|
@ -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
|
8
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_samesite_strict.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_samesite_strict.php
vendored
Normal file
|
@ -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();
|
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_urlencode.expected
vendored
Normal file
10
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_urlencode.expected
vendored
Normal file
|
@ -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: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/
|
||||
[4] => Set-Cookie: ?*():@&+$/%#[]=%3F%2A%28%29%3A%40%26%2B%24%2F%25%23%5B%5D; path=/
|
||||
)
|
||||
shutdown
|
12
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_urlencode.php
vendored
Normal file
12
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/cookie_urlencode.php
vendored
Normal file
|
@ -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));
|
||||
$r->sendHeaders();
|
||||
|
||||
setcookie($str, $str, 0, '/');
|
|
@ -0,0 +1,6 @@
|
|||
The cookie name "Hello + world" contains invalid characters.
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
)
|
||||
shutdown
|
11
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/invalid_cookie_name.php
vendored
Normal file
11
vendor/symfony/http-foundation/Tests/Fixtures/response-functional/invalid_cookie_name.php
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\HttpFoundation\Cookie;
|
||||
|
||||
$r = require __DIR__.'/common.inc';
|
||||
|
||||
try {
|
||||
$r->headers->setCookie(new Cookie('Hello + world', 'hodor'));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
205
vendor/symfony/http-foundation/Tests/HeaderBagTest.php
vendored
Normal file
205
vendor/symfony/http-foundation/Tests/HeaderBagTest.php
vendored
Normal file
|
@ -0,0 +1,205 @@
|
|||
<?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(array('foo' => 'bar'));
|
||||
$this->assertTrue($bag->has('foo'));
|
||||
}
|
||||
|
||||
public function testToStringNull()
|
||||
{
|
||||
$bag = new HeaderBag();
|
||||
$this->assertEquals('', $bag->__toString());
|
||||
}
|
||||
|
||||
public function testToStringNotNull()
|
||||
{
|
||||
$bag = new HeaderBag(array('foo' => 'bar'));
|
||||
$this->assertEquals("Foo: bar\r\n", $bag->__toString());
|
||||
}
|
||||
|
||||
public function testKeys()
|
||||
{
|
||||
$bag = new HeaderBag(array('foo' => 'bar'));
|
||||
$keys = $bag->keys();
|
||||
$this->assertEquals('foo', $keys[0]);
|
||||
}
|
||||
|
||||
public function testGetDate()
|
||||
{
|
||||
$bag = new HeaderBag(array('foo' => 'Tue, 4 Sep 2012 20:00:00 +0200'));
|
||||
$headerDate = $bag->getDate('foo');
|
||||
$this->assertInstanceOf('DateTime', $headerDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGetDateException()
|
||||
{
|
||||
$bag = new HeaderBag(array('foo' => 'Tue'));
|
||||
$headerDate = $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(array('foo' => 'bar'));
|
||||
$this->assertEquals(array('foo' => array('bar')), $bag->all(), '->all() gets all the input');
|
||||
|
||||
$bag = new HeaderBag(array('FOO' => 'BAR'));
|
||||
$this->assertEquals(array('foo' => array('BAR')), $bag->all(), '->all() gets all the input key are lower case');
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$bag = new HeaderBag(array('foo' => 'bar'));
|
||||
|
||||
$bag->replace(array('NOPE' => 'BAR'));
|
||||
$this->assertEquals(array('nope' => array('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(array('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(array('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(array('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(array('bar', 'bor'), $bag->get('foo', 'nope', false), '->get return all values as array');
|
||||
}
|
||||
|
||||
public function testSetAssociativeArray()
|
||||
{
|
||||
$bag = new HeaderBag();
|
||||
$bag->set('foo', array('bad-assoc-index' => 'value'));
|
||||
$this->assertSame('value', $bag->get('foo'));
|
||||
$this->assertEquals(array('value'), $bag->get('foo', 'nope', false), 'assoc indices of multi-valued headers are ignored');
|
||||
}
|
||||
|
||||
public function testContains()
|
||||
{
|
||||
$bag = new HeaderBag(array('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(array('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(array('cache-control' => 'max-age="0"'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('max-age'));
|
||||
$this->assertEquals(0, $bag->getCacheControlDirective('max-age'));
|
||||
}
|
||||
|
||||
public function testCacheControlDirectiveOverrideWithReplace()
|
||||
{
|
||||
$bag = new HeaderBag(array('cache-control' => 'private, max-age=100'));
|
||||
$bag->replace(array('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 = array('foo' => 'bar');
|
||||
$bag1 = new HeaderBag($headers);
|
||||
$bag2 = new HeaderBag($bag1->all());
|
||||
|
||||
$this->assertEquals($bag1->all(), $bag2->all());
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$headers = array('foo' => 'bar', 'hello' => 'world', 'third' => 'charm');
|
||||
$headerBag = new HeaderBag($headers);
|
||||
|
||||
$i = 0;
|
||||
foreach ($headerBag as $key => $val) {
|
||||
++$i;
|
||||
$this->assertEquals(array($headers[$key]), $val);
|
||||
}
|
||||
|
||||
$this->assertEquals(\count($headers), $i);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$headers = array('foo' => 'bar', 'HELLO' => 'WORLD');
|
||||
$headerBag = new HeaderBag($headers);
|
||||
|
||||
$this->assertCount(\count($headers), $headerBag);
|
||||
}
|
||||
}
|
104
vendor/symfony/http-foundation/Tests/IpUtilsTest.php
vendored
Normal file
104
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 array(
|
||||
array(true, '192.168.1.1', '192.168.1.1'),
|
||||
array(true, '192.168.1.1', '192.168.1.1/1'),
|
||||
array(true, '192.168.1.1', '192.168.1.0/24'),
|
||||
array(false, '192.168.1.1', '1.2.3.4/1'),
|
||||
array(false, '192.168.1.1', '192.168.1.1/33'), // invalid subnet
|
||||
array(true, '192.168.1.1', array('1.2.3.4/1', '192.168.1.0/24')),
|
||||
array(true, '192.168.1.1', array('192.168.1.0/24', '1.2.3.4/1')),
|
||||
array(false, '192.168.1.1', array('1.2.3.4/1', '4.3.2.1/1')),
|
||||
array(true, '1.2.3.4', '0.0.0.0/0'),
|
||||
array(true, '1.2.3.4', '192.168.1.0/0'),
|
||||
array(false, '1.2.3.4', '256.256.256/0'), // invalid CIDR notation
|
||||
array(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 array(
|
||||
array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
|
||||
array(false, '2a00:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
|
||||
array(false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'),
|
||||
array(true, '0:0:0:0:0:0:0:1', '::1'),
|
||||
array(false, '0:0:603:0:396e:4789:8e99:0001', '::1'),
|
||||
array(true, '0:0:603:0:396e:4789:8e99:0001', '::/0'),
|
||||
array(true, '0:0:603:0:396e:4789:8e99:0001', '2a01:198:603:0::/0'),
|
||||
array(true, '2a01:198:603:0:396e:4789:8e99:890f', array('::1', '2a01:198:603:0::/65')),
|
||||
array(true, '2a01:198:603:0:396e:4789:8e99:890f', array('2a01:198:603:0::/65', '::1')),
|
||||
array(false, '2a01:198:603:0:396e:4789:8e99:890f', array('::1', '1a01:198:603:0::/65')),
|
||||
array(false, '}__test|O:21:"JDatabaseDriverMysqli":3:{s:2', '::1'),
|
||||
array(false, '2a01:198:603:0:396e:4789:8e99:890f', 'unknown'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @requires extension sockets
|
||||
*/
|
||||
public function testAnIpv6WithOptionDisabledIpv6()
|
||||
{
|
||||
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 array(
|
||||
'invalid proxy wildcard' => array('192.168.20.13', '*'),
|
||||
'invalid proxy missing netmask' => array('192.168.20.13', '0.0.0.0'),
|
||||
'invalid request IP with invalid proxy wildcard' => array('0.0.0.0', '*'),
|
||||
);
|
||||
}
|
||||
}
|
266
vendor/symfony/http-foundation/Tests/JsonResponseTest.php
vendored
Normal file
266
vendor/symfony/http-foundation/Tests/JsonResponseTest.php
vendored
Normal file
|
@ -0,0 +1,266 @@
|
|||
<?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(array(0, 1, 2, 3));
|
||||
$this->assertSame('[0,1,2,3]', $response->getContent());
|
||||
}
|
||||
|
||||
public function testConstructorWithAssocArrayCreatesJsonObject()
|
||||
{
|
||||
$response = new JsonResponse(array('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->assertSame('0.1', $response->getContent());
|
||||
|
||||
$response = new JsonResponse(true);
|
||||
$this->assertSame('true', $response->getContent());
|
||||
}
|
||||
|
||||
public function testConstructorWithCustomStatus()
|
||||
{
|
||||
$response = new JsonResponse(array(), 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(array(), 200, array('ETag' => 'foo'));
|
||||
$this->assertSame('application/json', $response->headers->get('Content-Type'));
|
||||
$this->assertSame('foo', $response->headers->get('ETag'));
|
||||
}
|
||||
|
||||
public function testConstructorWithCustomContentType()
|
||||
{
|
||||
$headers = array('Content-Type' => 'application/vnd.acme.blog-v1+json');
|
||||
|
||||
$response = new JsonResponse(array(), 200, $headers);
|
||||
$this->assertSame('application/vnd.acme.blog-v1+json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testSetJson()
|
||||
{
|
||||
$response = new JsonResponse('1', 200, array(), true);
|
||||
$this->assertEquals('1', $response->getContent());
|
||||
|
||||
$response = new JsonResponse('[1]', 200, array(), true);
|
||||
$this->assertEquals('[1]', $response->getContent());
|
||||
|
||||
$response = new JsonResponse(null, 200, array());
|
||||
$response->setJson('true');
|
||||
$this->assertEquals('true', $response->getContent());
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$response = JsonResponse::create(array('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(array(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(array('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->assertSame('0.1', $response->getContent());
|
||||
|
||||
$response = JsonResponse::create(true);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
|
||||
$this->assertSame('true', $response->getContent());
|
||||
}
|
||||
|
||||
public function testStaticCreateWithCustomStatus()
|
||||
{
|
||||
$response = JsonResponse::create(array(), 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(array(), 200, array('ETag' => 'foo'));
|
||||
$this->assertSame('application/json', $response->headers->get('Content-Type'));
|
||||
$this->assertSame('foo', $response->headers->get('ETag'));
|
||||
}
|
||||
|
||||
public function testStaticCreateWithCustomContentType()
|
||||
{
|
||||
$headers = array('Content-Type' => 'application/vnd.acme.blog-v1+json');
|
||||
|
||||
$response = JsonResponse::create(array(), 200, $headers);
|
||||
$this->assertSame('application/vnd.acme.blog-v1+json', $response->headers->get('Content-Type'));
|
||||
}
|
||||
|
||||
public function testSetCallback()
|
||||
{
|
||||
$response = JsonResponse::create(array('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(array(array(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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testSetCallbackInvalidIdentifier()
|
||||
{
|
||||
$response = new JsonResponse('foo');
|
||||
$response->setCallback('+invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testSetContent()
|
||||
{
|
||||
JsonResponse::create("\xB1\x31");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessage This error is expected
|
||||
*/
|
||||
public function testSetContentJsonSerializeError()
|
||||
{
|
||||
if (!interface_exists('JsonSerializable', false)) {
|
||||
$this->markTestSkipped('JsonSerializable is required.');
|
||||
}
|
||||
|
||||
$serializable = new JsonSerializableObject();
|
||||
|
||||
JsonResponse::create($serializable);
|
||||
}
|
||||
|
||||
public function testSetComplexCallback()
|
||||
{
|
||||
$response = JsonResponse::create(array('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
vendor/symfony/http-foundation/Tests/ParameterBagTest.php
vendored
Normal file
194
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(array('foo' => 'bar'));
|
||||
$this->assertEquals(array('foo' => 'bar'), $bag->all(), '->all() gets all the input');
|
||||
}
|
||||
|
||||
public function testKeys()
|
||||
{
|
||||
$bag = new ParameterBag(array('foo' => 'bar'));
|
||||
$this->assertEquals(array('foo'), $bag->keys());
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$bag = new ParameterBag(array('foo' => 'bar'));
|
||||
$bag->add(array('bar' => 'bas'));
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'bas'), $bag->all());
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$bag = new ParameterBag(array('foo' => 'bar'));
|
||||
$bag->add(array('bar' => 'bas'));
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'bas'), $bag->all());
|
||||
$bag->remove('bar');
|
||||
$this->assertEquals(array('foo' => 'bar'), $bag->all());
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$bag = new ParameterBag(array('foo' => 'bar'));
|
||||
|
||||
$bag->replace(array('FOO' => 'BAR'));
|
||||
$this->assertEquals(array('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(array('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(array('foo' => array('bar' => 'moo')));
|
||||
|
||||
$this->assertNull($bag->get('foo[bar]'));
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$bag = new ParameterBag(array());
|
||||
|
||||
$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(array('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(array('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(array('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(array('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(array('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(array(
|
||||
'digits' => '0123ab',
|
||||
'email' => 'example@example.com',
|
||||
'url' => 'http://example.com/foo',
|
||||
'dec' => '256',
|
||||
'hex' => '0x100',
|
||||
'array' => 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, array('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, array(
|
||||
'flags' => FILTER_FLAG_ALLOW_HEX,
|
||||
'options' => array('min_range' => 1, 'max_range' => 0xff),
|
||||
)), '->filter() gets a value of parameter as integer between boundaries');
|
||||
|
||||
$this->assertFalse($bag->filter('hex', '', FILTER_VALIDATE_INT, array(
|
||||
'flags' => FILTER_FLAG_ALLOW_HEX,
|
||||
'options' => array('min_range' => 1, 'max_range' => 0xff),
|
||||
)), '->filter() gets a value of parameter as integer between boundaries');
|
||||
|
||||
$this->assertEquals(array('bang'), $bag->filter('array', ''), '->filter() gets a value of parameter as an array');
|
||||
}
|
||||
|
||||
public function testGetIterator()
|
||||
{
|
||||
$parameters = array('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 = array('foo' => 'bar', 'hello' => 'world');
|
||||
$bag = new ParameterBag($parameters);
|
||||
|
||||
$this->assertCount(\count($parameters), $bag);
|
||||
}
|
||||
|
||||
public function testGetBoolean()
|
||||
{
|
||||
$parameters = array('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');
|
||||
}
|
||||
}
|
97
vendor/symfony/http-foundation/Tests/RedirectResponseTest.php
vendored
Normal file
97
vendor/symfony/http-foundation/Tests/RedirectResponseTest.php
vendored
Normal file
|
@ -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;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
class RedirectResponseTest extends TestCase
|
||||
{
|
||||
public function testGenerateMetaRedirect()
|
||||
{
|
||||
$response = new RedirectResponse('foo.bar');
|
||||
|
||||
$this->assertEquals(1, preg_match(
|
||||
'#<meta http-equiv="refresh" content="\d+;url=foo\.bar" />#',
|
||||
preg_replace(array('/\s+/', '/\'/'), array(' ', '"'), $response->getContent())
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testRedirectResponseConstructorNullUrl()
|
||||
{
|
||||
$response = new RedirectResponse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testRedirectResponseConstructorWrongStatusCode()
|
||||
{
|
||||
$response = 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testSetTargetUrlNull()
|
||||
{
|
||||
$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, array('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
vendor/symfony/http-foundation/Tests/RequestMatcherTest.php
vendored
Normal file
151
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 array(
|
||||
array('get', 'get', true),
|
||||
array('get', array('get', 'post'), true),
|
||||
array('get', 'post', false),
|
||||
array('get', 'GET', true),
|
||||
array('get', array('GET', 'POST'), true),
|
||||
array('get', 'POST', false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testScheme()
|
||||
{
|
||||
$httpRequest = $request = $request = Request::create('');
|
||||
$httpsRequest = $request = $request = Request::create('', 'get', array(), array(), array(), array('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', array(), array(), array(), array('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 array(
|
||||
array('.*\.example\.com', true),
|
||||
array('\.example\.com$', true),
|
||||
array('^.*\.example\.com$', true),
|
||||
array('.*\.sensio\.com', false),
|
||||
array('.*\.example\.COM', true),
|
||||
array('\.example\.COM$', true),
|
||||
array('^.*\.example\.COM$', true),
|
||||
array('.*\.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
vendor/symfony/http-foundation/Tests/RequestStackTest.php
vendored
Normal file
70
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());
|
||||
}
|
||||
}
|
2345
vendor/symfony/http-foundation/Tests/RequestTest.php
vendored
Normal file
2345
vendor/symfony/http-foundation/Tests/RequestTest.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
58
vendor/symfony/http-foundation/Tests/ResponseFunctionalTest.php
vendored
Normal file
58
vendor/symfony/http-foundation/Tests/ResponseFunctionalTest.php
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?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 = array(
|
||||
1 => array('file', '/dev/null', 'w'),
|
||||
2 => array('file', '/dev/null', 'w'),
|
||||
);
|
||||
if (!self::$server = @proc_open('exec php -S localhost:8054', $spec, $pipes, __DIR__.'/Fixtures/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)
|
||||
{
|
||||
$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 array(pathinfo($file, PATHINFO_FILENAME));
|
||||
}
|
||||
}
|
||||
}
|
363
vendor/symfony/http-foundation/Tests/ResponseHeaderBagTest.php
vendored
Normal file
363
vendor/symfony/http-foundation/Tests/ResponseHeaderBagTest.php
vendored
Normal file
|
@ -0,0 +1,363 @@
|
|||
<?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 = array(
|
||||
'fOo' => 'BAR',
|
||||
'ETag' => 'xyzzy',
|
||||
'Content-MD5' => 'Q2hlY2sgSW50ZWdyaXR5IQ==',
|
||||
'P3P' => 'CP="CAO PSA OUR"',
|
||||
'WWW-Authenticate' => 'Basic realm="WallyWorld"',
|
||||
'X-UA-Compatible' => 'IE=edge,chrome=1',
|
||||
'X-XSS-Protection' => '1; mode=block',
|
||||
);
|
||||
|
||||
$bag = new ResponseHeaderBag($headers);
|
||||
$allPreservedCase = $bag->allPreserveCase();
|
||||
|
||||
foreach (array_keys($headers) as $headerName) {
|
||||
$this->assertArrayHasKey($headerName, $allPreservedCase, '->allPreserveCase() gets all input keys in original case');
|
||||
}
|
||||
}
|
||||
|
||||
public function testCacheControlHeader()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('Cache-Control' => 'public'));
|
||||
$this->assertEquals('public', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('ETag' => 'abcde'));
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('private'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('must-revalidate'));
|
||||
$this->assertFalse($bag->hasCacheControlDirective('max-age'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('Expires' => 'Wed, 16 Feb 2011 14:17:43 GMT'));
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array(
|
||||
'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(array('Last-Modified' => 'abcde'));
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('Etag' => 'abcde', 'Last-Modified' => 'abcde'));
|
||||
$this->assertEquals('private, must-revalidate', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('cache-control' => 'max-age=100'));
|
||||
$this->assertEquals('max-age=100, private', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('cache-control' => 's-maxage=100'));
|
||||
$this->assertEquals('s-maxage=100', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('cache-control' => 'private, max-age=100'));
|
||||
$this->assertEquals('max-age=100, private', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag(array('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', array('public', 'must-revalidate'));
|
||||
$this->assertCount(1, $bag->get('Cache-Control', null, false));
|
||||
$this->assertEquals('must-revalidate, public', $bag->get('Cache-Control'));
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->set('Cache-Control', 'public');
|
||||
$bag->set('Cache-Control', 'must-revalidate', false);
|
||||
$this->assertCount(1, $bag->get('Cache-Control', null, false));
|
||||
$this->assertEquals('must-revalidate, public', $bag->get('Cache-Control'));
|
||||
}
|
||||
|
||||
public function testCacheControlClone()
|
||||
{
|
||||
$headers = array('foo' => 'bar');
|
||||
$bag1 = new ResponseHeaderBag($headers);
|
||||
$bag2 = new ResponseHeaderBag($bag1->allPreserveCase());
|
||||
$this->assertEquals($bag1->allPreserveCase(), $bag2->allPreserveCase());
|
||||
}
|
||||
|
||||
public function testToStringIncludesCookieHeaders()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$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(array());
|
||||
|
||||
$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 testReplace()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag->replace(array('Cache-Control' => 'public'));
|
||||
$this->assertEquals('public', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('public'));
|
||||
}
|
||||
|
||||
public function testReplaceWithRemove()
|
||||
{
|
||||
$bag = new ResponseHeaderBag(array());
|
||||
$this->assertEquals('no-cache, private', $bag->get('Cache-Control'));
|
||||
$this->assertTrue($bag->hasCacheControlDirective('no-cache'));
|
||||
|
||||
$bag->remove('Cache-Control');
|
||||
$bag->replace(array());
|
||||
$this->assertEquals('no-cache, 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(array(
|
||||
'foo=bar; path=/path/foo; domain=foo.bar; httponly',
|
||||
'foo=bar; path=/path/bar; domain=foo.bar; httponly',
|
||||
'foo=bar; path=/path/bar; domain=bar.foo; httponly',
|
||||
'foo=bar; path=/; httponly',
|
||||
), $bag->get('set-cookie', null, false));
|
||||
|
||||
$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(array(new Cookie('foo', 'bar', 0, '/', null, false, false, true)), $bag->getCookies());
|
||||
|
||||
$bag->set('set-cookie', 'foo2=bar2', false);
|
||||
$this->assertEquals(array(
|
||||
new Cookie('foo', 'bar', 0, '/', null, false, false, true),
|
||||
new Cookie('foo2', 'bar2', 0, '/', null, false, false, true),
|
||||
), $bag->getCookies());
|
||||
|
||||
$bag->remove('set-cookie');
|
||||
$this->assertEquals(array(), $bag->getCookies());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testGetCookiesWithInvalidArgument()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
|
||||
$bag->getCookies('invalid_argument');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testMakeDispositionInvalidDisposition()
|
||||
{
|
||||
$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(array('http://www.symfony.com'), $allHeaders['Location']);
|
||||
$this->assertEquals(array('text/html'), $allHeaders['Content-type']);
|
||||
}
|
||||
|
||||
public function provideMakeDisposition()
|
||||
{
|
||||
return array(
|
||||
array('attachment', 'foo.html', 'foo.html', 'attachment; filename="foo.html"'),
|
||||
array('attachment', 'foo.html', '', 'attachment; filename="foo.html"'),
|
||||
array('attachment', 'foo bar.html', '', 'attachment; filename="foo bar.html"'),
|
||||
array('attachment', 'foo "bar".html', '', 'attachment; filename="foo \\"bar\\".html"'),
|
||||
array('attachment', 'foo%20bar.html', 'foo bar.html', 'attachment; filename="foo bar.html"; filename*=utf-8\'\'foo%2520bar.html'),
|
||||
array('attachment', 'föö.html', 'foo.html', 'attachment; filename="foo.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideMakeDispositionFail
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testMakeDispositionFail($disposition, $filename)
|
||||
{
|
||||
$headers = new ResponseHeaderBag();
|
||||
|
||||
$headers->makeDisposition($disposition, $filename);
|
||||
}
|
||||
|
||||
public function provideMakeDispositionFail()
|
||||
{
|
||||
return array(
|
||||
array('attachment', 'foo%20bar.html'),
|
||||
array('attachment', 'foo/bar.html'),
|
||||
array('attachment', '/foo.html'),
|
||||
array('attachment', 'foo\bar.html'),
|
||||
array('attachment', '\foo.html'),
|
||||
array('attachment', 'föö.html'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testDateHeaderAddedOnCreation()
|
||||
{
|
||||
$now = time();
|
||||
|
||||
$bag = new ResponseHeaderBag();
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
|
||||
$this->assertEquals($now, $bag->getDate('Date')->getTimestamp());
|
||||
}
|
||||
|
||||
public function testDateHeaderCanBeSetOnCreation()
|
||||
{
|
||||
$someDate = 'Thu, 23 Mar 2017 09:15:12 GMT';
|
||||
$bag = new ResponseHeaderBag(array('Date' => $someDate));
|
||||
|
||||
$this->assertEquals($someDate, $bag->get('Date'));
|
||||
}
|
||||
|
||||
public function testDateHeaderWillBeRecreatedWhenRemoved()
|
||||
{
|
||||
$someDate = 'Thu, 23 Mar 2017 09:15:12 GMT';
|
||||
$bag = new ResponseHeaderBag(array('Date' => $someDate));
|
||||
$bag->remove('Date');
|
||||
|
||||
// a (new) Date header is still present
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
$this->assertNotEquals($someDate, $bag->get('Date'));
|
||||
}
|
||||
|
||||
public function testDateHeaderWillBeRecreatedWhenHeadersAreReplaced()
|
||||
{
|
||||
$bag = new ResponseHeaderBag();
|
||||
$bag->replace(array());
|
||||
|
||||
$this->assertTrue($bag->has('Date'));
|
||||
}
|
||||
|
||||
private function assertSetCookieHeader($expected, ResponseHeaderBag $actual)
|
||||
{
|
||||
$this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
|
||||
}
|
||||
}
|
1013
vendor/symfony/http-foundation/Tests/ResponseTest.php
vendored
Normal file
1013
vendor/symfony/http-foundation/Tests/ResponseTest.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
89
vendor/symfony/http-foundation/Tests/ResponseTestCase.php
vendored
Normal file
89
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
vendor/symfony/http-foundation/Tests/ServerBagTest.php
vendored
Normal file
170
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 = array(
|
||||
'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(array(
|
||||
'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(array('PHP_AUTH_USER' => 'foo'));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => '',
|
||||
), $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpBasicAuthWithPhpCgi()
|
||||
{
|
||||
$bag = new ServerBag(array('HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:bar')));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => 'bar',
|
||||
), $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpBasicAuthWithPhpCgiBogus()
|
||||
{
|
||||
$bag = new ServerBag(array('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(array('REDIRECT_HTTP_AUTHORIZATION' => 'Basic '.base64_encode('username:pass:word')));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'AUTHORIZATION' => 'Basic '.base64_encode('username:pass:word'),
|
||||
'PHP_AUTH_USER' => 'username',
|
||||
'PHP_AUTH_PW' => 'pass:word',
|
||||
), $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testHttpBasicAuthWithPhpCgiEmptyPassword()
|
||||
{
|
||||
$bag = new ServerBag(array('HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:')));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'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(array('HTTP_AUTHORIZATION' => $digest));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'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(array('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(array('REDIRECT_HTTP_AUTHORIZATION' => $digest));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'AUTHORIZATION' => $digest,
|
||||
'PHP_AUTH_DIGEST' => $digest,
|
||||
), $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testOAuthBearerAuth()
|
||||
{
|
||||
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
|
||||
$bag = new ServerBag(array('HTTP_AUTHORIZATION' => $headerContent));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'AUTHORIZATION' => $headerContent,
|
||||
), $bag->getHeaders());
|
||||
}
|
||||
|
||||
public function testOAuthBearerAuthWithRedirect()
|
||||
{
|
||||
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
|
||||
$bag = new ServerBag(array('REDIRECT_HTTP_AUTHORIZATION' => $headerContent));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'AUTHORIZATION' => $headerContent,
|
||||
), $bag->getHeaders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/symfony/symfony/issues/17345
|
||||
*/
|
||||
public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet()
|
||||
{
|
||||
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
|
||||
$bag = new ServerBag(array('PHP_AUTH_USER' => 'foo', 'HTTP_AUTHORIZATION' => $headerContent));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'AUTHORIZATION' => $headerContent,
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => '',
|
||||
), $bag->getHeaders());
|
||||
}
|
||||
}
|
186
vendor/symfony/http-foundation/Tests/Session/Attribute/AttributeBagTest.php
vendored
Normal file
186
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 = array();
|
||||
|
||||
/**
|
||||
* @var AttributeBag
|
||||
*/
|
||||
private $bag;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->array = array(
|
||||
'hello' => 'world',
|
||||
'always' => 'be happy',
|
||||
'user.login' => 'drak',
|
||||
'csrf.token' => array(
|
||||
'a' => '1234',
|
||||
'b' => '4321',
|
||||
),
|
||||
'category' => array(
|
||||
'fishing' => array(
|
||||
'first' => 'cod',
|
||||
'second' => 'sole',
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->bag = new AttributeBag('_sf2');
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->bag = null;
|
||||
$this->array = array();
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$bag = new AttributeBag();
|
||||
$bag->initialize($this->array);
|
||||
$this->assertEquals($this->array, $bag->all());
|
||||
$array = 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();
|
||||
$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(array(), $this->bag->all());
|
||||
}
|
||||
|
||||
public function attributesProvider()
|
||||
{
|
||||
return array(
|
||||
array('hello', 'world', true),
|
||||
array('always', 'be happy', true),
|
||||
array('user.login', 'drak', true),
|
||||
array('csrf.token', array('a' => '1234', 'b' => '4321'), true),
|
||||
array('category', array('fishing' => array('first' => 'cod', 'second' => 'sole')), true),
|
||||
array('user2.login', null, false),
|
||||
array('never', null, false),
|
||||
array('bye', null, false),
|
||||
array('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);
|
||||
}
|
||||
}
|
204
vendor/symfony/http-foundation/Tests/Session/Attribute/NamespacedAttributeBagTest.php
vendored
Normal file
204
vendor/symfony/http-foundation/Tests/Session/Attribute/NamespacedAttributeBagTest.php
vendored
Normal file
|
@ -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 = array();
|
||||
|
||||
/**
|
||||
* @var NamespacedAttributeBag
|
||||
*/
|
||||
private $bag;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->array = array(
|
||||
'hello' => 'world',
|
||||
'always' => 'be happy',
|
||||
'user.login' => 'drak',
|
||||
'csrf.token' => array(
|
||||
'a' => '1234',
|
||||
'b' => '4321',
|
||||
),
|
||||
'category' => array(
|
||||
'fishing' => array(
|
||||
'first' => 'cod',
|
||||
'second' => 'sole',
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->bag = new NamespacedAttributeBag('_sf2', '/');
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->bag = null;
|
||||
$this->array = array();
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$bag = new NamespacedAttributeBag();
|
||||
$bag->initialize($this->array);
|
||||
$this->assertEquals($this->array, $this->bag->all());
|
||||
$array = 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();
|
||||
$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(array(), $this->bag->all());
|
||||
}
|
||||
|
||||
public function attributesProvider()
|
||||
{
|
||||
return array(
|
||||
array('hello', 'world', true),
|
||||
array('always', 'be happy', true),
|
||||
array('user.login', 'drak', true),
|
||||
array('csrf.token', array('a' => '1234', 'b' => '4321'), true),
|
||||
array('csrf.token/a', '1234', true),
|
||||
array('csrf.token/b', '4321', true),
|
||||
array('category', array('fishing' => array('first' => 'cod', 'second' => 'sole')), true),
|
||||
array('category/fishing', array('first' => 'cod', 'second' => 'sole'), true),
|
||||
array('category/fishing/missing/first', null, false),
|
||||
array('category/fishing/first', 'cod', true),
|
||||
array('category/fishing/second', 'sole', true),
|
||||
array('category/fishing/missing/second', null, false),
|
||||
array('user2.login', null, false),
|
||||
array('never', null, false),
|
||||
array('bye', null, false),
|
||||
array('bye/for/now', null, false),
|
||||
);
|
||||
}
|
||||
}
|
161
vendor/symfony/http-foundation/Tests/Session/Flash/AutoExpireFlashBagTest.php
vendored
Normal file
161
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 = array();
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->bag = new FlashBag();
|
||||
$this->array = array('new' => array('notice' => array('A previous flash message')));
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->bag = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$bag = new FlashBag();
|
||||
$array = array('new' => array('notice' => array('A previous flash message')));
|
||||
$bag->initialize($array);
|
||||
$this->assertEquals(array('A previous flash message'), $bag->peek('notice'));
|
||||
$array = array('new' => array(
|
||||
'notice' => array('Something else'),
|
||||
'error' => array('a'),
|
||||
));
|
||||
$bag->initialize($array);
|
||||
$this->assertEquals(array('Something else'), $bag->peek('notice'));
|
||||
$this->assertEquals(array('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(array(), $this->bag->peek('non_existing'));
|
||||
$this->assertEquals(array('default'), $this->bag->peek('non_existing', array('default')));
|
||||
$this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
|
||||
$this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->assertEquals(array('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(array('notice'), $this->bag->keys());
|
||||
}
|
||||
|
||||
public function testPeekAll()
|
||||
{
|
||||
$array = array(
|
||||
'new' => array(
|
||||
'notice' => 'Foo',
|
||||
'error' => 'Bar',
|
||||
),
|
||||
);
|
||||
|
||||
$this->bag->initialize($array);
|
||||
$this->assertEquals(array(
|
||||
'notice' => 'Foo',
|
||||
'error' => 'Bar',
|
||||
), $this->bag->peekAll()
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'notice' => 'Foo',
|
||||
'error' => 'Bar',
|
||||
), $this->bag->peekAll()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->assertEquals(array(), $this->bag->get('non_existing'));
|
||||
$this->assertEquals(array('default'), $this->bag->get('non_existing', array('default')));
|
||||
$this->assertEquals(array('A previous flash message'), $this->bag->get('notice'));
|
||||
$this->assertEquals(array(), $this->bag->get('notice'));
|
||||
}
|
||||
|
||||
public function testSetAll()
|
||||
{
|
||||
$this->bag->setAll(array('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(array(
|
||||
'notice' => array('A previous flash message'),
|
||||
), $this->bag->all()
|
||||
);
|
||||
|
||||
$this->assertEquals(array(), $this->bag->all());
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->assertEquals(array('notice' => array('A previous flash message')), $this->bag->clear());
|
||||
}
|
||||
|
||||
public function testDoNotRemoveTheNewFlashesWhenDisplayingTheExistingOnes()
|
||||
{
|
||||
$this->bag->add('success', 'Something');
|
||||
$this->bag->all();
|
||||
|
||||
$this->assertEquals(array('new' => array('success' => array('Something')), 'display' => array()), $this->array);
|
||||
}
|
||||
}
|
157
vendor/symfony/http-foundation/Tests/Session/Flash/FlashBagTest.php
vendored
Normal file
157
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 = array();
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->bag = new FlashBag();
|
||||
$this->array = array('notice' => array('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 = array('should' => array('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(array(), $this->bag->peek('non_existing'));
|
||||
$this->assertEquals(array('default'), $this->bag->peek('not_existing', array('default')));
|
||||
$this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
|
||||
$this->assertEquals(array('A previous flash message'), $this->bag->peek('notice'));
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$tab = array('bar' => 'baz');
|
||||
$this->bag->add('string_message', 'lorem');
|
||||
$this->bag->add('object_message', new \stdClass());
|
||||
$this->bag->add('array_message', $tab);
|
||||
|
||||
$this->assertEquals(array('lorem'), $this->bag->get('string_message'));
|
||||
$this->assertEquals(array(new \stdClass()), $this->bag->get('object_message'));
|
||||
$this->assertEquals(array($tab), $this->bag->get('array_message'));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->assertEquals(array(), $this->bag->get('non_existing'));
|
||||
$this->assertEquals(array('default'), $this->bag->get('not_existing', array('default')));
|
||||
$this->assertEquals(array('A previous flash message'), $this->bag->get('notice'));
|
||||
$this->assertEquals(array(), $this->bag->get('notice'));
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->bag->set('error', 'Bar');
|
||||
$this->assertEquals(array(
|
||||
'notice' => array('Foo'),
|
||||
'error' => array('Bar'), ), $this->bag->all()
|
||||
);
|
||||
|
||||
$this->assertEquals(array(), $this->bag->all());
|
||||
}
|
||||
|
||||
public function testSet()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->bag->set('notice', 'Bar');
|
||||
$this->assertEquals(array('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(array('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(array('unique_flash' => 'FooBar'));
|
||||
$this->assertFalse($this->bag->has('one_flash'));
|
||||
$this->assertFalse($this->bag->has('another_flash'));
|
||||
$this->assertSame(array('unique_flash' => 'FooBar'), $this->bag->all());
|
||||
$this->assertSame(array(), $this->bag->all());
|
||||
}
|
||||
|
||||
public function testPeekAll()
|
||||
{
|
||||
$this->bag->set('notice', 'Foo');
|
||||
$this->bag->set('error', 'Bar');
|
||||
$this->assertEquals(array(
|
||||
'notice' => array('Foo'),
|
||||
'error' => array('Bar'),
|
||||
), $this->bag->peekAll()
|
||||
);
|
||||
$this->assertTrue($this->bag->has('notice'));
|
||||
$this->assertTrue($this->bag->has('error'));
|
||||
$this->assertEquals(array(
|
||||
'notice' => array('Foo'),
|
||||
'error' => array('Bar'),
|
||||
), $this->bag->peekAll()
|
||||
);
|
||||
}
|
||||
}
|
263
vendor/symfony/http-foundation/Tests/Session/SessionTest.php
vendored
Normal file
263
vendor/symfony/http-foundation/Tests/Session/SessionTest.php
vendored
Normal file
|
@ -0,0 +1,263 @@
|
|||
<?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\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(array('happiness' => 'be good', 'symfony' => 'awesome'));
|
||||
$this->assertEquals(array('happiness' => 'be good', 'symfony' => 'awesome'), $this->session->all());
|
||||
$this->session->replace(array());
|
||||
$this->assertEquals(array(), $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(array(), $this->session->all());
|
||||
}
|
||||
|
||||
public function setProvider()
|
||||
{
|
||||
return array(
|
||||
array('foo', 'bar', array('foo' => 'bar')),
|
||||
array('foo.bar', 'too much beer', array('foo.bar' => 'too much beer')),
|
||||
array('great', 'symfony is great', array('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(array('hi.world' => 'have a nice day'), $this->session->all());
|
||||
}
|
||||
|
||||
public function testInvalidate()
|
||||
{
|
||||
$this->session->set('invalidate', 123);
|
||||
$this->session->invalidate();
|
||||
$this->assertEquals(array(), $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 = array('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());
|
||||
}
|
||||
}
|
61
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php
vendored
Normal file
61
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/AbstractSessionHandlerTest.php
vendored
Normal file
|
@ -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 = array(
|
||||
1 => array('file', '/dev/null', 'w'),
|
||||
2 => array('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 = array('http' => array('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 array(pathinfo($file, PATHINFO_FILENAME));
|
||||
}
|
||||
}
|
||||
}
|
151
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/common.inc
vendored
Normal file
151
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;
|
||||
}
|
||||
}
|
17
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.expected
vendored
Normal file
17
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.expected
vendored
Normal file
|
@ -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
|
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.php
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
unset($_SESSION['abc']);
|
14
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/read_only.expected
vendored
Normal file
14
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/read_only.expected
vendored
Normal file
|
@ -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
|
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/read_only.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/read_only.php
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
require __DIR__.'/common.inc';
|
||||
|
||||
session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
|
||||
session_start();
|
||||
|
||||
echo $_SESSION['abc'];
|
24
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/regenerate.expected
vendored
Normal file
24
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/regenerate.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
destroy
|
||||
doDestroy
|
||||
close
|
||||
open
|
||||
validateId
|
||||
read
|
||||
doRead: abc|i:123;
|
||||
read
|
||||
|
||||
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
|
10
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/regenerate.php
vendored
Normal file
10
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/regenerate.php
vendored
Normal file
|
@ -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); });
|
20
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/storage.expected
vendored
Normal file
20
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/storage.expected
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
open
|
||||
validateId
|
||||
read
|
||||
doRead:
|
||||
read
|
||||
Array
|
||||
(
|
||||
[0] => bar
|
||||
)
|
||||
$_SESSION is not empty
|
||||
write
|
||||
destroy
|
||||
close
|
||||
$_SESSION is not empty
|
||||
Array
|
||||
(
|
||||
[0] => Content-Type: text/plain; charset=utf-8
|
||||
[1] => Cache-Control: max-age=0, private, must-revalidate
|
||||
)
|
||||
shutdown
|
24
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/storage.php
vendored
Normal file
24
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/storage.php
vendored
Normal file
|
@ -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); });
|
15
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.expected
vendored
Normal file
15
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.expected
vendored
Normal file
|
@ -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
|
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.php
vendored
Normal file
8
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.php
vendored
Normal file
|
@ -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,24 @@
|
|||
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
|
||||
)
|
||||
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']);
|
135
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php
vendored
Normal file
135
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php
vendored
Normal file
|
@ -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,
|
||||
array('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))
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->write('id', 'data'));
|
||||
}
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->memcache
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with(self::PREFIX.'id')
|
||||
->will($this->returnValue(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 array(
|
||||
array(array('prefix' => 'session'), true),
|
||||
array(array('expiretime' => 100), true),
|
||||
array(array('prefix' => 'session', 'expiretime' => 200), true),
|
||||
array(array('expiretime' => 100, 'foo' => 'bar'), false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$method = new \ReflectionMethod($this->storage, 'getMemcache');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\Memcache', $method->invoke($this->storage));
|
||||
}
|
||||
}
|
139
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php
vendored
Normal file
139
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.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\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,
|
||||
array('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->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))
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertTrue($this->storage->write('id', 'data'));
|
||||
}
|
||||
|
||||
public function testDestroySession()
|
||||
{
|
||||
$this->memcached
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with(self::PREFIX.'id')
|
||||
->will($this->returnValue(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 array(
|
||||
array(array('prefix' => 'session'), true),
|
||||
array(array('expiretime' => 100), true),
|
||||
array(array('prefix' => 'session', 'expiretime' => 200), true),
|
||||
array(array('expiretime' => 100, 'foo' => 'bar'), false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$method = new \ReflectionMethod($this->storage, 'getMemcached');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$this->assertInstanceOf('\Memcached', $method->invoke($this->storage));
|
||||
}
|
||||
}
|
333
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php
vendored
Normal file
333
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,333 @@
|
|||
<?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\MongoDbSessionHandler;
|
||||
|
||||
/**
|
||||
* @author Markus Bachmann <markus.bachmann@bachi.biz>
|
||||
* @group time-sensitive
|
||||
* @group legacy
|
||||
*/
|
||||
class MongoDbSessionHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_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 = array(
|
||||
'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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructorShouldThrowExceptionForInvalidMongo()
|
||||
{
|
||||
new MongoDbSessionHandler(new \stdClass(), $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructorShouldThrowExceptionForMissingOptions()
|
||||
{
|
||||
new MongoDbSessionHandler($this->mongo, array());
|
||||
}
|
||||
|
||||
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'])
|
||||
->will($this->returnValue($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')
|
||||
->will($this->returnCallback(function ($criteria) use ($testTimeout) {
|
||||
$this->assertArrayHasKey($this->options['id_field'], $criteria);
|
||||
$this->assertEquals($criteria[$this->options['id_field']], 'foo');
|
||||
|
||||
$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 = array(
|
||||
$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'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$data = array();
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$this->assertEquals(array($this->options['id_field'] => 'foo'), $criteria);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals(array('upsert' => true), $options);
|
||||
} else {
|
||||
$this->assertEquals(array('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 = array(
|
||||
'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'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$data = array();
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
|
||||
$this->assertEquals(array($this->options['id_field'] => 'foo'), $criteria);
|
||||
|
||||
if (phpversion('mongodb')) {
|
||||
$this->assertEquals(array('upsert' => true), $options);
|
||||
} else {
|
||||
$this->assertEquals(array('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'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$data = array();
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'updateOne' : 'update';
|
||||
|
||||
$collection->expects($this->exactly(2))
|
||||
->method($methodName)
|
||||
->will($this->returnCallback(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'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'deleteOne' : 'remove';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->with(array($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'])
|
||||
->will($this->returnValue($collection));
|
||||
|
||||
$methodName = phpversion('mongodb') ? 'deleteMany' : 'remove';
|
||||
|
||||
$collection->expects($this->once())
|
||||
->method($methodName)
|
||||
->will($this->returnCallback(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;
|
||||
}
|
||||
}
|
77
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php
vendored
Normal file
77
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?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(array('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)
|
||||
{
|
||||
$handler = new NativeFileSessionHandler($savePath);
|
||||
$this->assertEquals($expectedSavePath, ini_get('session.save_path'));
|
||||
$this->assertTrue(is_dir(realpath($path)));
|
||||
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
public function savePathDataProvider()
|
||||
{
|
||||
$base = sys_get_temp_dir();
|
||||
|
||||
return array(
|
||||
array("$base/foo", "$base/foo", "$base/foo"),
|
||||
array("5;$base/foo", "5;$base/foo", "$base/foo"),
|
||||
array("5;0600;$base/foo", "5;0600;$base/foo", "$base/foo"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructException()
|
||||
{
|
||||
$handler = new NativeFileSessionHandler('something;invalid;with;too-many-args');
|
||||
}
|
||||
|
||||
public function testConstructDefault()
|
||||
{
|
||||
$path = ini_get('session.save_path');
|
||||
$storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
|
||||
|
||||
$this->assertEquals($path, ini_get('session.save_path'));
|
||||
}
|
||||
}
|
38
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php
vendored
Normal file
38
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php
vendored
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
59
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NullSessionHandlerTest.php
vendored
Normal file
59
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/NullSessionHandlerTest.php
vendored
Normal file
|
@ -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()
|
||||
{
|
||||
$storage = $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(array(), new NullSessionHandler());
|
||||
}
|
||||
}
|
411
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php
vendored
Normal file
411
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,411 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testWrongPdoErrMode()
|
||||
{
|
||||
$pdo = $this->getMemorySqlitePdo();
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
|
||||
|
||||
$storage = new PdoSessionHandler($pdo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testInexistentTable()
|
||||
{
|
||||
$storage = new PdoSessionHandler($this->getMemorySqlitePdo(), array('db_table' => 'inexistent_table'));
|
||||
$storage->open('', 'sid');
|
||||
$storage->read('id');
|
||||
$storage->write('id', 'data');
|
||||
$storage->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testCreateTableTwice()
|
||||
{
|
||||
$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')
|
||||
->will($this->returnValue(array(array($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 (ini_get('session.use_strict_mode')) {
|
||||
$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')
|
||||
->will($this->returnCallback(function () use (&$exception, $stream) {
|
||||
return $exception ? array(array($stream, 42, time())) : array();
|
||||
}));
|
||||
|
||||
$insertStmt->expects($this->once())->method('execute')
|
||||
->will($this->returnCallback(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);
|
||||
|
||||
$this->assertAttributeEquals($expectedDsn, 'dsn', $storage);
|
||||
|
||||
if (null !== $expectedUser) {
|
||||
$this->assertAttributeEquals($expectedUser, 'username', $storage);
|
||||
}
|
||||
|
||||
if (null !== $expectedPassword) {
|
||||
$this->assertAttributeEquals($expectedPassword, 'password', $storage);
|
||||
}
|
||||
}
|
||||
|
||||
public function provideUrlDsnPairs()
|
||||
{
|
||||
yield array('mysql://localhost/test', 'mysql:host=localhost;dbname=test;');
|
||||
yield array('mysql://localhost:56/test', 'mysql:host=localhost;port=56;dbname=test;');
|
||||
yield array('mysql2://root:pwd@localhost/test', 'mysql:host=localhost;dbname=test;', 'root', 'pwd');
|
||||
yield array('postgres://localhost/test', 'pgsql:host=localhost;dbname=test;');
|
||||
yield array('postgresql://localhost:5634/test', 'pgsql:host=localhost;port=5634;dbname=test;');
|
||||
yield array('postgres://root:pwd@localhost/test', 'pgsql:host=localhost;dbname=test;', 'root', 'pwd');
|
||||
yield 'sqlite relative path' => array('sqlite://localhost/tmp/test', 'sqlite:tmp/test');
|
||||
yield 'sqlite absolute path' => array('sqlite://localhost//tmp/test', 'sqlite:/tmp/test');
|
||||
yield 'sqlite relative path without host' => array('sqlite:///tmp/test', 'sqlite:tmp/test');
|
||||
yield 'sqlite absolute path without host' => array('sqlite3:////tmp/test', 'sqlite:/tmp/test');
|
||||
yield array('sqlite://localhost/:memory:', 'sqlite::memory:');
|
||||
yield array('mssql://localhost/test', 'sqlsrv:server=localhost;Database=test');
|
||||
yield array('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 = array())
|
||||
{
|
||||
return \is_callable($this->prepareResult)
|
||||
? \call_user_func($this->prepareResult, $statement, $driverOptions)
|
||||
: $this->prepareResult;
|
||||
}
|
||||
|
||||
public function beginTransaction()
|
||||
{
|
||||
}
|
||||
|
||||
public function rollBack()
|
||||
{
|
||||
}
|
||||
}
|
189
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php
vendored
Normal file
189
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/StrictSessionHandlerTest.php
vendored
Normal file
|
@ -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(array('id1'), array('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));
|
||||
}
|
||||
}
|
97
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/WriteCheckSessionHandlerTest.php
vendored
Normal file
97
vendor/symfony/http-foundation/Tests/Session/Storage/Handler/WriteCheckSessionHandlerTest.php
vendored
Normal file
|
@ -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()
|
||||
->will($this->returnValue(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')
|
||||
->will($this->returnValue(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')
|
||||
->will($this->returnValue('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')
|
||||
->will($this->returnValue('bar'))
|
||||
;
|
||||
|
||||
$wrappedSessionHandlerMock
|
||||
->expects($this->once())
|
||||
->method('write')
|
||||
->with('foo', 'baZZZ')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
|
||||
$this->assertTrue($writeCheckSessionHandler->write('foo', 'baZZZ'));
|
||||
}
|
||||
}
|
139
vendor/symfony/http-foundation/Tests/Session/Storage/MetadataBagTest.php
vendored
Normal file
139
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 = array();
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->bag = new MetadataBag();
|
||||
$this->array = array(MetadataBag::CREATED => 1234567, MetadataBag::UPDATED => 12345678, MetadataBag::LIFETIME => 0);
|
||||
$this->bag->initialize($this->array);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->array = array();
|
||||
$this->bag = null;
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testInitialize()
|
||||
{
|
||||
$sessionMetadata = array();
|
||||
|
||||
$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 = 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 = array(
|
||||
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 = array(
|
||||
MetadataBag::CREATED => $created,
|
||||
MetadataBag::UPDATED => $created,
|
||||
MetadataBag::LIFETIME => 1000,
|
||||
);
|
||||
$bag->initialize($sessionMetadata);
|
||||
|
||||
$this->assertEquals($timeStamp, $sessionMetadata[MetadataBag::UPDATED]);
|
||||
}
|
||||
}
|
131
vendor/symfony/http-foundation/Tests/Session/Storage/MockArraySessionStorageTest.php
vendored
Normal file
131
vendor/symfony/http-foundation/Tests/Session/Storage/MockArraySessionStorageTest.php
vendored
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?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 = array(
|
||||
$this->attributes->getStorageKey() => array('foo' => 'bar'),
|
||||
$this->flashes->getStorageKey() => array('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(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
|
||||
$this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->peekAll());
|
||||
|
||||
$id = $this->storage->getId();
|
||||
$this->storage->regenerate(true);
|
||||
$this->assertNotEquals($id, $this->storage->getId());
|
||||
$this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all());
|
||||
$this->assertEquals(array('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(array(), $this->storage->getBag('attributes')->all());
|
||||
$this->assertSame(array(), $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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testUnstartedSave()
|
||||
{
|
||||
$this->storage->save();
|
||||
}
|
||||
}
|
127
vendor/symfony/http-foundation/Tests/Session/Storage/MockFileSessionStorageTest.php
vendored
Normal file
127
vendor/symfony/http-foundation/Tests/Session/Storage/MockFileSessionStorageTest.php
vendored
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?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()
|
||||
{
|
||||
$this->sessionDir = null;
|
||||
$this->storage = null;
|
||||
array_map('unlink', glob($this->sessionDir.'/*.session'));
|
||||
if (is_dir($this->sessionDir)) {
|
||||
rmdir($this->sessionDir);
|
||||
}
|
||||
}
|
||||
|
||||
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(array('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');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testSaveWithoutStart()
|
||||
{
|
||||
$storage1 = $this->getStorage();
|
||||
$storage1->save();
|
||||
}
|
||||
|
||||
private function getStorage()
|
||||
{
|
||||
$storage = new MockFileSessionStorage($this->sessionDir);
|
||||
$storage->registerBag(new FlashBag());
|
||||
$storage->registerBag(new AttributeBag());
|
||||
|
||||
return $storage;
|
||||
}
|
||||
}
|
294
vendor/symfony/http-foundation/Tests/Session/Storage/NativeSessionStorageTest.php
vendored
Normal file
294
vendor/symfony/http-foundation/Tests/Session/Storage/NativeSessionStorageTest.php
vendored
Normal file
|
@ -0,0 +1,294 @@
|
|||
<?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().'/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 NativeSessionStorage
|
||||
*/
|
||||
protected function getStorage(array $options = array())
|
||||
{
|
||||
$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()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testRegisterBagException()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$storage->getBag('non_existing');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testRegisterBagForAStartedSessionThrowsException()
|
||||
{
|
||||
$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->assertInternalType('string', $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 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');
|
||||
|
||||
$storage = new NativeSessionStorage();
|
||||
$this->assertEquals('', ini_get('session.cache_limiter'));
|
||||
}
|
||||
|
||||
public function testExplicitSessionCacheLimiter()
|
||||
{
|
||||
$this->iniSet('session.cache_limiter', 'nocache');
|
||||
|
||||
$storage = new NativeSessionStorage(array('cache_limiter' => 'public'));
|
||||
$this->assertEquals('public', ini_get('session.cache_limiter'));
|
||||
}
|
||||
|
||||
public function testCookieOptions()
|
||||
{
|
||||
$options = array(
|
||||
'cookie_lifetime' => 123456,
|
||||
'cookie_path' => '/my/cookie/path',
|
||||
'cookie_domain' => 'symfony.example.com',
|
||||
'cookie_secure' => true,
|
||||
'cookie_httponly' => false,
|
||||
);
|
||||
|
||||
$this->getStorage($options);
|
||||
$temp = session_get_cookie_params();
|
||||
$gco = array();
|
||||
|
||||
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 = array(
|
||||
'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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testSetSaveHandlerException()
|
||||
{
|
||||
$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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testStarted()
|
||||
{
|
||||
$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(array(
|
||||
'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);
|
||||
}
|
||||
}
|
96
vendor/symfony/http-foundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php
vendored
Normal file
96
vendor/symfony/http-foundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php
vendored
Normal file
|
@ -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($_SESSION[$key], array('symfony' => 'greatness'));
|
||||
$this->assertEquals($_SESSION['drak'], 'loves symfony');
|
||||
$storage->clear();
|
||||
$this->assertEquals($_SESSION[$key], array());
|
||||
$this->assertEquals($_SESSION['drak'], 'loves symfony');
|
||||
}
|
||||
}
|
113
vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php
vendored
Normal file
113
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
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testNameException()
|
||||
{
|
||||
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
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testIdException()
|
||||
{
|
||||
session_start();
|
||||
$this->proxy->setId('foo');
|
||||
}
|
||||
}
|
38
vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/NativeProxyTest.php
vendored
Normal file
38
vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/NativeProxyTest.php
vendored
Normal file
|
@ -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());
|
||||
}
|
||||
}
|
157
vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php
vendored
Normal file
157
vendor/symfony/http-foundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.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\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')
|
||||
->will($this->returnValue(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')
|
||||
->will($this->returnValue(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')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
$this->proxy->close();
|
||||
$this->assertFalse($this->proxy->isActive());
|
||||
}
|
||||
|
||||
public function testCloseFalse()
|
||||
{
|
||||
$this->mock->expects($this->once())
|
||||
->method('close')
|
||||
->will($this->returnValue(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(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->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(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
|
||||
$mock->expects($this->once())
|
||||
->method('updateTimestamp');
|
||||
|
||||
$proxy = new SessionHandlerProxy($mock);
|
||||
$proxy->updateTimestamp('id', 'data');
|
||||
|
||||
$this->mock->expects($this->once())
|
||||
->method('write');
|
||||
|
||||
$this->proxy->updateTimestamp('id', 'data');
|
||||
}
|
||||
}
|
144
vendor/symfony/http-foundation/Tests/StreamedResponseTest.php
vendored
Normal file
144
vendor/symfony/http-foundation/Tests/StreamedResponseTest.php
vendored
Normal file
|
@ -0,0 +1,144 @@
|
|||
<?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, array('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, array('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, array('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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testSendContentWithNonCallable()
|
||||
{
|
||||
$response = new StreamedResponse(null);
|
||||
$response->sendContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testSetContent()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
31
vendor/symfony/http-foundation/Tests/schema/http-status-codes.rng
vendored
Normal file
31
vendor/symfony/http-foundation/Tests/schema/http-status-codes.rng
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version='1.0'?>
|
||||
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
|
||||
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
|
||||
ns="http://www.iana.org/assignments">
|
||||
|
||||
<include href="iana-registry.rng"/>
|
||||
|
||||
<start>
|
||||
<element name="registry">
|
||||
<ref name="registryMeta"/>
|
||||
<element name="registry">
|
||||
<ref name="registryMeta"/>
|
||||
<zeroOrMore>
|
||||
<element name="record">
|
||||
<optional>
|
||||
<attribute name="date"><ref name="genericDate"/></attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="updated"><ref name="genericDate"/></attribute>
|
||||
</optional>
|
||||
<element name="value"><ref name="genericRange"/></element>
|
||||
<element name="description"><text/></element>
|
||||
<ref name="references"/>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
</element>
|
||||
<ref name="people"/>
|
||||
</element>
|
||||
</start>
|
||||
|
||||
</grammar>
|
198
vendor/symfony/http-foundation/Tests/schema/iana-registry.rng
vendored
Normal file
198
vendor/symfony/http-foundation/Tests/schema/iana-registry.rng
vendored
Normal file
|
@ -0,0 +1,198 @@
|
|||
<?xml version='1.0'?>
|
||||
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
|
||||
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
|
||||
ns="http://www.iana.org/assignments">
|
||||
|
||||
<define name="registryMeta">
|
||||
<interleave>
|
||||
<attribute name="id"><data type="ID"/></attribute>
|
||||
<optional><element name="title"><ref name="text_with_references"/></element></optional>
|
||||
<optional><element name="created"><ref name="genericDate"/></element></optional>
|
||||
<optional><element name="updated"><data type="date"/></element></optional>
|
||||
<optional><element name="registration_rule"><ref
|
||||
name="text_with_references"/></element></optional>
|
||||
<optional><element name="expert"><text/></element></optional>
|
||||
<optional><element name="description"><ref name="text_with_references"/></element></optional>
|
||||
<zeroOrMore><element name="note"><ref name="text_with_references"/></element></zeroOrMore>
|
||||
<ref name="references"/>
|
||||
<optional><element name="hide"><empty/></element></optional>
|
||||
<zeroOrMore><element name="category"><text/></element></zeroOrMore>
|
||||
<zeroOrMore><ref name="range"/></zeroOrMore>
|
||||
<optional><ref name="file"/></optional>
|
||||
</interleave>
|
||||
</define>
|
||||
|
||||
<define name="range">
|
||||
<element name="range">
|
||||
<interleave>
|
||||
<element name="value"><text/></element>
|
||||
<optional><element name="hex"><text/></element></optional>
|
||||
<element name="registration_rule"><ref name="text_with_references"/></element>
|
||||
<optional><element name="note"><ref name="text_with_references"/></element></optional>
|
||||
<optional><ref name="xref"/></optional>
|
||||
</interleave>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="people">
|
||||
<element name="people">
|
||||
<zeroOrMore>
|
||||
<element name="person">
|
||||
<attribute name="id"><data type="ID"/></attribute>
|
||||
<optional><element name="name"><text/></element></optional>
|
||||
<optional><element name="org"><text/></element></optional>
|
||||
<zeroOrMore><element name="uri"><data type="anyURI"/></element></zeroOrMore>
|
||||
<optional><element name="updated"><ref name="genericDate"/></element></optional>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="xref">
|
||||
<element name="xref">
|
||||
<optional>
|
||||
<attribute name="lastupdated"><ref name="genericDate"/></attribute>
|
||||
</optional>
|
||||
<choice>
|
||||
<group>
|
||||
<attribute name="type"><value>uri</value></attribute>
|
||||
<attribute name="data"><data type="anyURI"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>rfc</value></attribute>
|
||||
<attribute name="data">
|
||||
<data type="string">
|
||||
<param name="pattern">(rfc|bcp|std)\d+</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>rfc-errata</value></attribute>
|
||||
<attribute name="data"><data type="positiveInteger"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>draft</value></attribute>
|
||||
<attribute name="data">
|
||||
<data type="string">
|
||||
<param name="pattern">(draft|RFC)(-[a-zA-Z0-9]+)+</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>registry</value></attribute>
|
||||
<attribute name="data"><data type="NCName"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>person</value></attribute>
|
||||
<attribute name="data"><data type="NCName"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>text</value></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>note</value></attribute>
|
||||
<attribute name="data"><data type="positiveInteger"/></attribute>
|
||||
</group>
|
||||
<group>
|
||||
<attribute name="type"><value>unicode</value></attribute>
|
||||
<attribute name="data">
|
||||
<data type="string">
|
||||
<param name="pattern">ucd\d+\.\d+\.\d+</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</group>
|
||||
</choice>
|
||||
<text/>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="references">
|
||||
<zeroOrMore>
|
||||
<ref name="xref"/>
|
||||
</zeroOrMore>
|
||||
</define>
|
||||
|
||||
<define name="text_with_references">
|
||||
<interleave>
|
||||
<zeroOrMore>
|
||||
<text/>
|
||||
<optional><ref name="xref"/></optional>
|
||||
</zeroOrMore>
|
||||
</interleave>
|
||||
</define>
|
||||
|
||||
<define name="richText">
|
||||
<zeroOrMore>
|
||||
<choice>
|
||||
<interleave>
|
||||
<ref name="text_with_references"/>
|
||||
<optional><element name="br"><empty/></element></optional>
|
||||
</interleave>
|
||||
<element name="paragraph">
|
||||
<interleave>
|
||||
<ref name="text_with_references"/>
|
||||
<optional><element name="br"><empty/></element></optional>
|
||||
</interleave>
|
||||
</element>
|
||||
<element name="artwork"><text/></element>
|
||||
</choice>
|
||||
</zeroOrMore>
|
||||
</define>
|
||||
|
||||
<define name="genericRange">
|
||||
<data type="string">
|
||||
<param name="pattern">(\d+|0x[\da-fA-F]+)(\s*-\s*(\d+|0x[\da-fA-F]+))?</param>
|
||||
</data>
|
||||
</define>
|
||||
|
||||
<define name="genericDate">
|
||||
<choice>
|
||||
<data type="date"/>
|
||||
<data type="gYearMonth"/>
|
||||
</choice>
|
||||
</define>
|
||||
|
||||
<define name="hex32">
|
||||
<data type="string">
|
||||
<param name="pattern">0x[0-9]{8}</param>
|
||||
</data>
|
||||
</define>
|
||||
|
||||
<define name="binary">
|
||||
<data type="string">
|
||||
<param name="pattern">[0-1]+</param>
|
||||
</data>
|
||||
</define>
|
||||
|
||||
<define name="footnotes">
|
||||
<zeroOrMore>
|
||||
<element name="footnote">
|
||||
<attribute name="anchor"><data type="positiveInteger"/></attribute>
|
||||
<interleave>
|
||||
<zeroOrMore>
|
||||
<text/>
|
||||
<optional><ref name="xref"/></optional>
|
||||
</zeroOrMore>
|
||||
</interleave>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
</define>
|
||||
|
||||
<define name="file">
|
||||
<element name="file">
|
||||
<attribute name="type">
|
||||
<choice>
|
||||
<value>legacy</value>
|
||||
<value>mib</value>
|
||||
<value>template</value>
|
||||
<value>json</value>
|
||||
</choice>
|
||||
</attribute>
|
||||
<optional>
|
||||
<attribute name="name"/>
|
||||
</optional>
|
||||
<data type="anyURI"/>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
</grammar>
|
Reference in a new issue