Beispiel #1
0
// sfValidatedFile
// ->getOriginalName() ->getTempName() ->getSize() ->getType()
$t->diag('->getOriginalName() ->getTempName() ->getSize() ->getType()');
sfToolkit::clearDirectory($tmpDir . '/foo');
if (is_dir($tmpDir . '/foo')) {
    rmdir($tmpDir . '/foo');
}
$f = new sfValidatedFile('test.txt', 'text/plain', $tmpDir . '/test.txt', strlen($content));
$t->is($f->getOriginalName(), 'test.txt', '->getOriginalName() returns the original name');
$t->is($f->getTempName(), $tmpDir . '/test.txt', '->getTempName() returns the temp name');
$t->is($f->getType(), 'text/plain', '->getType() returns the content type');
$t->is($f->getSize(), strlen($content), '->getSize() returns the size of the uploaded file');
// ->save() ->isSaved() ->getSavedName()
$t->diag('->save() ->isSaved() ->getSavedName()');
$f = new sfValidatedFile('test.txt', 'text/plain', $tmpDir . '/test.txt', strlen($content));
$t->is($f->isSaved(), false, '->isSaved() returns false if the file has not been saved');
$t->is($f->getSavedName(), null, '->getSavedName() returns null if the file has not been saved');
$filename = $f->save($tmpDir . '/foo/test1.txt');
$t->is($filename, $tmpDir . '/foo/test1.txt', '->save() returns the saved filename');
$t->is(file_get_contents($tmpDir . '/foo/test1.txt'), file_get_contents($tmpDir . '/test.txt'), '->save() saves the file to the given path');
$t->is($f->isSaved(), true, '->isSaved() returns true if the file has been saved');
$t->is($f->getSavedName(), $tmpDir . '/foo/test1.txt', '->getSavedName() returns the saved file name');
$f = new sfValidatedFile('test.txt', 'text/plain', $tmpDir . '/test.txt', strlen($content), $tmpDir);
$filename = $f->save($tmpDir . '/foo/test1.txt');
$t->is($filename, 'foo/test1.txt', '->save() returns the saved filename relative to the path given');
$t->is(file_get_contents($tmpDir . '/foo/test1.txt'), file_get_contents($tmpDir . '/test.txt'), '->save() saves the file to the given path');
$t->is($f->getSavedName(), $tmpDir . '/foo/test1.txt', '->getSavedName() returns the saved file name');
$filename = $f->save('foo/test1.txt');
$t->is($filename, 'foo/test1.txt', '->save() returns the saved filename relative to the path given');
$t->is(file_get_contents($tmpDir . '/foo/test1.txt'), file_get_contents($tmpDir . '/test.txt'), '->save() saves the file to the given path and uses the path if the file is not absolute');
$t->is($f->getSavedName(), $tmpDir . '/foo/test1.txt', '->getSavedName() returns the saved file name');