1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Grafizzi\Graph\Tests\IG04Test: a component of the Grafizzi library. |
6
|
|
|
* |
7
|
|
|
* (c) 2012 Frédéric G. MARAND <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Grafizzi is free software: you can redistribute it and/or modify it under the |
10
|
|
|
* terms of the GNU Lesser General Public License as published by the Free |
11
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
12
|
|
|
* later version. |
13
|
|
|
* |
14
|
|
|
* Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY |
15
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
16
|
|
|
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
17
|
|
|
* details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
20
|
|
|
* along with Grafizzi, in the COPYING.LESSER.txt file. If not, see |
21
|
|
|
* <http://www.gnu.org/licenses/> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Grafizzi\Graph\Tests; |
25
|
|
|
|
26
|
|
|
use Grafizzi\Graph\Attribute; |
27
|
|
|
use Grafizzi\Graph\Edge; |
28
|
|
|
use Grafizzi\Graph\Node; |
29
|
|
|
use Grafizzi\Graph\Subgraph; |
30
|
|
|
|
31
|
|
|
require 'vendor/autoload.php'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* A recreation of Image_GraphViz test4.phpt |
35
|
|
|
* |
36
|
|
|
* Image_GraphViz version author: Philippe Jausions <[email protected]> |
37
|
|
|
* |
38
|
|
|
* Test 4: "HTML-like labels" |
39
|
|
|
* |
40
|
|
|
* Note: also tests ports. |
41
|
|
|
*/ |
42
|
|
|
class IG04Test extends BaseGraphTest { |
43
|
|
|
|
44
|
|
|
public function setUp() : void { |
45
|
|
|
parent::setUpExtended('G'); |
|
|
|
|
46
|
|
|
$this->Graph->setDirected(true); |
47
|
|
|
$graph = &$this->Graph; |
48
|
|
|
$dic = $this->dic; |
49
|
|
|
$graph->setAttribute(new Attribute($dic, 'rankdir', 'LR')); |
50
|
|
|
|
51
|
|
|
$graph->addChild($nA = new Node($dic, 'a', array( |
52
|
|
|
new Attribute($dic, 'shape', 'plaintext'), |
53
|
|
|
new Attribute($dic, 'label', '<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> |
54
|
|
|
<TR><TD ROWSPAN="3" BGCOLOR="yellow">class</TD></TR> |
55
|
|
|
<TR><TD PORT="here" BGCOLOR="lightblue">qualifier</TD></TR> |
56
|
|
|
</TABLE>'), |
57
|
|
|
))); |
58
|
|
|
|
59
|
|
|
// Note: subgraph was created after some of its children in Image_GraphViz, |
60
|
|
|
// but Grafizzi lets you only add to existing elements, so it is created |
61
|
|
|
// earlier in this test. |
62
|
|
|
$graph->addChild($subgraph = new Subgraph($dic, 'subgraph', array( |
63
|
|
|
new Attribute($dic, 'title', ''), |
64
|
|
|
new Attribute($dic, 'rank', 'same'), |
65
|
|
|
))); |
66
|
|
|
$subgraph->addChild($nB = new Node($dic, 'b', array( |
67
|
|
|
new Attribute($dic, 'shape', 'ellipse'), |
68
|
|
|
new Attribute($dic, 'style', 'filled'), |
69
|
|
|
new Attribute($dic, 'label', '<TABLE BGCOLOR="bisque"> |
70
|
|
|
<TR><TD COLSPAN="3">elephant</TD> |
71
|
|
|
<TD ROWSPAN="2" BGCOLOR="chartreuse" |
72
|
|
|
VALIGN="bottom" ALIGN="right">two</TD> </TR> |
73
|
|
|
<TR><TD COLSPAN="2" ROWSPAN="2"> |
74
|
|
|
<TABLE BGCOLOR="grey"> |
75
|
|
|
<TR> <TD>corn</TD> </TR> |
76
|
|
|
<TR> <TD BGCOLOR="yellow">c</TD> </TR> |
77
|
|
|
<TR> <TD>f</TD> </TR> |
78
|
|
|
</TABLE> </TD> |
79
|
|
|
<TD BGCOLOR="white">penguin</TD> |
80
|
|
|
</TR> |
81
|
|
|
<TR> <TD COLSPAN="2" BORDER="4" ALIGN="right" PORT="there">4</TD> </TR> |
82
|
|
|
</TABLE> |
83
|
|
|
'), |
84
|
|
|
))); |
85
|
|
|
$subgraph->addChild($nC = new Node($dic, 'c', array( |
86
|
|
|
new Attribute($dic, 'shape', 'plaintext'), |
87
|
|
|
new Attribute($dic, 'label', 'long line 1<BR/>line 2<BR ALIGN="LEFT"/>line 3<BR ALIGN="RIGHT"/>'), |
88
|
|
|
))); |
89
|
|
|
|
90
|
|
|
$graph->addChild($edgeBC = new Edge($dic, $nC, $nB)); |
91
|
|
|
|
92
|
|
|
$graph->addChild($nD = new Node($dic, 'd', array( |
93
|
|
|
new Attribute($dic, 'shape', 'triangle'), |
94
|
|
|
))); |
95
|
|
|
|
96
|
|
|
$graph->addChild($edgeDC = new Edge($dic, $nD, $nC, array( |
97
|
|
|
new Attribute($dic, 'label', '<TABLE> |
98
|
|
|
<TR><TD BGCOLOR="red" WIDTH="10"> </TD> |
99
|
|
|
<TD>Edge labels<BR/>also</TD> |
100
|
|
|
<TD BGCOLOR="blue" WIDTH="10"> </TD> |
101
|
|
|
</TR> |
102
|
|
|
</TABLE>'), |
103
|
|
|
))); |
104
|
|
|
$graph->addChild($edgeAB = new Edge($dic, $nA, $nB, array( |
105
|
|
|
new Attribute($dic, 'arrowtail', 'diamond'), |
106
|
|
|
), 'here', 'there')); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Tests Graph->build() |
111
|
|
|
*/ |
112
|
|
|
public function testBuild() { |
113
|
|
|
$expected = <<<EOT |
114
|
|
|
digraph G { |
115
|
|
|
rankdir=LR; |
116
|
|
|
|
117
|
|
|
a [ shape=plaintext, label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> |
118
|
|
|
<TR><TD ROWSPAN="3" BGCOLOR="yellow">class</TD></TR> |
119
|
|
|
<TR><TD PORT="here" BGCOLOR="lightblue">qualifier</TD></TR> |
120
|
|
|
</TABLE>> ]; |
121
|
|
|
subgraph "subgraph" { |
122
|
|
|
rank=same; |
123
|
|
|
|
124
|
|
|
b [ shape=ellipse, style=filled, label=<<TABLE BGCOLOR="bisque"> |
125
|
|
|
<TR><TD COLSPAN="3">elephant</TD> |
126
|
|
|
<TD ROWSPAN="2" BGCOLOR="chartreuse" |
127
|
|
|
VALIGN="bottom" ALIGN="right">two</TD> </TR> |
128
|
|
|
<TR><TD COLSPAN="2" ROWSPAN="2"> |
129
|
|
|
<TABLE BGCOLOR="grey"> |
130
|
|
|
<TR> <TD>corn</TD> </TR> |
131
|
|
|
<TR> <TD BGCOLOR="yellow">c</TD> </TR> |
132
|
|
|
<TR> <TD>f</TD> </TR> |
133
|
|
|
</TABLE> </TD> |
134
|
|
|
<TD BGCOLOR="white">penguin</TD> |
135
|
|
|
</TR> |
136
|
|
|
<TR> <TD COLSPAN="2" BORDER="4" ALIGN="right" PORT="there">4</TD> </TR> |
137
|
|
|
</TABLE> |
138
|
|
|
> ]; |
139
|
|
|
c [ shape=plaintext, label=<long line 1<BR/>line 2<BR ALIGN="LEFT"/>line 3<BR ALIGN="RIGHT"/>> ]; |
140
|
|
|
} /* /subgraph "subgraph" */ |
141
|
|
|
c -> b; |
142
|
|
|
d [ shape=triangle ]; |
143
|
|
|
d -> c [ label=<<TABLE> |
144
|
|
|
<TR><TD BGCOLOR="red" WIDTH="10"> </TD> |
145
|
|
|
<TD>Edge labels<BR/>also</TD> |
146
|
|
|
<TD BGCOLOR="blue" WIDTH="10"> </TD> |
147
|
|
|
</TR> |
148
|
|
|
</TABLE>> ]; |
149
|
|
|
a:here -> b:there [ arrowtail=diamond ]; |
150
|
|
|
} /* /digraph G */ |
151
|
|
|
|
152
|
|
|
EOT; |
153
|
|
|
$this->check($expected, "Image_GraphViz test 4 passed."); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.