// ->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(); $mimeType = $v->guessFromMimeContentType($tmpDir . '/test.txt'); if (version_compare(PHP_VERSION, '5.3', '<') && false === $mimeType) { $t->skip('mime_content_type has some issue with php 5.2', 1); } else { $t->is($mimeType, '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->guessFromFileBinary($tmpDir . '/foo.txt'), null, '->guessFromFileBinary() returns null if the file type is not guessable'); $t->is($v->guessFromFileBinary('/bin/ls'), PHP_OS != 'Darwin' ? 'application/x-executable' : 'application/octet-stream', '->guessFromFileBinary() returns correct type if file is guessable'); // ->getMimeType() $t->diag('->getMimeType()');
// ->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->guessFromFileBinary($tmpDir . '/foo.txt'), null, '->guessFromFileBinary() returns null if the file type is not guessable'); $t->is($v->guessFromFileBinary('/bin/ls'), PHP_OS != 'Darwin' ? 'application/x-executable' : 'application/octet-stream', '->guessFromFileBinary() returns correct type if file is guessable'); // ->getMimeType() $t->diag('->getMimeType()'); $v = new testValidatorFile(); $t->is($v->getMimeType($tmpDir . '/test.txt', 'image/png'), 'text/plain', '->getMimeType() guesses the type of a given file'); $t->is($v->getMimeType($tmpDir . '/foo.txt', 'text/plain'), 'text/plain', '->getMimeType() returns the default type if the file type is not guessable'); $v->setOption('mime_type_guessers', array_merge(array(array($v, 'guessFromNothing')), $v->getOption('mime_type_guessers'))); $t->is($v->getMimeType($tmpDir . '/test.txt', 'image/png'), 'nothing/plain', '->getMimeType() takes all guessers from the mime_type_guessers option');
// ->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'); $t->is($v->guessFromFileBinary($tmpDir . '/foo.txt'), null, '->guessFromFileBinary() returns null if the file type is not guessable'); $t->is($v->guessFromFileBinary('/bin/ls'), PHP_OS != 'Darwin' ? 'application/x-executable' : 'application/octet-stream', '->guessFromFileBinary() returns correct type if file is guessable'); // ->getMimeType() $t->diag('->getMimeType()'); $v = new testValidatorFile(); $t->is($v->getMimeType($tmpDir . '/test.txt', 'image/png'), version_compare(PHP_VERSION, '5.3', '<') ? 'text/plain' : 'text/plain; charset=us-ascii', '->getMimeType() guesses the type of a given file'); $t->is($v->getMimeType($tmpDir . '/foo.txt', 'text/plain'), 'text/plain', '->getMimeType() returns the default type if the file type is not guessable'); $v->setOption('mime_type_guessers', array_merge(array(array($v, 'guessFromNothing')), $v->getOption('mime_type_guessers'))); $t->is($v->getMimeType($tmpDir . '/test.txt', 'image/png'), 'nothing/plain', '->getMimeType() takes all guessers from the mime_type_guessers option');