Skip to content

Commit

Permalink
Merge branch '2.3' into 2.7
Browse files Browse the repository at this point in the history
* 2.3:
  Windows and Intl fixes
  Add appveyor.yml for C.I. on Windows
  [travis] merge php: nightly and deps=high test-matrix lines
  [Security] Add missing docblock in PreAuthenticatedToken

Conflicts:
	.travis.yml
	src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
	src/Symfony/Component/HttpFoundation/JsonResponse.php
	src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php
  • Loading branch information
nicolas-grekas committed Aug 26, 2015
2 parents 4d341df + fd351e4 commit d002fb5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Request.php
Expand Up @@ -1852,9 +1852,9 @@ protected function prepareBaseUrl()
return $prefix;
}

if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(dirname($baseUrl), '/').'/')) {
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(dirname($baseUrl), '/'.DIRECTORY_SEPARATOR).'/')) {
// directory portion of $baseUrl matches
return rtrim($prefix, '/');
return rtrim($prefix, '/'.DIRECTORY_SEPARATOR);
}

$truncatedRequestUri = $requestUri;
Expand All @@ -1875,7 +1875,7 @@ protected function prepareBaseUrl()
$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
}

return rtrim($baseUrl, '/');
return rtrim($baseUrl, '/'.DIRECTORY_SEPARATOR);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions Tests/BinaryFileResponseTest.php
Expand Up @@ -54,7 +54,7 @@ public function testGetContent()
*/
public function testRequests($requestRange, $offset, $length, $responseRange)
{
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif')->setAutoEtag();
$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('/');
Expand Down Expand Up @@ -96,7 +96,7 @@ public function provideRanges()
*/
public function testFullFileRequests($requestRange)
{
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif')->setAutoEtag();
$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('/');
Expand Down Expand Up @@ -131,7 +131,7 @@ public function provideFullFileRanges()
*/
public function testInvalidRequests($requestRange)
{
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif')->setAutoEtag();
$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('/');
Expand Down Expand Up @@ -159,7 +159,7 @@ public function testXSendfile()
$request->headers->set('X-Sendfile-Type', 'X-Sendfile');

BinaryFileResponse::trustXSendfileTypeHeader();
$response = BinaryFileResponse::create(__DIR__.'/../README.md');
$response = BinaryFileResponse::create(__DIR__.'/../README.md', 200, array('Content-Type' => 'application/octet-stream'));
$response->prepare($request);

$this->expectOutputString('');
Expand All @@ -180,7 +180,7 @@ public function testXAccelMapping($realpath, $mapping, $virtual)
$file = new FakeFile($realpath, __DIR__.'/File/Fixtures/test');

BinaryFileResponse::trustXSendfileTypeHeader();
$response = new BinaryFileResponse($file);
$response = new BinaryFileResponse($file, 200, array('Content-Type' => 'application/octet-stream'));
$reflection = new \ReflectionObject($response);
$property = $reflection->getProperty('file');
$property->setAccessible(true);
Expand Down Expand Up @@ -211,7 +211,7 @@ public function testDeleteFileAfterSend()
public function testAcceptRangeOnUnsafeMethods()
{
$request = Request::create('/', 'POST');
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif');
$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'));
Expand All @@ -220,7 +220,7 @@ public function testAcceptRangeOnUnsafeMethods()
public function testAcceptRangeNotOverriden()
{
$request = Request::create('/', 'POST');
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif');
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('Content-Type' => 'application/octet-stream'));
$response->headers->set('Accept-Ranges', 'foo');
$response->prepare($request);

Expand All @@ -237,7 +237,7 @@ public function getSampleXAccelMappings()

protected function provideResponse()
{
return new BinaryFileResponse(__DIR__.'/../README.md');
return new BinaryFileResponse(__DIR__.'/../README.md', 200, array('Content-Type' => 'application/octet-stream'));
}

public static function tearDownAfterClass()
Expand Down
3 changes: 3 additions & 0 deletions Tests/File/FileTest.php
Expand Up @@ -45,6 +45,9 @@ public function testGuessExtensionIsBasedOnMimeType()
$this->assertEquals('gif', $file->guessExtension());
}

/**
* @requires extension fileinfo
*/
public function testGuessExtensionWithReset()
{
$file = new File(__DIR__.'/Fixtures/other-file.example');
Expand Down
31 changes: 9 additions & 22 deletions Tests/File/MimeType/MimeTypeTest.php
Expand Up @@ -14,17 +14,16 @@
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;

/**
* @requires extension fileinfo
*/
class MimeTypeTest extends \PHPUnit_Framework_TestCase
{
protected $path;

public function testGuessImageWithoutExtension()
{
if (extension_loaded('fileinfo')) {
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
} else {
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
}
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
}

public function testGuessImageWithDirectory()
Expand All @@ -38,29 +37,17 @@ public function testGuessImageWithFileBinaryMimeTypeGuesser()
{
$guesser = MimeTypeGuesser::getInstance();
$guesser->register(new FileBinaryMimeTypeGuesser());
if (extension_loaded('fileinfo')) {
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
} else {
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
}
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
}

public function testGuessImageWithKnownExtension()
{
if (extension_loaded('fileinfo')) {
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
} else {
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
}
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
}

public function testGuessFileWithUnknownExtension()
{
if (extension_loaded('fileinfo')) {
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
} else {
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
}
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
}

public function testGuessWithIncorrectPath()
Expand All @@ -75,15 +62,15 @@ public function testGuessWithNonReadablePath()
$this->markTestSkipped('Can not verify chmod operations on Windows');
}

if ('root' === get_current_user()) {
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 (get_current_user() != 'root' && substr(sprintf('%o', fileperms($path)), -4) == '0333') {
if (substr(sprintf('%o', fileperms($path)), -4) == '0333') {
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
MimeTypeGuesser::getInstance()->guess($path);
} else {
Expand Down

0 comments on commit d002fb5

Please sign in to comment.