[Request] Fix getting mime type
This commit is contained in:
parent
d1cd442361
commit
f470c5605e
@ -943,13 +943,13 @@ class Request
|
||||
static protected function initializeFormats()
|
||||
{
|
||||
static::$formats = array(
|
||||
'txt' => 'text/plain',
|
||||
'txt' => array('text/plain'),
|
||||
'js' => array('application/javascript', 'application/x-javascript', 'text/javascript'),
|
||||
'css' => 'text/css',
|
||||
'css' => array('text/css'),
|
||||
'json' => array('application/json', 'application/x-json'),
|
||||
'xml' => array('text/xml', 'application/xml', 'application/x-xml'),
|
||||
'rdf' => 'application/rdf+xml',
|
||||
'atom' => 'application/atom+xml',
|
||||
'rdf' => array('application/rdf+xml'),
|
||||
'atom' => array('application/atom+xml'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1741,13 +1741,13 @@ class Request
|
||||
static protected function initializeFormats()
|
||||
{
|
||||
static::$formats = array(
|
||||
'txt' => 'text/plain',
|
||||
'txt' => array('text/plain'),
|
||||
'js' => array('application/javascript', 'application/x-javascript', 'text/javascript'),
|
||||
'css' => 'text/css',
|
||||
'css' => array('text/css'),
|
||||
'json' => array('application/json', 'application/x-json'),
|
||||
'xml' => array('text/xml', 'application/xml', 'application/x-xml'),
|
||||
'rdf' => 'application/rdf+xml',
|
||||
'atom' => 'application/atom+xml',
|
||||
'rdf' => array('application/rdf+xml'),
|
||||
'atom' => array('application/atom+xml'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -97,17 +97,41 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\HttpFoundation\Request::getFormat
|
||||
* @dataProvider getFormatToMimeTypeMapProvider
|
||||
*/
|
||||
public function testGetFormat()
|
||||
public function testGetFormatFromMimeType($format, $mimeTypes)
|
||||
{
|
||||
$request = new Request();
|
||||
foreach ($mimeTypes as $mime) {
|
||||
$this->assertEquals($format, $request->getFormat($mime));
|
||||
}
|
||||
|
||||
$this->assertNull($request->getFormat(null), '->getFormat() returns null when mime-type is null');
|
||||
$this->assertNull($request->getFormat('unexistant-mime-type'), '->getFormat() returns null when mime-type is unknown');
|
||||
$this->assertEquals('txt', $request->getFormat('text/plain'), '->getFormat() returns correct format when mime-type have one format only');
|
||||
$this->assertEquals('js', $request->getFormat('application/javascript'), '->getFormat() returns correct format when format have multiple mime-type (first)');
|
||||
$this->assertEquals('js', $request->getFormat('application/x-javascript'), '->getFormat() returns correct format when format have multiple mime-type');
|
||||
$this->assertEquals('js', $request->getFormat('text/javascript'), '->getFormat() returns correct format when format have multiple mime-type (last)');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\HttpFoundation\Request::getMimeType
|
||||
* @dataProvider getFormatToMimeTypeMapProvider
|
||||
*/
|
||||
public function testGetMimeTypeFromFormat($format, $mimeTypes)
|
||||
{
|
||||
if (!is_null($format)) {
|
||||
$request = new Request();
|
||||
$this->assertEquals($mimeTypes[0], $request->getMimeType($format));
|
||||
}
|
||||
}
|
||||
|
||||
public function getFormatToMimeTypeMapProvider()
|
||||
{
|
||||
return array(
|
||||
array(null, array(null, 'unexistant-mime-type')),
|
||||
array('txt', array('text/plain')),
|
||||
array('js', array('application/javascript', 'application/x-javascript', 'text/javascript')),
|
||||
array('css', array('text/css')),
|
||||
array('json', array('application/json', 'application/x-json')),
|
||||
array('xml', array('text/xml', 'application/xml', 'application/x-xml')),
|
||||
array('rdf', array('application/rdf+xml')),
|
||||
array('atom',array('application/atom+xml')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user