mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11912] Add tests for content_guesser
PHPBB3-11912
This commit is contained in:
parent
63945f3687
commit
f617aff182
1 changed files with 48 additions and 3 deletions
|
@ -7,20 +7,32 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\mimetype;
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/null_guesser.php';
|
require_once dirname(__FILE__) . '/null_guesser.php';
|
||||||
require_once dirname(__FILE__) . '/incorrect_guesser.php';
|
require_once dirname(__FILE__) . '/incorrect_guesser.php';
|
||||||
|
|
||||||
class phpbb_mimetype_guesser_test extends phpbb_test_case
|
function function_exists($name)
|
||||||
{
|
{
|
||||||
|
return guesser_test::$function_exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
class guesser_test extends \phpbb_test_case
|
||||||
|
{
|
||||||
|
public static $function_exists = true;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
global $phpbb_root_path;
|
||||||
|
|
||||||
$guessers = array(
|
$guessers = array(
|
||||||
new Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(),
|
new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(),
|
||||||
new Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(),
|
new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(),
|
||||||
);
|
);
|
||||||
$this->guesser = new \phpbb\mimetype\guesser($guessers);
|
$this->guesser = new \phpbb\mimetype\guesser($guessers);
|
||||||
$this->path = dirname(__FILE__);
|
$this->path = dirname(__FILE__);
|
||||||
$this->jpg_file = $this->path . '/fixtures/jpg';
|
$this->jpg_file = $this->path . '/fixtures/jpg';
|
||||||
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function data_guess_files()
|
public function data_guess_files()
|
||||||
|
@ -80,4 +92,37 @@ class phpbb_mimetype_guesser_test extends phpbb_test_case
|
||||||
{
|
{
|
||||||
$guesser = new \phpbb\mimetype\guesser($guessers);
|
$guesser = new \phpbb\mimetype\guesser($guessers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function data_content_guesser()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'image/jpeg',
|
||||||
|
'image/jpeg',
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'application/octet-stream',
|
||||||
|
'image/jpeg',
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data_content_guesser
|
||||||
|
*/
|
||||||
|
public function test_content_guesser($expected, $overload = false)
|
||||||
|
{
|
||||||
|
self::$function_exists = ($overload) ? false : true;
|
||||||
|
$guesser = new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\content_guesser($this->phpbb_root_path, new \phpbb\php\ini)));
|
||||||
|
$this->assertEquals($expected[0], $guesser->guess($this->jpg_file));
|
||||||
|
@copy($this->jpg_file, $this->jpg_file . '.jpg');
|
||||||
|
$this->assertEquals($expected[1], $guesser->guess($this->jpg_file . '.jpg'));
|
||||||
|
@unlink($this->jpg_file . '.jpg');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue