public function testMergeTag() { $tree1 = array(0 => null); $res = Trees::mergeTag($tree1, $tree1); $this->assertEqual(array('(root)' => null), $res); $tree1 = array(0 => null); $tree2 = array(1 => null); $res = Trees::mergeTag($tree1, $tree2); $this->assertEqual(array('(root)' => null), $res); // 0 // / \ // 1 2 // / / \ // 3 4 5 $tree1 = array(0 => array('children' => array(1 => array('children' => array(3 => null)), 2 => array('children' => array(4 => null, 5 => null))))); $expected = array('(root)' => array('children' => array(1 => array('children' => array(3 => array('tag' => 'IN_BOTH')), 'tag' => 'IN_BOTH'), 2 => array('children' => array(4 => array('tag' => 'IN_BOTH'), 5 => array('tag' => 'IN_BOTH')), 'tag' => 'IN_BOTH')))); $res = Trees::mergeTag($tree1, $tree1); $this->assertEqual($expected, $res); // Tree 1 // // 0 // / \ // 1 2 // / \ \ // 3 4 5 $tree1 = array(0 => array('children' => array(1 => array('children' => array(3 => null, 4 => null)), 2 => array('children' => array(5 => null))), 'somedata' => 1)); // Tree 2 // // 0 // / | \ // 1 2 7 // | // 6 $tree2 = array(0 => array('children' => array(1 => null, 2 => array('children' => array(6 => null)), 7 => array('somedata' => 2)))); // Expected result: the two previous trees merged // // 0 // / | \ // 1 7 2 // / \ / \ // 3 4 5 6 $expected = array('(root)' => array('children' => array(1 => array('children' => array(3 => array('tag' => 'IN_FIRST'), 4 => array('tag' => 'IN_FIRST')), 'tag' => 'IN_BOTH'), 2 => array('children' => array(5 => array('tag' => 'IN_FIRST'), 6 => array('tag' => 'IN_SECOND')), 'tag' => 'IN_BOTH'), 7 => array('tag' => 'IN_SECOND', 'somedata' => 2)), 'somedata' => 1)); $res = Trees::mergeTag($tree1, $tree2); $this->assertEqual($expected, $res); }
/** * Converts an array of items as returned by the SOAP function getDocmanTreeInfo to a tree of IDs */ private function buildDistantTreeFromSoapArray() { $listOfNodes = array(); foreach ($this->remoteItems as $id => $itemInfo) { $listOfNodes[$itemInfo->parent_id][] = $id; } // Tree of ids $tree = Trees::nodeListToTree($listOfNodes); return $tree; }