@@ -382,6 +382,32 @@ public function testGetChildrenAsULNodeDeletedOnStage()
382382 $ this ->assertEquals ('unexpanded jstree-closed closed ' , $ nodeClass , 'obj2 should have children in the sitetree ' );
383383 }
384384
385+ public function testGetChildrenAsArrayIncludesLevel (): void
386+ {
387+ $ obj3 = $ this ->objFromFixture (HierarchyTest \TestObject::class, 'obj3 ' );
388+ $ obj3a = $ this ->objFromFixture (HierarchyTest \TestObject::class, 'obj3a ' );
389+ $ obj3aa = $ this ->objFromFixture (HierarchyTest \TestObject::class, 'obj3aa ' );
390+
391+ $ set = new MarkedSet (HierarchyTest \TestObject::singleton (), 'AllChildrenIncludingDeleted ' , 'numChildren ' );
392+ $ set ->markPartialTree ();
393+ $ set ->markToExpose ($ obj3aa );
394+
395+ $ tree = $ set ->getChildrenAsArray (function ($ node ) {
396+ return [
397+ 'id ' => $ node ->ID ,
398+ 'title ' => $ node ->Title ,
399+ ];
400+ });
401+ $ node3 = $ this ->findTreeNodeById ($ tree , $ obj3 ->ID );
402+ $ node3a = $ this ->findTreeNodeById ($ tree , $ obj3a ->ID );
403+ $ node3aa = $ this ->findTreeNodeById ($ tree , $ obj3aa ->ID );
404+
405+ $ this ->assertSame (1 , $ tree ['level ' ]);
406+ $ this ->assertSame (2 , $ node3 ['level ' ]);
407+ $ this ->assertSame (3 , $ node3a ['level ' ]);
408+ $ this ->assertSame (4 , $ node3aa ['level ' ]);
409+ }
410+
385411
386412 /**
387413 * @param string $html [description]
@@ -436,6 +462,22 @@ protected function getNodeClassFromTree($html, $node)
436462 return '' ;
437463 }
438464
465+ protected function findTreeNodeById (array $ tree , int $ id ): array
466+ {
467+ if (($ tree ['id ' ] ?? null ) === $ id ) {
468+ return $ tree ;
469+ }
470+
471+ foreach ($ tree ['children ' ] ?? [] as $ child ) {
472+ $ result = $ this ->findTreeNodeById ($ child , $ id );
473+ if ($ result ) {
474+ return $ result ;
475+ }
476+ }
477+
478+ return [];
479+ }
480+
439481 protected function assertHTMLSame ($ expected , $ actual , $ message = '' )
440482 {
441483 // Trim each line, strip empty lines
0 commit comments