From d7916037913434a642963f64e4d8a975624aee8d Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 8 Sep 2008 16:44:06 +0000 Subject: [PATCH] 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 --- cake/libs/folder.php | 4 ++-- cake/tests/cases/libs/folder.test.php | 29 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cake/libs/folder.php b/cake/libs/folder.php index 8fe397976..8d09a1809 100644 --- a/cake/libs/folder.php +++ b/cake/libs/folder.php @@ -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) { diff --git a/cake/tests/cases/libs/folder.test.php b/cake/tests/cases/libs/folder.test.php index 9d013c2dd..48364e319 100644 --- a/cake/tests/cases/libs/folder.test.php +++ b/cake/tests/cases/libs/folder.test.php @@ -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); + } + } ?> \ No newline at end of file