Path: blob/master/src/infrastructure/diff/view/__tests__/PHUIDiffGraphViewTestCase.php
12242 views
<?php12final class PHUIDiffGraphViewTestCase extends PhabricatorTestCase {34public function testTailTermination() {5$nodes = array(6'A' => array('B'),7'B' => array('C', 'D', 'E'),8'E' => array(),9'D' => array(),10'C' => array('F', 'G'),11'G' => array(),12'F' => array(),13);1415$graph = $this->newGraph($nodes);1617$picture = array(18'^',19'o',20'||x',21'|x ',22'o ',23'|x ',24'x ',25);2627$this->assertGraph($picture, $graph, pht('Terminating Tree'));28}2930public function testReverseTree() {31$nodes = array(32'A' => array('B'),33'C' => array('B'),34'B' => array('D'),35'E' => array('D'),36'F' => array('D'),37'D' => array('G'),38'G' => array(),39);4041$graph = $this->newGraph($nodes);4243$picture = array(44'^',45'|^',46'o ',47'| ^',48'| |^',49'o ',50'x ',51);5253$this->assertGraph($picture, $graph, pht('Reverse Tree'));54}5556public function testJoinTerminateTree() {57$nodes = array(58'A' => array('D'),59'B' => array('C'),60'C' => array('D'),61'D' => array(),62);6364$graph = $this->newGraph($nodes);6566$picture = array(67'^',68'|^',69'|o',70'x ',71);7273$this->assertGraph($picture, $graph, pht('Terminated Tree'));74}7576public function testThreeWayGraphJoin() {77$nodes = array(78'A' => array('D', 'C', 'B'),79'B' => array('D'),80'C' => array('B', 'E', 'F'),81'D' => array(),82'E' => array(),83'F' => array(),84);8586$graph = $this->newGraph($nodes);87$picture = array(88'^',89'||o',90'|o|',91'x| ||',92' | x|',93' | x',94);9596$this->assertGraph($picture, $graph, pht('Three-Way Tree'));97}9899private function newGraph(array $nodes) {100return id(new PHUIDiffGraphView())101->setIsHead(true)102->setIsTail(true)103->renderRawGraph($nodes);104}105106private function assertGraph($picture, $graph, $label) {107list($data, $count) = $graph;108$lines = ipull($data, 'line');109110$picture = implode("\n", $picture);111$lines = implode("\n", $lines);112113$this->assertEqual($picture, $lines, $label);114}115116}117118119