Skip to content

Commit

Permalink
[zendframework#4431] Better mime_content_type behavior
Browse files Browse the repository at this point in the history
- Only skip if we're dealing with a zip type in the first place.
  • Loading branch information
weierophinney committed May 6, 2013
1 parent b96418d commit a149b1b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tests/ZendTest/Validator/File/IsCompressedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ public function basicBehaviorDataProvider()

// Sometimes mime_content_type() gives application/zip and sometimes
// application/x-zip ...
$allowed = array('application/zip', 'application/x-zip');
$expectedMimeType = mime_content_type($testFile);
$fileUpload = array(
'tmp_name' => $testFile,
'name' => basename($testFile),
'size' => 200,
'error' => 0,
'type' => $expectedMimeType,
'type' => in_array($expectedMimeType, $allowed) ? $expectedMimeType : 'application/zip',
);

return array(
// Options, isValid Param, Expected value
array(null, $fileUpload, true),
array('zip', $fileUpload, true),
array('test/notype', $fileUpload, false),
array(array('application/x-zip, application/zip, application/x-tar'), $fileUpload, true),
array('application/x-zip, application/zip, application/x-tar', $fileUpload, true),
array(array('application/x-zip', 'application/zip', 'application/x-tar'), $fileUpload, true),
array(array('zip', 'tar'), $fileUpload, true),
array(array('tar', 'arj'), $fileUpload, false),
Expand All @@ -85,8 +86,17 @@ function_exists('mime_content_type') && ini_get('mime_magic.magicfile') &&
/**
* Skip a test if mime_content_type returns buggy information
*/
protected function skipIfBuggyMimeContentType()
protected function skipIfBuggyMimeContentType($options)
{
if (!is_array($options)) {
$options = (array) $options;
}

if (!in_array('application/zip', $options)) {
// mime_content_type does not play a role; no need to skip
return;
}

// Sometimes mime_content_type() gives application/zip and sometimes
// application/x-zip ...
$expectedMimeType = mime_content_type(__DIR__ . '/_files/test.zip');
Expand All @@ -104,7 +114,7 @@ protected function skipIfBuggyMimeContentType()
public function testBasic($options, $isValidParam, $expected)
{
$this->skipIfNoFileInfoExtension();
$this->skipIfBuggyMimeContentType();
$this->skipIfBuggyMimeContentType($options);

$validator = new File\IsCompressed($options);
$validator->enableHeaderCheck();
Expand All @@ -124,7 +134,7 @@ public function testLegacy($options, $isValidParam, $expected)
}

$this->skipIfNoFileInfoExtension();
$this->skipIfBuggyMimeContentType();
$this->skipIfBuggyMimeContentType($options);

$validator = new File\IsCompressed($options);
$validator->enableHeaderCheck();
Expand Down

0 comments on commit a149b1b

Please sign in to comment.