/** * Builds the node tree from the given structure. * * @param array $treeStructure * the tree structure as array, may be empty * @param tx_oelib_Visibility_Node $parentNode * the parent node for the current key * * @return void */ private function buildTreeFromArray(array $treeStructure, tx_oelib_Visibility_Node $parentNode) { foreach ($treeStructure as $nodeKey => $nodeContents) { /** @var tx_oelib_Visibility_Node $childNode */ $childNode = t3lib_div::makeInstance('tx_oelib_Visibility_Node'); $parentNode->addChild($childNode); if (is_array($nodeContents)) { $this->buildTreeFromArray($nodeContents, $childNode); } elseif ($nodeContents === TRUE) { $childNode->markAsVisible(); } $this->nodes[$nodeKey] = $childNode; } }
/** * @test */ public function markAsVisibleForNodeWithParentAndGrandparentMarksGrandparentNodeAsVisible() { $childNode = new tx_oelib_Visibility_Node(); $grandChildNode = new tx_oelib_Visibility_Node(); $childNode->setParent($this->subject); $grandChildNode->setParent($childNode); $grandChildNode->markAsVisible(); self::assertTrue($this->subject->isVisible()); }
/** * Adds a child to this node. * * @param tx_oelib_Visibility_Node $child the child to add to this node * * @return void */ public function addChild(tx_oelib_Visibility_Node $child) { $this->children[] = $child; $child->setParent($this); }