diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-10-23 23:18:40 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-10-23 23:18:40 +0200 |
commit | f617aff182f5f291d5b7d0ff854abea12a04cb0b (patch) | |
tree | 70b7c654075605378a9d4c85933b1e985b1ced63 /tests | |
parent | 63945f3687f57fc341c6c28c7b8940805efa99b7 (diff) | |
download | forums-f617aff182f5f291d5b7d0ff854abea12a04cb0b.tar forums-f617aff182f5f291d5b7d0ff854abea12a04cb0b.tar.gz forums-f617aff182f5f291d5b7d0ff854abea12a04cb0b.tar.bz2 forums-f617aff182f5f291d5b7d0ff854abea12a04cb0b.tar.xz forums-f617aff182f5f291d5b7d0ff854abea12a04cb0b.zip |
[ticket/11912] Add tests for content_guesser
PHPBB3-11912
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mimetype/guesser_test.php | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php index 3728961460..6484606210 100644 --- a/tests/mimetype/guesser_test.php +++ b/tests/mimetype/guesser_test.php @@ -7,20 +7,32 @@ * */ +namespace phpbb\mimetype; + require_once dirname(__FILE__) . '/null_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() { + global $phpbb_root_path; + $guessers = array( - new Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(), - new Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(), + new \Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser(), + new \Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser(), ); $this->guesser = new \phpbb\mimetype\guesser($guessers); $this->path = dirname(__FILE__); $this->jpg_file = $this->path . '/fixtures/jpg'; + $this->phpbb_root_path = $phpbb_root_path; } public function data_guess_files() @@ -80,4 +92,37 @@ class phpbb_mimetype_guesser_test extends phpbb_test_case { $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'); + } } |