1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SRF\Tests\Unit\Formats; |
4
|
|
|
|
5
|
|
|
use SRF\Graph\GraphFormatter; |
6
|
|
|
use SRF\Graph\GraphNode; |
7
|
|
|
use SRF\Graph\GraphOptions; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \SRF\Graph\GraphFormatter |
12
|
|
|
* @group semantic-result-formats |
13
|
|
|
* |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* |
16
|
|
|
* @author Sebastian Schmid (gesinn.it) |
17
|
|
|
*/ |
18
|
|
|
class GraphFormatterTest extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
/* |
21
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Help:Graph_format |
22
|
|
|
*/ |
23
|
|
|
private $options; |
24
|
|
|
|
25
|
|
|
private $graphFormatter; |
26
|
|
|
|
27
|
|
|
private $nodes = []; |
28
|
|
|
|
29
|
|
|
protected function setUp() { |
30
|
|
|
parent::setUp(); |
31
|
|
|
|
32
|
|
|
$params = [ |
33
|
|
|
'graphname' => 'Unit Test', |
34
|
|
|
'graphsize' => '100', |
35
|
|
|
'nodeshape' => 'rect', |
36
|
|
|
'nodelabel' => 'displaytitle', |
37
|
|
|
'arrowdirection' => 'LR', |
38
|
|
|
'wordwraplimit' => 20, |
39
|
|
|
'relation' => 'parent', |
40
|
|
|
'graphlink' => true, |
41
|
|
|
'graphlabel' => true, |
42
|
|
|
'graphcolor' => true, |
43
|
|
|
'graphlegend' => true, |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
$this->options = new GraphOptions($params); |
47
|
|
|
|
48
|
|
|
$this->graphFormatter = new GraphFormatter( $this->options ); |
49
|
|
|
|
50
|
|
|
$node1 = new GraphNode( 'Team:Alpha' ); |
51
|
|
|
$node1->setLabel( "Alpha" ); |
52
|
|
|
$node1->addParentNode( "Casted", "Person:Alexander Gesinn" ); |
53
|
|
|
$this->nodes[] = $node1; |
54
|
|
|
|
55
|
|
|
$node2 = new GraphNode( 'Team:Beta' ); |
56
|
|
|
$node2->setLabel( "Beta" ); |
57
|
|
|
$node2->addParentNode( "Casted", "Person:Sebastian Schmid" ); |
58
|
|
|
$node2->addParentNode( "Casted", "Person:Alexander Gesinn" ); |
59
|
|
|
$node2->addParentNode( "Part of Team ", "Team:Alpha" ); |
60
|
|
|
$this->nodes[] = $node2; |
61
|
|
|
|
62
|
|
|
$this->graphFormatter->buildGraph( $this->nodes ); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testCanConstruct() { |
66
|
|
|
$this->assertInstanceOf( GraphFormatter::class, new GraphFormatter( $this->options ) ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetWordWrappedText() { |
70
|
|
|
$text = 'Lorem ipsum dolor sit amet'; |
71
|
|
|
$expected = 'Lorem \nipsum \ndolor sit \namet'; |
72
|
|
|
|
73
|
|
|
$this->assertEquals( GraphFormatter::getWordWrappedText( $text, 10 ), $expected ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testGetGraphLegend() { |
77
|
|
|
$expected = "<div class=\"graphlegend\">". |
78
|
|
|
"<div class=\"graphlegenditem\" style=\"color: black\">black: Casted</div>". |
79
|
|
|
"<div class=\"graphlegenditem\" style=\"color: red\">red: Part of Team </div>". |
80
|
|
|
"</div>"; |
81
|
|
|
|
82
|
|
|
$this->assertEquals( $this->graphFormatter->getGraphLegend(), $expected ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testBuildGraph(){ |
86
|
|
|
$expected = "digraph Unit Test {graph [fontsize=10, fontname=\"Verdana\"]\n". |
87
|
|
|
"node [fontsize=10, fontname=\"Verdana\"];\n". |
88
|
|
|
"edge [fontsize=10, fontname=\"Verdana\"];\n". |
89
|
|
|
"size=\"100\";node [shape=rect];rankdir=LR;". |
90
|
|
|
"\"Team:Alpha\" [URL = \"[[Team:Alpha]]\", label = \"Alpha\"]; ". |
91
|
|
|
"\"Team:Beta\" [URL = \"[[Team:Beta]]\", label = \"Beta\"]; ". |
92
|
|
|
"\"Person:Alexander Gesinn\" -> \"Team:Alpha\" [label=\"Casted\",fontcolor=black,color=black]; ". |
93
|
|
|
"\"Person:Sebastian Schmid\" -> \"Team:Beta\" [label=\"Casted\",fontcolor=black,color=black]; ". |
94
|
|
|
"\"Person:Alexander Gesinn\" -> \"Team:Beta\" [label=\"Casted\",fontcolor=black,color=black]; ". |
95
|
|
|
"\"Team:Alpha\" -> \"Team:Beta\" [label=\"Part of Team \",fontcolor=red,color=red];}"; |
96
|
|
|
|
97
|
|
|
$this->assertEquals( $this->graphFormatter->getGraph(), $expected); |
98
|
|
|
} |
99
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: