Skip to content

Commit e1f29f0

Browse files
committed
Adding test for find('threaded') with composite keys
1 parent deec394 commit e1f29f0

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

tests/TestCase/ORM/CompositeKeysTest.php

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public function testOneGenerateBelongsToManyEntitiesFromIds() {
355355
*
356356
* @return void
357357
*/
358-
public function testFindCompositeKeys() {
358+
public function testFindListCompositeKeys() {
359359
$table = new Table([
360360
'table' => 'site_authors',
361361
'connection' => $this->connection,
@@ -400,4 +400,94 @@ public function testFindCompositeKeys() {
400400
$this->assertEquals($expected, $query->toArray());
401401
}
402402

403+
/**
404+
* Tests find('threaded') with composite keys
405+
*
406+
* @return void
407+
*/
408+
public function testFindThreadedCompositeKeys() {
409+
$table = TableRegistry::get('SiteAuthors');
410+
$query = $this->getMock(
411+
'\Cake\ORM\Query',
412+
['_addDefaultFields', 'execute'],
413+
[null, $table]
414+
);
415+
416+
$items = new \Cake\ORM\ResultSetDecorator([
417+
['id' => 1, 'name' => 'a', 'site_id' => 1, 'parent_id' => null],
418+
['id' => 2, 'name' => 'a', 'site_id' => 2, 'parent_id' => null],
419+
['id' => 3, 'name' => 'a', 'site_id' => 1, 'parent_id' => 1],
420+
['id' => 4, 'name' => 'a', 'site_id' => 2, 'parent_id' => 2],
421+
['id' => 5, 'name' => 'a', 'site_id' => 2, 'parent_id' => 4],
422+
['id' => 6, 'name' => 'a', 'site_id' => 1, 'parent_id' => 2],
423+
['id' => 7, 'name' => 'a', 'site_id' => 1, 'parent_id' => 3],
424+
['id' => 8, 'name' => 'a', 'site_id' => 2, 'parent_id' => 4],
425+
]);
426+
$query->find('threaded', ['parentField' => ['parent_id', 'site_id']]);
427+
$formatter = $query->formatResults()[0];
428+
429+
$expected = [
430+
[
431+
'id' => 1,
432+
'name' => 'a',
433+
'site_id' => 1,
434+
'parent_id' => null,
435+
'children' => [
436+
[
437+
'id' => 3,
438+
'name' => 'a',
439+
'site_id' => 1,
440+
'parent_id' => 1,
441+
'children' => [
442+
[
443+
'id' => 7,
444+
'name' => 'a',
445+
'site_id' => 1,
446+
'parent_id' => 3,
447+
'children' => []
448+
]
449+
]
450+
]
451+
]
452+
],
453+
[
454+
'id' => 2,
455+
'name' => 'a',
456+
'site_id' => 2,
457+
'parent_id' => null,
458+
'children' => [
459+
[
460+
'id' => 4,
461+
'name' => 'a',
462+
'site_id' => 2,
463+
'parent_id' => 2,
464+
'children' => [
465+
[
466+
'id' => 5,
467+
'name' => 'a',
468+
'site_id' => 2,
469+
'parent_id' => 4,
470+
'children' => []
471+
],
472+
[
473+
'id' => 8,
474+
'name' => 'a',
475+
'site_id' => 2,
476+
'parent_id' => 4,
477+
'children' => []
478+
]
479+
]
480+
]
481+
]
482+
],
483+
[
484+
'id' => 6,
485+
'name' => 'a',
486+
'site_id' => 1,
487+
'parent_id' => 2,
488+
'children' => []
489+
]
490+
];
491+
$this->assertEquals($expected, $formatter($items)->toArray());
492+
}
403493
}

0 commit comments

Comments
 (0)