Skip to content

Commit

Permalink
Applying patch from 'Ceeram'. Adds File::copy() and test case. Refs #150
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 9, 2009
1 parent ee7015c commit 8d40532
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cake/libs/file.php
Expand Up @@ -314,7 +314,7 @@ function delete() {
}

/**
* Returns the File extension.
* Returns the File info.
*
* @return string The File extension
* @access public
Expand Down Expand Up @@ -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);
}
}
?>
29 changes: 29 additions & 0 deletions cake/tests/cases/libs/file.test.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 8d40532

Please sign in to comment.