Skip to content
Permalink
Browse files

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

  • Loading branch information...
markstory committed Oct 9, 2009
1 parent ee7015c commit 8d40532931827697ee2653e9eafc035d433632c5
Showing with 45 additions and 1 deletion.
  1. +16 −1 cake/libs/file.php
  2. +29 −0 cake/tests/cases/libs/file.test.php
@@ -314,7 +314,7 @@ function delete() {
}
/**
* Returns the File extension.
* Returns the File info.
*
* @return string The File extension
* @access public
@@ -540,5 +540,20 @@ function lastChange() {
function &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);
}
}
?>
@@ -416,6 +416,35 @@ function testDelete() {
$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
*

0 comments on commit 8d40532

Please sign in to comment.
You can’t perform that action at this time.