@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PHUIDiffGraphViewTestCase extends PhabricatorTestCase {
4
5 public function testTailTermination() {
6 $nodes = array(
7 'A' => array('B'),
8 'B' => array('C', 'D', 'E'),
9 'E' => array(),
10 'D' => array(),
11 'C' => array('F', 'G'),
12 'G' => array(),
13 'F' => array(),
14 );
15
16 $graph = $this->newGraph($nodes);
17
18 $picture = array(
19 '^',
20 'o',
21 '||x',
22 '|x ',
23 'o ',
24 '|x ',
25 'x ',
26 );
27
28 $this->assertGraph($picture, $graph, pht('Terminating Tree'));
29 }
30
31 public function testReverseTree() {
32 $nodes = array(
33 'A' => array('B'),
34 'C' => array('B'),
35 'B' => array('D'),
36 'E' => array('D'),
37 'F' => array('D'),
38 'D' => array('G'),
39 'G' => array(),
40 );
41
42 $graph = $this->newGraph($nodes);
43
44 $picture = array(
45 '^',
46 '|^',
47 'o ',
48 '| ^',
49 '| |^',
50 'o ',
51 'x ',
52 );
53
54 $this->assertGraph($picture, $graph, pht('Reverse Tree'));
55 }
56
57 public function testJoinTerminateTree() {
58 $nodes = array(
59 'A' => array('D'),
60 'B' => array('C'),
61 'C' => array('D'),
62 'D' => array(),
63 );
64
65 $graph = $this->newGraph($nodes);
66
67 $picture = array(
68 '^',
69 '|^',
70 '|o',
71 'x ',
72 );
73
74 $this->assertGraph($picture, $graph, pht('Terminated Tree'));
75 }
76
77 public function testThreeWayGraphJoin() {
78 $nodes = array(
79 'A' => array('D', 'C', 'B'),
80 'B' => array('D'),
81 'C' => array('B', 'E', 'F'),
82 'D' => array(),
83 'E' => array(),
84 'F' => array(),
85 );
86
87 $graph = $this->newGraph($nodes);
88 $picture = array(
89 '^',
90 '||o',
91 '|o|',
92 'x| ||',
93 ' | x|',
94 ' | x',
95 );
96
97 $this->assertGraph($picture, $graph, pht('Three-Way Tree'));
98 }
99
100 private function newGraph(array $nodes) {
101 return id(new PHUIDiffGraphView())
102 ->setIsHead(true)
103 ->setIsTail(true)
104 ->renderRawGraph($nodes);
105 }
106
107 private function assertGraph($picture, $graph, $label) {
108 list($data, $count) = $graph;
109 $lines = ipull($data, 'line');
110
111 $picture = implode("\n", $picture);
112 $lines = implode("\n", $lines);
113
114 $this->assertEqual($picture, $lines, $label);
115 }
116
117}