mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-01 14:30:32 +02:00
Merge branch 'develop-ascraeus' into develop
* develop-ascraeus: [ticket/11148] Remove unneeded variable mimetype and use type octet-stream [ticket/11148] Change expected output with disallowed content in test [ticket/11148] Always use the output of the mimetype guesser in get_mimetype [ticket/11148] Get rid of extra line in mimetype guesser setter doc block [ticket/11148] Add missing parts to docblock of get_mimetype() method [ticket/11148] Default to application/octet-stream if no mimetype given [ticket/11148] Use mimetype guesser for uploaded avatars [ticket/11148] Pass mimetype guesser to upload_attachment() function [ticket/11148] Add mimetype guesser to filespec and fileupload class
This commit is contained in:
@@ -43,6 +43,14 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
|
||||
$phpEx
|
||||
);
|
||||
|
||||
$guessers = array(
|
||||
new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(),
|
||||
new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(),
|
||||
new \phpbb\mimetype\extension_guesser,
|
||||
new \phpbb\mimetype\content_guesser,
|
||||
);
|
||||
$guesser = new \phpbb\mimetype\guesser($guessers);
|
||||
|
||||
// $this->avatar_foobar will be needed later on
|
||||
$this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
|
||||
$this->avatar_foobar->expects($this->any())
|
||||
@@ -57,7 +65,14 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
|
||||
|
||||
foreach ($this->avatar_drivers() as $driver)
|
||||
{
|
||||
$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
|
||||
if ($driver !== 'upload')
|
||||
{
|
||||
$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
|
||||
}
|
||||
else
|
||||
{
|
||||
$cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $cache));
|
||||
}
|
||||
$cur_avatar->expects($this->any())
|
||||
->method('get_name')
|
||||
->will($this->returnValue('avatar.driver.' . $driver));
|
||||
|
@@ -109,9 +109,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case
|
||||
|
||||
$crawler = $this->upload_file('disallowed.jpg', 'image/jpeg');
|
||||
|
||||
// Hitting the UNABLE_GET_IMAGE_SIZE error means we passed the
|
||||
// Hitting the ATTACHED_IMAGE_NOT_IMAGE error means we passed the
|
||||
// DISALLOWED_CONTENT check
|
||||
$this->assertEquals($this->lang('UNABLE_GET_IMAGE_SIZE'), $crawler->filter('p.error')->text());
|
||||
$this->assertContains($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->text());
|
||||
}
|
||||
|
||||
public function test_too_large()
|
||||
|
@@ -65,6 +65,16 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy_2');
|
||||
}
|
||||
}
|
||||
|
||||
$guessers = array(
|
||||
new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(),
|
||||
new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(),
|
||||
new \phpbb\mimetype\content_guesser(),
|
||||
new \phpbb\mimetype\extension_guesser(),
|
||||
);
|
||||
$guessers[2]->set_priority(-2);
|
||||
$guessers[3]->set_priority(-2);
|
||||
$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers);
|
||||
}
|
||||
|
||||
private function get_filespec($override = array())
|
||||
@@ -78,7 +88,7 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
'error' => '',
|
||||
);
|
||||
|
||||
return new filespec(array_merge($upload_ary, $override), null);
|
||||
return new filespec(array_merge($upload_ary, $override), null, $this->mimetype_guesser);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
@@ -222,6 +232,9 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
array('png', 'image/png', true),
|
||||
array('tif', 'image/tif', true),
|
||||
array('txt', 'text/plain', false),
|
||||
array('jpg', 'application/octet-stream', false),
|
||||
array('gif', 'application/octetstream', false),
|
||||
array('png', 'application/mime', false),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -234,6 +247,30 @@ class phpbb_filespec_test extends phpbb_test_case
|
||||
$this->assertEquals($expected, $filespec->is_image());
|
||||
}
|
||||
|
||||
public function is_image_get_mimetype()
|
||||
{
|
||||
return array(
|
||||
array('gif', 'image/gif', true),
|
||||
array('jpg', 'image/jpg', true),
|
||||
array('png', 'image/png', true),
|
||||
array('tif', 'image/tif', true),
|
||||
array('txt', 'text/plain', false),
|
||||
array('jpg', 'application/octet-stream', true),
|
||||
array('gif', 'application/octetstream', true),
|
||||
array('png', 'application/mime', true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider is_image_get_mimetype
|
||||
*/
|
||||
public function test_is_image_get_mimetype($filename, $mimetype, $expected)
|
||||
{
|
||||
$filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype));
|
||||
$filespec->get_mimetype($this->path . $filename);
|
||||
$this->assertEquals($expected, $filespec->is_image());
|
||||
}
|
||||
|
||||
public function move_file_variables()
|
||||
{
|
||||
return array(
|
||||
|
Reference in New Issue
Block a user