public function itReturnsTheChildrenAndSubChildrenAsAFlatList() { $child1 = new TreeNode(); $subchild1 = new TreeNode(); $child1->addChild($subchild1); $child2 = new TreeNode(); $node = new TreeNode(); $node->addChild($child1); $node->addChild($child2); $this->assertEqual(array($child1, $subchild1, $child2), $node->flattenChildren()); }
/** * @return TreeNode */ public function wrapInAThreeLevelArtifactTree(array $cards) { $forest = new TreeNode(); $forest->setChildren($cards); $root = new TreeNode(); $root->addChild($forest); return $root; }
public function itHasACardInCellPresenterWithSwimLineValueCollection() { $parent_node = new TreeNode(); $parent_node->addChild($this->card_presenter_node); $mapping_collection = stub('Cardwall_MappingCollection')->getSwimLineValues($this->field_id)->returns(array(123, 456)); $cardincell_presenter_callback = new Cardwall_CardInCellPresenterCallback($this->field_retriever, $mapping_collection); $cardincell_presenter_node = $cardincell_presenter_callback->apply($this->card_presenter_node); $this->assertEqual($cardincell_presenter_node->getCardInCellPresenter(), new Cardwall_CardInCellPresenter($this->card_presenter, $this->field_id, $parent_node->getId(), array(123, 456))); }
/** * Return the Tree * * ROOT * | * +-Child 1 (id:6, al:8) * | * '-Child 2 (id:8) * */ protected function buildBaseTree() { $parent = new TreeNode(); $child1 = $this->getTreeNode(6, 'Child 1', '8'); $child2 = $this->getTreeNode(8, 'Child 2'); $parent->addChild($child1); $child1->addChild($child2); return $parent; }
function ItInjectsPadding() { $root = new TreeNode(); $node1 = new TreeNode(); $node2 = new TreeNode(); $root->addChild($node1); $node1->addChild($node2); $visitor = new TreeNode_InjectPaddingInTreeNodeVisitor(); $root->accept($visitor); $data = $node2->getData(); $this->assertPattern('%div class="tree-blank" >[^<]*</div><div class="tree-last"%', $data['tree-padding']); }
private function buildTreeNode() { $root = new TreeNode(); $root->setId(0); foreach (func_get_args() as $arg) { $node = new TreeNode(); $node->setObject($arg); $node->setId($arg->getId()); $root->addChild($node); } return $root; }
private function getHierarchyAsTreeNode($hierarchy) { $node = new TreeNode(); if (isset($hierarchy['children'])) { $node->setData(array('name' => $hierarchy['name'], 'id' => $hierarchy['id'], 'current_class' => '')); $node->setId($hierarchy['id']); $hierarchy = $hierarchy['children']; } else { $node->setId('root'); } foreach ($hierarchy as $item) { $node->addChild($this->getHierarchyAsTreeNode($item)); } return $node; }
/** * Test the constructor */ function test_everything() { // create a few root nodes $node1 = new TreeNode('1'); $this->assertIdentical($node1->getId(), '1'); $this->assertFalse($node1->hasParents()); $this->assertEqual($node1->getChildren(), array()); $this->assertFalse($node1->hasChildren()); $this->assertIdentical($node1->getChildrenCount(), 0); // create some children $node1_1 = new TreeNode('2'); $node1_2 = new TreeNode('3'); $node1->addChild($node1_1); $node1->addChild($node1_2); $node1_1_1 = new TreeNode('4'); $node1_1->addChild($node1_1_1); $parents = $node1_1->getParents(); $this->assertReference($node1, $parents['1']); $parents = $node1_2->getParents(); $this->assertReference($node1, $parents['1']); $parents = $node1_1_1->getParents(); $this->assertReference($node1_1, $parents['2']); $this->assertIdentical($node1_1->getId(), '2'); $this->assertIdentical($node1_2->getId(), '3'); $this->assertIdentical($node1_1_1->getId(), '4'); $this->assertTrue($node1->hasChildren()); $this->assertTrue($node1_1->hasChildren()); $this->assertFalse($node1_2->hasChildren()); $this->assertIdentical($node1->getChildrenCount(), 2); $children = $node1->getChildren(); $this->assertReference($children['2'], $node1_1); $this->assertReference($children['3'], $node1_2); $children = $node1_1->getChildren(); $this->assertReference($children['4'], $node1_1_1); // create a new root $node = new TreeNode('100'); $node->addChild($node1); $children = $node->getChildren(); $this->assertReference($children['1'], $node1); $parents = $node1->getParents(); $this->assertReference($node, $parents['100']); // try detaching a node now $node1->detachChild($node1_1); $this->assertFalse($node1_1->hasParents()); $this->assertFalse($node1->isChild($node1_1)); $this->assertTrue($node1->isChild($node1_2)); }
/** * Adds $parent_node children according to $artifact ones. * * @param type $user * @param type $artifact * @param type $parent_node * @param type $parents The list of parents to prevent infinite recursion * * @return boolean */ private function addChildrenPlannedArtifacts(User $user, Tracker_Artifact $artifact, TreeNode $parent_node, array $parents) { $linked_artifacts = $artifact->getUniqueLinkedArtifacts($user); if (!$linked_artifacts) { return false; } if (in_array($artifact->getId(), $parents)) { return false; } $parents[] = $artifact->getId(); foreach ($linked_artifacts as $linked_artifact) { $node = $this->makeNodeWithChildren($user, $linked_artifact, $parents); $parent_node->addChild($node); } }
private function GivenANodeInAparent(TreeNode $parent) { $node = new TreeNode(); $parent->addChild($node); return $node; }
function project_tabs($toptab, $group_id) { $pm = ProjectManager::instance(); $project = $pm->getProject($group_id); if ($project->isError()) { //wasn't found or some other problem return; } $menuTree = new TreeNode(); $output = ''; $tabs = $this->_getProjectTabs($toptab, $project); $nb = count($tabs); $selected = false; for ($i = 0; $i < $nb; $i++) { if ($tabs[$i]['enabled'] === true) { $selected = true; } $menuTree->addChild(new TreeNode(array('link' => $tabs[$i]['link'], 'title' => $tabs[$i]['label'], 'selected' => $tabs[$i]['enabled']))); } //$output .= $this->tabGenerator($TABS_DIRS,$TABS_TITLES,true,$selected, 2); //echo $output; return $menuTree; }
function testRenderShouldPadTheArtifactsAccordingToTheirLevel() { $service = new MockService(); $criteria = $this->GivenCriteria(); $artifacts = array(array('id' => '6', 'last_changeset_id' => '12345', 'title' => 'As a user I want to search on shared fields', 'artifactlinks' => '8'), array('id' => '8', 'last_changeset_id' => '56789', 'title' => 'Add the form', 'artifactlinks' => '')); $root = new TreeNode(); $node0 = new TreeNode($artifacts[0]); $node0->setId($artifacts[0]['id']); $node1 = new TreeNode($artifacts[1]); $node1->setId($artifacts[1]['id']); $root->addChild($node0); $node0->addChild($node1); $view = $this->GivenASearchView($service, $criteria, $artifacts, $root); $output = $this->renderAndGetContent($view); $pattern = '(.*)?(tree-node-6)(.*)?(node-indent)(.*)?(node-last-left)(.*)?(node-tree)(.*)?(node-indent)(.*)?(node-minus-tree)(.*)?(node-child)'; $pattern .= '(.*)?(tree-node-8)(.*)?(node-blank)(.*)?'; $this->assertPattern("%^{$pattern}\$%ism", $output); }
/** * Function to create a TreeNode based off the * given value and add it to the tree with a * set parent. * * @param mixed $value - the value of the created * TreeNode * @param TreeNode $parent - the parent node or null * if there is no parent * @return void * @author Karthik Viswanathan */ private function appendToTree($value, $parent) { $node = null; // if there is no parent, make the tag // without one. if ($parent == null) { $node = new TreeNode($value); } else { $node = new TreeNode($value, $parent); $parent->addChild($node); } return $node; }
protected function getATreeNode($tree_node_id, $artifact_links = array(), $classname = "planning-draggable-alreadyplanned") { $node = new TreeNode(array('id' => $tree_node_id, 'artifact_id' => $tree_node_id, 'title' => 'Artifact ' . $tree_node_id, 'class' => $classname, 'uri' => '/bar', 'xref' => 'art #' . $tree_node_id, 'editLabel' => null, 'allowedChildrenTypes' => array())); $node->setId($tree_node_id); foreach ($artifact_links as $node_child) { $node->addChild($node_child); } return $node; }
private function buildArtifactsTree(User $user, TreeNode $root, array $artifacts, array $artifacts_info) { foreach ($artifacts as $artifact) { $node = new TreeNode($this->getArtifactInfo($artifact, $artifacts_info)); $node->setObject($artifact); $this->buildArtifactsTree($user, $node, $artifact->getHierarchyLinkedArtifacts($user), $artifacts_info); $root->addChild($node); } }
private function buildArtifactsTree(User $user, TreeNode $root, array $artifacts, array $artifacts_info, array $excluded_artifact_ids) { foreach ($artifacts as $artifact) { if (!isset($excluded_artifact_ids[$artifact->getId()])) { $node = new TreeNode($this->getArtifactInfo($artifact, $artifacts_info)); $node->setObject($artifact); $this->buildArtifactsTree($user, $node, $artifact->getHierarchyLinkedArtifacts($user), $artifacts_info, $excluded_artifact_ids); $root->addChild($node); } } }
public function setUp() { parent::setUp(); $report = new MockTracker_Report(); $release_tracker_id = 743; $release_tracker = aTracker()->withId($release_tracker_id)->build(); $art_link_release_field_id = 131; $art_link_release_field = mock('Tracker_CrossSearch_ArtifactReportField'); stub($art_link_release_field)->getTracker()->returns($release_tracker); stub($art_link_release_field)->getArtifactLinkFieldName()->returns('art_link_' . $art_link_release_field_id); $art_link_release_criterion = new Tracker_Report_Criteria(null, $report, $art_link_release_field, 0, true); $sprint_tracker_id = 365; $sprint_tracker = aTracker()->withId($sprint_tracker_id)->build(); $art_link_sprint_field_id = 511; $art_link_sprint_field = mock('Tracker_CrossSearch_ArtifactReportField'); stub($art_link_sprint_field)->getTracker()->returns($sprint_tracker); stub($art_link_sprint_field)->getArtifactLinkFieldName()->returns('art_link_' . $art_link_sprint_field_id); $art_link_sprint_criterion = new Tracker_Report_Criteria(null, $report, $art_link_sprint_field, 0, true); $criteria = array($art_link_release_criterion, $art_link_sprint_criterion); $this->sprint_id = '354'; $this->sprint = stub('Tracker_Artifact')->getTitle()->returns('The planning known as Sprint'); $this->release_id = '666'; $this->release = stub('Tracker_Artifact')->getTitle()->returns('I release I can fly'); $artifact_node = new TreeNode(); $artifact_node->setId(1); $artifact_node->setData(array('id' => 123, 'title' => 'foo', 'last_changeset_id' => '567', 'art_link_' . $art_link_sprint_field_id => $this->sprint_id, 'art_link_' . $art_link_release_field_id => $this->release_id)); $tree_of_artifacts = new TreeNode(); $tree_of_artifacts->setId(0); $tree_of_artifacts->addChild($artifact_node); $this->artifact_factory = new MockTracker_ArtifactFactory(); $factory = new MockTracker_FormElementFactory(); $tracker = new MockTracker(); $artifact = new MockTracker_Artifact(); $this->user = mock('PFUser'); $artifact->setReturnValue('getTracker', $tracker); stub($this->artifact_factory)->getArtifactById(123)->returns($artifact); $this->view = new Tracker_CrossSearch_SearchContentView($report, $criteria, $tree_of_artifacts, $this->artifact_factory, $factory, $this->user); }
/** * recursive way to build tree structure * * @param array $keyParts * @param TreeNode $rootNode * * @return TreeNode */ protected function createTree(&$keyParts, TreeNode $rootNode) : TreeNode { if (!count($keyParts)) { return $rootNode; } $newKey = array_shift($keyParts); $newNode = new self($rootNode, $newKey, null, $rootNode->getKeyDelimiter()); $rootNode->addChild($newNode); return $this->createTree($keyParts, $newNode); }