Skip to content
This repository
Browse code

making messages() and errors() reset themselves by default

  • Loading branch information...
commit 7383298410836ee05566863aac785b31d1d6de3d 1 parent 9ed901b
Mark authored October 01, 2012
46  lib/Cake/Test/Case/Utility/FolderTest.php
@@ -767,6 +767,52 @@ public function testDirSize() {
767 767
 	}
768 768
 
769 769
 /**
  770
+ * test that errors and messages can be resetted
  771
+ *
  772
+ * @return void
  773
+ */
  774
+	public function testReset() {
  775
+		$path = TMP . 'folder_delete_test';
  776
+		mkdir($path);
  777
+		$folder = $path . DS . 'sub';
  778
+		mkdir($folder);
  779
+		$file = $folder . DS . 'file';
  780
+		touch($file);
  781
+		$handle = fopen($file, 'a');
  782
+
  783
+		$Folder = new Folder($folder);
  784
+		$return = $Folder->delete();
  785
+		$this->assertFalse($return);
  786
+
  787
+		$messages = $Folder->messages();
  788
+		$errors = $Folder->errors();
  789
+		$expected = array(
  790
+			$folder . DS . 'file NOT removed',
  791
+			$folder . ' NOT removed',
  792
+		);
  793
+		sort($expected);
  794
+		sort($errors);
  795
+		$this->assertEmpty($messages);
  796
+		$this->assertEquals($expected, $errors);
  797
+
  798
+		fclose($handle);
  799
+
  800
+		$return = $Folder->delete();
  801
+		$this->assertTrue($return);
  802
+
  803
+		$messages = $Folder->messages();
  804
+		$errors = $Folder->errors();
  805
+		$expected = array(
  806
+			$folder . DS . 'file removed',
  807
+			$folder . ' removed',
  808
+		);
  809
+		sort($expected);
  810
+		sort($messages);
  811
+		$this->assertEmpty($errors);
  812
+		$this->assertEquals($expected, $messages);
  813
+	}
  814
+
  815
+/**
770 816
  * testDelete method
771 817
  *
772 818
  * @return void
20  lib/Cake/Utility/Folder.php
@@ -23,7 +23,7 @@ class Folder {
23 23
 
24 24
 /**
25 25
  * Default scheme for Folder::copy
26  
- * Recursively merges subfolders with the same name 
  26
+ * Recursively merges subfolders with the same name
27 27
  *
28 28
  * @constant MERGE
29 29
  */
@@ -740,21 +740,31 @@ public function move($options) {
740 740
 /**
741 741
  * get messages from latest method
742 742
  *
  743
+ * @param boolean $reset Reset message stack after reading
743 744
  * @return array
744 745
  * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::messages
745 746
  */
746  
-	public function messages() {
747  
-		return $this->_messages;
  747
+	public function messages($reset = true) {
  748
+		$messages = $this->_messages;
  749
+		if ($reset) {
  750
+			$this->_messages = array();
  751
+		}
  752
+		return $messages;
748 753
 	}
749 754
 
750 755
 /**
751 756
  * get error from latest method
752 757
  *
  758
+ * @param boolean $reset Reset error stack after reading
753 759
  * @return array
754 760
  * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::errors
755 761
  */
756  
-	public function errors() {
757  
-		return $this->_errors;
  762
+	public function errors($reset = true) {
  763
+		$errors = $this->_errors;
  764
+		if ($reset) {
  765
+			$this->_errors = array();
  766
+		}
  767
+		return $errors;
758 768
 	}
759 769
 
760 770
 /**

0 notes on commit 7383298

Please sign in to comment.
Something went wrong with that request. Please try again.