|
24 | 24 | */
|
25 | 25 | class TestTable extends Table {
|
26 | 26 |
|
| 27 | + public function initialize(array $config = []) { |
| 28 | + $this->schema(['id' => ['type' => 'integer']]); |
| 29 | + } |
| 30 | + |
| 31 | + public function findPublished($query) { |
| 32 | + return $query->applyOptions(['this' => 'worked']); |
| 33 | + } |
| 34 | + |
27 | 35 | }
|
28 | 36 |
|
29 | 37 | /**
|
@@ -197,4 +205,39 @@ public function testInvalidStrategy() {
|
197 | 205 | $this->assertEquals('subquery', $this->association->strategy());
|
198 | 206 | }
|
199 | 207 |
|
| 208 | + public function testFinderMethod() { |
| 209 | + $this->assertEquals('all', $this->association->finder()); |
| 210 | + $this->assertEquals('published', $this->association->finder('published')); |
| 211 | + $this->assertEquals('published', $this->association->finder()); |
| 212 | + } |
| 213 | + |
| 214 | + public function testFinderInConstructor() { |
| 215 | + $config = [ |
| 216 | + 'className' => '\Cake\Test\TestCase\ORM\TestTable', |
| 217 | + 'foreignKey' => 'a_key', |
| 218 | + 'conditions' => ['field' => 'value'], |
| 219 | + 'dependent' => true, |
| 220 | + 'sourceTable' => $this->source, |
| 221 | + 'joinType' => 'INNER', |
| 222 | + 'finder' => 'published' |
| 223 | + ]; |
| 224 | + $assoc = $this->getMock( |
| 225 | + '\Cake\ORM\Association', |
| 226 | + [ |
| 227 | + '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide', |
| 228 | + 'saveAssociated', 'eagerLoader', 'type' |
| 229 | + ], |
| 230 | + ['Foo', $config] |
| 231 | + ); |
| 232 | + $this->assertEquals('published', $assoc->finder()); |
| 233 | + } |
| 234 | + |
| 235 | + public function testCustomFinderIsUsed() { |
| 236 | + $this->association->finder('published'); |
| 237 | + $this->assertEquals( |
| 238 | + ['this' => 'worked'], |
| 239 | + $this->association->find()->getOptions() |
| 240 | + ); |
| 241 | + } |
| 242 | + |
200 | 243 | }
|
0 commit comments