Updating folder::delete() to properly record file deletions. Thanks for the patch 'davidpersson'. Tests Added. Closes #5394

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7570 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-09-08 16:44:06 +00:00
parent fe82e827f0
commit d791603791
2 changed files with 31 additions and 2 deletions

View file

@ -544,9 +544,9 @@ class Folder extends Object {
}
if (is_file($file) === true) {
if (@unlink($file)) {
$this->__messages[] = sprintf(__('%s removed', true), $path);
$this->__messages[] = sprintf(__('%s removed', true), $file);
} else {
$this->__errors[] = sprintf(__('%s NOT removed', true), $path);
$this->__errors[] = sprintf(__('%s NOT removed', true), $file);
}
} elseif (is_dir($file) === true) {
if ($this->delete($file) === false) {

View file

@ -460,5 +460,34 @@ class FolderTest extends CakeTestCase {
$folder->cd(TMP);
$folder->delete($folder->pwd().'config_non_existant');
}
/**
* testDelete method
*
* @access public
* @return void
*/
function testDelete() {
$path = TMP . 'folder_delete_test';
$Folder =& new Folder($path, true);
touch(TMP.'folder_delete_test' . DS . 'file1');
touch(TMP.'folder_delete_test' . DS . 'file2');
$return = $Folder->delete();
$this->assertTrue($return);
$messages = $Folder->messages();
$errors = $Folder->errors();
$this->assertEqual($errors, array());
$expected = array(
$path . ' created',
$path . DS . 'file1 removed',
$path . DS . 'file2 removed',
$path . ' removed'
);
$this->assertEqual($expected, $messages);
}
}
?>