Esempio n. 1
0
    $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');
// ->clean()
$t->diag('->clean()');
$v = new testValidatorFile();
try {
    $v->clean(array('test' => true));
    $t->fail('->clean() throws an sfValidatorError if the given value is not well formatted');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the given value is not well formatted');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
$f = $v->clean(array('tmp_name' => $tmpDir . '/test.txt'));
Esempio n. 2
0
    $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');
// ->clean()
$t->diag('->clean()');
$v = new testValidatorFile();
try {
    $v->clean(array('test' => true));
    $t->fail('->clean() throws an sfValidatorError if the given value is not well formatted');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws an sfValidatorError if the given value is not well formatted');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
$f = $v->clean(array('tmp_name' => $tmpDir . '/test.txt'));