/** * @param NodeInterface $rootNode */ public function __construct(NodeInterface $rootNode = null) { if (!$rootNode) { $rootNode = new Node('root'); } $rootNode->setId(0); $this->nodes[0] = $rootNode; }
/** * @param mixed|null $id * @param \Codex\Codex\Menus\Menu $menu * @param null $value * @param array $children */ public function __construct($id, Menu $menu, $value = null, array $children = []) { parent::__construct($value, $children); $this->id = $id; $this->menu = $menu; $this->meta = []; $this->attributes = ['href' => '#']; }
/** * root * /|\ * a b c * /| | * d e f */ public function testWalkSubTree() { $root = new Node('root'); $a = new Node('a'); $b = new Node('b'); $c = new Node('c'); $d = new Node('d'); $e = new Node('e'); $f = new Node('f'); $root->addChild($a); $root->addChild($b); $root->addChild($c); $a->addChild($d); $a->addChild($e); $b->addChild($f); $visitor = new PostOrderVisitor(); $expected = [$d, $e, $a]; $this->assertSame($expected, $visitor->visit($a)); }
protected function mergeUp(Node $node, $mergeName = '', $pushedObjects = array()) { // If it's a leaf, we do nothing! if ($node->isLeaf()) { return $pushedObjects; } // For the root node, we skip it, as it's a placeholder if ($node->getValue() == $this->config->getRootName()) { foreach ($node->getChildren() as $child) { $pushedObjects = $this->mergeUp($child, '', $pushedObjects); } return $pushedObjects; } // If it's any node with children, we merge self into those branches foreach ($node->getChildren() as $child) { // Get and prepare the from/to branches based on the node values $from = $this->bm->getBranchObjectByName($node->getValue()); if (!empty($mergeName)) { $from->setMergeName($mergeName); } $to = $this->bm->getBranchObjectByName($child->getValue()); if ($this->options['interactive']) { $this->dialog->askConfirmation($this->getOutput(), "Merge from {$from} to {$to}: ", FALSE); } $branchMerge = new BranchMerge($from, $to); $pushedObjectArr = $this->git->merge($branchMerge); // We want to merge the local branch into it's children, since the pull request will // not have been merged immediately $child->setValue((string) $pushedObjectArr['remoteBranch']); if ($this->options['pull-request'] && !empty($pushedObjectArr['pullRequest'])) { if ($this->options['interactive']) { $this->dialog->askConfirmation($this->getOutput(), "Submit pull request for {$pushedObjectArr['pullRequest']}: ", FALSE); } $this->git->submitPullRequest($pushedObjectArr['pullRequest']); } $pushedObjects[] = $pushedObjectArr; $pushedObjects = $this->mergeUp($child, $pushedObjectArr['remoteBranch']->getMergeName(), $pushedObjects); } return $pushedObjects; }
public function testGetSize() { $root = new Node(); $root->addChild($child1 = new Node('child1'))->addChild($child2 = new Node('child2'))->addChild($child3 = new Node('child3')); $child3->addChild(new Node("a"))->addChild($child4 = new Node("b")); $child4->addChild($child5 = new Node("c")); $child5->addChild(new Node("d"))->addChild(new Node("f")); $this->assertEquals(9, $root->getSize()); $this->assertEquals(3, $child5->getSize()); $this->assertEquals(4, $child4->getSize()); $this->assertEquals(6, $child3->getSize()); $this->assertEquals(1, $child2->getSize()); }
public function testId() { $node1 = new Node(null, [], 2); $node2 = new Node(null, [], 5); $node3 = (new Node())->setId(10); $this->assertEquals(2, $node1->getId()); $this->assertEquals(5, $node2->getId()); $this->assertEquals(10, $node3->getId()); }
/** * Find an account node using its id * * @param Nominal $nId * @return node|null */ protected function findNode(Nominal $nId) { return $this->tree->accept(new NodeFinder($nId)); }
/** * Recursively build chart of account tree * * @param Node $tree * @param \DOMNode $node * @param Chart $chart * @param array $accountTypes */ protected function buildTree(Node $tree, \DOMNode $node, Chart $chart, array $accountTypes) { //create current node list($nominal, $type, $name) = FFor::create()->attributes(function () use($node) { return $node->attributes; })->nominal(function ($attributes) { return new Nominal($attributes->getNamedItem('nominal')->nodeValue); })->name(function ($attributes) { return new StringType($attributes->getNamedItem('name')->nodeValue); })->type(function ($attributes) use($accountTypes) { return new AccountType($accountTypes[strtoupper($attributes->getNamedItem('type')->nodeValue)]); })->fyield('nominal', 'type', 'name'); $tree->setValue(new Account($chart, $nominal, $type, $name)); //recurse through sub accounts foreach ($node->childNodes as $childNode) { if ($childNode instanceof \DOMElement) { $childTree = new Node(); $tree->addChild($childTree); $this->buildTree($childTree, $childNode, $chart, $accountTypes); } } }
public function testTheYieldOfALeafNodeIsTheNodeItself() { $node = new Node('node'); $visitor = new YieldVisitor(); $this->assertSame([$node], $node->accept($visitor)); }
public function testIsChild() { $root = new Node('root'); $root->addChild($child = new Node('child')); $this->assertTrue($child->isChild()); $this->assertFalse($root->isChild()); }
protected function isRootNode(Node $node) { return $node->getValue() == $this->getRootName(); }
public function testBasicArray() { $tree = new Tree(); $a = new Node('a'); $c = new Node('c'); $a->addChild($c); $a->addChild($d = new Node('d')); $b = new Node('b'); $b->addChild($e = new Node('e')); $b->addChild($f = new Node('f')); $tree->addNode($a); $tree->addNode($b); $tree->addNode($g = new Node('g')); $h = new Node('h'); $tree->addNode($h, $c); $this->assertEquals([1 => $a, 2 => $c, 3 => $d, 4 => $b, 5 => $e, 6 => $f, 7 => $g, 8 => $h], $tree->getNodes()); }