mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Applying patch from 'Ceeram'. Adds File::copy() and test case. Refs #150
This commit is contained in:
parent
ee7015c9bd
commit
8d40532931
2 changed files with 45 additions and 1 deletions
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -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
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue