From c8040024cb9c1d28b669568789c5dfacc0941f54 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 23 Oct 2013 18:36:11 +0200 Subject: [PATCH] [ticket/11912] Add tests for phpbb mimetype guesser PHPBB3-11912 --- tests/mimetype/fixtures/jpg | Bin 0 -> 519 bytes tests/mimetype/guesser_test.php | 83 +++++++++++++++++++++++++++ tests/mimetype/incorrect_guesser.php | 18 ++++++ tests/mimetype/null_guesser.php | 30 ++++++++++ 4 files changed, 131 insertions(+) create mode 100644 tests/mimetype/fixtures/jpg create mode 100644 tests/mimetype/guesser_test.php create mode 100644 tests/mimetype/incorrect_guesser.php create mode 100644 tests/mimetype/null_guesser.php diff --git a/tests/mimetype/fixtures/jpg b/tests/mimetype/fixtures/jpg new file mode 100644 index 0000000000000000000000000000000000000000..3cd5038e38a45d49127638da67a2faaa551fd32f GIT binary patch literal 519 zcmbu4yA1+C3`A#afi58MN>BhavH{WwXzE&_7DN$z5;`$nP9X8QB{(~?o;}Zg@*8Z| zZd;JVCK`Ul8a}q-2*=*=15yKm$`vG06a9!qsN%gO#`CW!{DPShVrl^QU7_rAw@^*& rav~2P{RWiGtO4=@1|z1qj~E1)m)%nu8b6vA=Zcd3Q|f_AVgTnmym`8t literal 0 HcmV?d00001 diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php new file mode 100644 index 0000000000..3728961460 --- /dev/null +++ b/tests/mimetype/guesser_test.php @@ -0,0 +1,83 @@ +guesser = new \phpbb\mimetype\guesser($guessers); + $this->path = dirname(__FILE__); + $this->jpg_file = $this->path . '/fixtures/jpg'; + } + + public function data_guess_files() + { + return array( + array('image/gif', 'gif'), + array('image/png', 'png'), + array('image/jpeg', 'jpg'), + array('image/tiff', 'tif'), + array('text/html', 'txt'), + array(false, 'foobar'), + ); + } + + /** + * @dataProvider data_guess_files + */ + public function test_guess_files($expected, $file) + { + $this->assertEquals($expected, $this->guesser->guess($this->path . '/../upload/fixture/' . $file)); + } + + public function test_file_not_readable() + { + @chmod($this->jpg_file, 0000); + if (is_readable($this->jpg_file)) + { + @chmod($this->jpg_file, 0644); + $this->markTestSkipped('is_readable always returns true if user is superuser or chmod does not work'); + } + $this->assertEquals(false, $this->guesser->guess($this->jpg_file)); + @chmod($this->jpg_file, 0644); + $this->assertEquals('image/jpeg', $this->guesser->guess($this->jpg_file)); + } + + public function test_null_guess() + { + $guesser = new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\null_guesser)); + $this->assertEquals('application/octet-stream', $guesser->guess($this->jpg_file)); + } + + public function data_incorrect_guessers() + { + return array( + array(array(new \phpbb\mimetype\incorrect_guesser)), + array(array(new \phpbb\mimetype\null_guesser(false))), + array(array()), + ); + } + + /** + * @dataProvider data_incorrect_guessers + * + * @expectedException \LogicException + */ + public function test_incorrect_guesser($guessers) + { + $guesser = new \phpbb\mimetype\guesser($guessers); + } +} diff --git a/tests/mimetype/incorrect_guesser.php b/tests/mimetype/incorrect_guesser.php new file mode 100644 index 0000000000..3939826faa --- /dev/null +++ b/tests/mimetype/incorrect_guesser.php @@ -0,0 +1,18 @@ +is_supported = $is_supported; + } + + public function is_supported() + { + return $this->is_supported; + } + + public function guess($file) + { + return null; + } +}