function testNumChildren() { $this->assertEquals($this->objFromFixture('HierarchyTest_Object', 'obj1')->numChildren(), 0); $this->assertEquals($this->objFromFixture('HierarchyTest_Object', 'obj2')->numChildren(), 2); $this->assertEquals($this->objFromFixture('HierarchyTest_Object', 'obj3')->numChildren(), 2); $this->assertEquals($this->objFromFixture('HierarchyTest_Object', 'obj2a')->numChildren(), 2); $this->assertEquals($this->objFromFixture('HierarchyTest_Object', 'obj2b')->numChildren(), 0); $this->assertEquals($this->objFromFixture('HierarchyTest_Object', 'obj3a')->numChildren(), 2); $this->assertEquals($this->objFromFixture('HierarchyTest_Object', 'obj3b')->numChildren(), 0); $obj1 = $this->objFromFixture('HierarchyTest_Object', 'obj1'); $this->assertEquals($obj1->numChildren(), 0); $obj1Child1 = new HierarchyTest_Object(); $obj1Child1->ParentID = $obj1->ID; $obj1Child1->write(); $this->assertEquals($obj1->numChildren(false), 1, 'numChildren() caching can be disabled through method parameter'); $obj1Child2 = new HierarchyTest_Object(); $obj1Child2->ParentID = $obj1->ID; $obj1Child2->write(); $obj1->flushCache(); $this->assertEquals($obj1->numChildren(), 2, 'numChildren() caching can be disabled by flushCache()'); }
/** * This test checks that deleted ('archived') child pages _do_ set a css class on the parent * node that makes it look like it has children when getting all children including deleted */ public function testGetChildrenAsULNodeDeletedOnStage() { $obj2 = $this->objFromFixture('HierarchyTest_Object', 'obj2'); $obj2a = $this->objFromFixture('HierarchyTest_Object', 'obj2a'); $obj2aa = $this->objFromFixture('HierarchyTest_Object', 'obj2aa'); $obj2ab = $this->objFromFixture('HierarchyTest_Object', 'obj2b'); // delete all children under obj2 $obj2a->delete(); $obj2aa->delete(); $obj2ab->delete(); // Don't pre-load all children $nodeCountThreshold = 1; $childrenMethod = 'AllChildrenIncludingDeleted'; $numChildrenMethod = 'numHistoricalChildren'; $root = new HierarchyTest_Object(); $root->markPartialTree($nodeCountThreshold, null, $childrenMethod, $numChildrenMethod); // As in LeftAndMain::getSiteTreeFor() but simpler and more to the point for testing purposes $titleFn = function (&$child, $numChildrenMethod = "") { return '<li class="' . $child->markingClasses($numChildrenMethod) . '" id="' . $child->ID . '">"' . $child->Title; }; $html = $root->getChildrenAsUL("", $titleFn, null, true, $childrenMethod, $numChildrenMethod, true, $nodeCountThreshold); // Get the class attribute from the $obj2 node in the sitetree $nodeClass = $this->getNodeClassFromTree($html, $obj2); // Object2 can now be expanded $this->assertEquals('unexpanded jstree-closed closed', $nodeClass, 'obj2 should have children in the sitetree'); }