Applying patch from 'Ceeram'. Adds File::copy() and test case. Refs #150

This commit is contained in:
mark_story 2009-10-08 23:27:31 -04:00
parent ee7015c9bd
commit 8d40532931
2 changed files with 45 additions and 1 deletions

View file

@ -314,7 +314,7 @@ class File extends Object {
} }
/** /**
* Returns the File extension. * Returns the File info.
* *
* @return string The File extension * @return string The File extension
* @access public * @access public
@ -540,5 +540,20 @@ class File extends Object {
function &Folder() { function &Folder() {
return $this->Folder; return $this->Folder;
} }
/**
* Copy the File to $dest
*
* @param string $dest destination for the copy
* @param boolean $overwrite Overwrite $dest if exists
* @return boolean Succes
* @access public
*/
function copy($dest, $overwrite = true) {
if (!$this->exists() || is_file($dest) && !$overwrite) {
return false;
}
return copy($this->path, $dest);
}
} }
?> ?>

View file

@ -416,6 +416,35 @@ class FileTest extends CakeTestCase {
$this->assertFalse($result); $this->assertFalse($result);
} }
/**
* testCopy method
*
* @access public
* @return void
*/
function testCopy() {
$dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
$file = __FILE__;
$this->File =& new File($file);
$result = $this->File->copy($dest);
$this->assertTrue($result);
$result = $this->File->copy($dest, true);
$this->assertTrue($result);
$result = $this->File->copy($dest, false);
$this->assertFalse($result);
$this->File->close();
unlink($dest);
$TmpFile =& new File('/this/does/not/exist');
$result = $TmpFile->copy($dest);
$this->assertFalse($result);
$TmpFile->close();
}
/** /**
* getTmpFile method * getTmpFile method
* *