Skip to content

Commit 936b992

Browse files
committed
Add tests for overridden cacheMethodFilter
1 parent 1952d2e commit 936b992

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,35 @@ public function setConnection($conn) {
109109

110110
}
111111

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+
112141
/**
113142
* DboSourceTest class
114143
*
@@ -752,7 +781,7 @@ public function testCacheMethodFilter() {
752781

753782
$method = 'fields';
754783
$key = '2b57253ab1fffb3e95fa4f95299220b1';
755-
$value = ["`Menu`.`id`", "`Menu`.`name`"];
784+
$value = array("`Menu`.`id`", "`Menu`.`name`");
756785
$actual = $this->testDb->cacheMethodFilter($method, $key, $value);
757786

758787
$this->assertTrue($actual);
@@ -765,6 +794,50 @@ public function testCacheMethodFilter() {
765794
$this->assertTrue($actual);
766795
}
767796

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+
768841
/**
769842
* Test that rare collisions do not happen with method caching
770843
*

0 commit comments

Comments
 (0)