@@ -109,6 +109,35 @@ public function setConnection($conn) {
109
109
110
110
}
111
111
112
+ /**
113
+ * DboFourthTestSource
114
+ *
115
+ * @package Cake.Test.Case.Model.Datasource
116
+ */
117
+ class DboFourthTestSource extends DboSource {
118
+
119
+ public function connect ($ config = array ()) {
120
+ $ this ->connected = true ;
121
+ }
122
+
123
+ public function cacheMethodFilter ($ method , $ key , $ value ) {
124
+ if ($ method === 'name ' ) {
125
+ if ($ value === '`menus` ' ) {
126
+ return false ;
127
+ } elseif ($ key === '1fca740733997f1ebbedacfc7678592a ' ) {
128
+ return false ;
129
+ }
130
+ } elseif ($ method === 'fields ' ) {
131
+ $ endsWithName = preg_grep ('/`name`$/ ' , $ value );
132
+
133
+ return count ($ endsWithName ) === 0 ;
134
+ }
135
+
136
+ return true ;
137
+ }
138
+
139
+ }
140
+
112
141
/**
113
142
* DboSourceTest class
114
143
*
@@ -752,7 +781,7 @@ public function testCacheMethodFilter() {
752
781
753
782
$ method = 'fields ' ;
754
783
$ key = '2b57253ab1fffb3e95fa4f95299220b1 ' ;
755
- $ value = [ "`Menu`.`id` " , "`Menu`.`name` " ] ;
784
+ $ value = array ( "`Menu`.`id` " , "`Menu`.`name` " ) ;
756
785
$ actual = $ this ->testDb ->cacheMethodFilter ($ method , $ key , $ value );
757
786
758
787
$ this ->assertTrue ($ actual );
@@ -765,6 +794,50 @@ public function testCacheMethodFilter() {
765
794
$ this ->assertTrue ($ actual );
766
795
}
767
796
797
+ /**
798
+ * Test that cacheMethodFilter can be overridden to do actual filtering.
799
+ *
800
+ * @return void
801
+ */
802
+ public function testCacheMethodFilterOverridden () {
803
+ $ testDb = new DboFourthTestSource ();
804
+
805
+ $ method = 'name ' ;
806
+ $ key = '49d9207adfce6df1dd3ee8c30c434414 ' ;
807
+ $ value = '`menus` ' ;
808
+ $ actual = $ testDb ->cacheMethodFilter ($ method , $ key , $ value );
809
+
810
+ $ this ->assertFalse ($ actual );
811
+
812
+ $ method = 'name ' ;
813
+ $ key = '1fca740733997f1ebbedacfc7678592a ' ;
814
+ $ value = '`Menu`.`id` ' ;
815
+ $ actual = $ testDb ->cacheMethodFilter ($ method , $ key , $ value );
816
+
817
+ $ this ->assertFalse ($ actual );
818
+
819
+ $ method = 'fields ' ;
820
+ $ key = '2b57253ab1fffb3e95fa4f95299220b1 ' ;
821
+ $ value = array ("`Menu`.`id` " , "`Menu`.`name` " );
822
+ $ actual = $ testDb ->cacheMethodFilter ($ method , $ key , $ value );
823
+
824
+ $ this ->assertFalse ($ actual );
825
+
826
+ $ method = 'name ' ;
827
+ $ key = 'd2bc458620afb092c61ab4383b7475e0 ' ;
828
+ $ value = '`Menu` ' ;
829
+ $ actual = $ testDb ->cacheMethodFilter ($ method , $ key , $ value );
830
+
831
+ $ this ->assertTrue ($ actual );
832
+
833
+ $ method = 'non-existing ' ;
834
+ $ key = '' ;
835
+ $ value = '`` ' ;
836
+ $ actual = $ testDb ->cacheMethodFilter ($ method , $ key , $ value );
837
+
838
+ $ this ->assertTrue ($ actual );
839
+ }
840
+
768
841
/**
769
842
* Test that rare collisions do not happen with method caching
770
843
*
0 commit comments