$t->is($v->getMimeTypesFromCategory('non_existant_category'), ''); $t->fail('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist'); } $categories = $v->getOption('mime_categories'); $t->is($v->getMimeTypesFromCategory('web_images'), $categories['web_images'], '->getMimeTypesFromCategory() returns an array of mime types for a given category'); $v->setOption('mime_categories', array_merge($v->getOption('mime_categories'), array('text' => array('text/plain')))); $t->is($v->getMimeTypesFromCategory('text'), array('text/plain'), '->getMimeTypesFromCategory() returns an array of mime types for a given category'); // ->guessFromFileinfo() $t->diag('->guessFromFileinfo()'); if (!function_exists('finfo_open')) { $t->skip('finfo_open is not available', 2); } else { $v = new testValidatorFile(); $t->is($v->guessFromFileinfo($tmpDir . '/test.txt'), 'text/plain', '->guessFromFileinfo() guesses the type of a given file'); $t->is($v->guessFromFileinfo($tmpDir . '/foo.txt'), null, '->guessFromFileinfo() returns null if the file type is not guessable'); } // ->guessFromMimeContentType() $t->diag('->guessFromMimeContentType()'); if (!function_exists('mime_content_type')) { $t->skip('mime_content_type is not available', 2); } else { $v = new testValidatorFile(); $t->is($v->guessFromMimeContentType($tmpDir . '/test.txt'), 'text/plain', '->guessFromMimeContentType() guesses the type of a given file'); $t->is($v->guessFromMimeContentType($tmpDir . '/foo.txt'), null, '->guessFromMimeContentType() returns null if the file type is not guessable'); } // ->guessFromFileBinary() $t->diag('->guessFromFileBinary()'); $v = new testValidatorFile(); $t->is($v->guessFromFileBinary($tmpDir . '/test.txt'), 'text/plain', '->guessFromFileBinary() guesses the type of a given file');
$t->is($v->getMimeTypesFromCategory('non_existant_category'), ''); $t->fail('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist'); } $categories = $v->getOption('mime_categories'); $t->is($v->getMimeTypesFromCategory('web_images'), $categories['web_images'], '->getMimeTypesFromCategory() returns an array of mime types for a given category'); $v->setOption('mime_categories', array_merge($v->getOption('mime_categories'), array('text' => array('text/plain')))); $t->is($v->getMimeTypesFromCategory('text'), array('text/plain'), '->getMimeTypesFromCategory() returns an array of mime types for a given category'); // ->guessFromFileinfo() $t->diag('->guessFromFileinfo()'); if (!function_exists('finfo_open')) { $t->skip('finfo_open is not available', 2); } else { $v = new testValidatorFile(); $t->is($v->guessFromFileinfo($tmpDir . '/test.txt'), version_compare(PHP_VERSION, '5.3', '<') ? 'text/plain' : 'text/plain; charset=us-ascii', '->guessFromFileinfo() guesses the type of a given file'); $t->is($v->guessFromFileinfo($tmpDir . '/foo.txt'), null, '->guessFromFileinfo() returns null if the file type is not guessable'); } // ->guessFromMimeContentType() $t->diag('->guessFromMimeContentType()'); if (!function_exists('mime_content_type')) { $t->skip('mime_content_type is not available', 2); } else { $v = new testValidatorFile(); $t->is($v->guessFromMimeContentType($tmpDir . '/test.txt'), version_compare(PHP_VERSION, '5.3', '<') ? 'text/plain' : 'text/plain; charset=us-ascii', '->guessFromMimeContentType() guesses the type of a given file'); $t->is($v->guessFromMimeContentType($tmpDir . '/foo.txt'), null, '->guessFromMimeContentType() returns null if the file type is not guessable'); } // ->guessFromFileBinary() $t->diag('->guessFromFileBinary()'); $v = new testValidatorFile(); $t->is($v->guessFromFileBinary($tmpDir . '/test.txt'), 'text/plain', '->guessFromFileBinary() guesses the type of a given file');