aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2014-05-02 16:54:24 +0200
committerNils Adermann <naderman@naderman.de>2014-05-02 16:54:24 +0200
commit1dd02b0a916f1cd7672ffc247f09c9b6d4598d7c (patch)
tree0e5e093c61b467af1ac6c5faacdea924a072d04a /tests
parente65c51e3cd6f8ecd0a811b2671a94fef3fcf9d83 (diff)
parent98aebabd73e0be202f91a31f3f689a8bccd01079 (diff)
downloadforums-1dd02b0a916f1cd7672ffc247f09c9b6d4598d7c.tar
forums-1dd02b0a916f1cd7672ffc247f09c9b6d4598d7c.tar.gz
forums-1dd02b0a916f1cd7672ffc247f09c9b6d4598d7c.tar.bz2
forums-1dd02b0a916f1cd7672ffc247f09c9b6d4598d7c.tar.xz
forums-1dd02b0a916f1cd7672ffc247f09c9b6d4598d7c.zip
Merge remote-tracking branch 'github-marc1706/ticket/12071' into develop-ascraeus
* github-marc1706/ticket/12071: [ticket/12071] Add test that covers not available fileinfo [ticket/12071] Get rid of unneeded cast to boolean in tests [ticket/12071] Skip tests that depend on fileinfo and fix expected results
Diffstat (limited to 'tests')
-rw-r--r--tests/mimetype/guesser_test.php41
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php
index 9f0371262b..7c58340a7a 100644
--- a/tests/mimetype/guesser_test.php
+++ b/tests/mimetype/guesser_test.php
@@ -19,7 +19,9 @@ function function_exists($name)
class guesser_test extends \phpbb_test_case
{
- public static $function_exists = true;
+ public static $function_exists = false;
+
+ protected $fileinfo_supported = false;
public function setUp()
{
@@ -28,7 +30,16 @@ class guesser_test extends \phpbb_test_case
$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,
);
+
+ // Check if any guesser except the extension_guesser is available
+ $this->fileinfo_supported = $guessers[0]->isSupported() | $guessers[1]->isSupported() | $guessers[3]->is_supported();
+
+ // Also create a guesser that emulates not having fileinfo available
+ $this->guesser_no_fileinfo = new \phpbb\mimetype\guesser(array($guessers[2]));
+
$this->guesser = new \phpbb\mimetype\guesser($guessers);
$this->path = dirname(__FILE__);
$this->jpg_file = $this->path . '/fixtures/jpg';
@@ -52,9 +63,32 @@ class guesser_test extends \phpbb_test_case
*/
public function test_guess_files($expected, $file)
{
+ // We will always get application/octet-stream as mimetype if only the
+ // extension guesser is supported
+ if (!$this->fileinfo_supported)
+ {
+ $this->markTestSkipped('Unable to run tests depending on fileinfo if it is not available');
+ }
$this->assertEquals($expected, $this->guesser->guess($this->path . '/../upload/fixture/' . $file));
}
+ public function data_guess_files_no_fileinfo()
+ {
+ return array(
+ array('application/octet-stream', 'gif'),
+ array('application/octet-stream', 'txt'),
+ array(false, 'foobar'),
+ );
+ }
+
+ /**
+ * @dataProvider data_guess_files_no_fileinfo
+ */
+ public function test_guess_files_no_fileinfo($expected, $file)
+ {
+ $this->assertEquals($expected, $this->guesser_no_fileinfo->guess($this->path . '/../upload/fixture/' . $file));
+ }
+
public function test_file_not_readable()
{
@chmod($this->jpg_file, 0000);
@@ -130,6 +164,11 @@ class guesser_test extends \phpbb_test_case
$supported = false;
self::$function_exists = !$overload;
+ if (!\function_exists('mime_content_type'))
+ {
+ $this->markTestSkipped('Emulating supported mime_content_type() when it is not supported will cause a fatal error');
+ }
+
// Cover possible LogicExceptions
foreach ($guessers as $cur_guesser)
{