1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SRF\Tests\Unit\Formats; |
4
|
|
|
|
5
|
|
|
use SRF\Graph\GraphFormatter; |
6
|
|
|
use SRF\Graph\GraphNode; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \SRF\Graph\GraphFormatter |
11
|
|
|
* @group semantic-result-formats |
12
|
|
|
* |
13
|
|
|
* @license GNU GPL v2+ |
14
|
|
|
* @since 3.1 |
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
|
|
|
|
24
|
|
|
private $options = [ |
25
|
|
|
'graphName' => "Unit Test", |
26
|
|
|
'graphSize' => "100", |
27
|
|
|
'nodeShape' => "rect", |
28
|
|
|
'nodeLabel' => "displaytitle", |
29
|
|
|
'rankDir' => "TB", |
30
|
|
|
'wordWrapLimit' => "20", |
31
|
|
|
'parentRelation' => "parent", |
32
|
|
|
'enableGraphLink' => "yes", |
33
|
|
|
'showGraphLabel' => "yes", |
34
|
|
|
'showGraphColor' => "yes", |
35
|
|
|
'showGraphLegend' => "yes", |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
private $graphFormatter; |
39
|
|
|
|
40
|
|
|
private $nodes = []; |
41
|
|
|
|
42
|
|
|
protected function setUp() { |
43
|
|
|
parent::setUp(); |
44
|
|
|
|
45
|
|
|
$this->graphFormatter = new GraphFormatter( $this->options ); |
46
|
|
|
|
47
|
|
|
$this->nodes = []; |
48
|
|
|
|
49
|
|
|
$node1 = new GraphNode( 'Team:Alpha' ); |
50
|
|
|
$node1->setLabel( "Alpha" ); |
51
|
|
|
$node1->addParentNode( "Casted", "Person:Alexander Gesinn" ); |
52
|
|
|
$this->nodes[] = $node1; |
53
|
|
|
|
54
|
|
|
$node2 = new GraphNode( 'Team:Beta' ); |
55
|
|
|
$node2->setLabel( "Beta" ); |
56
|
|
|
$node2->addParentNode( "Casted", "Person:Sebastian Schmid" ); |
57
|
|
|
$node2->addParentNode( "Casted", "Person:Alexander Gesinn" ); |
58
|
|
|
$node2->addParentNode( "Part of Team ", "Team:Alpha" ); |
59
|
|
|
$this->nodes[] = $node2; |
60
|
|
|
|
61
|
|
|
$this->graphFormatter->buildGraph( $this->nodes ); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testCanConstruct() { |
65
|
|
|
$this->assertInstanceOf( GraphFormatter::class, new GraphFormatter( $this->options ) ); |
66
|
|
|
} |
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 = |
78
|
|
|
'<div class="graphlegend"><div class="graphlegenditem" style="color: black">black: Casted</div><div class="graphlegenditem" style="color: red">red: Part of Team </div></div>'; |
79
|
|
|
|
80
|
|
|
$this->assertEquals( $this->graphFormatter->getGraphLegend(), $expected ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/* |
85
|
|
|
public function testBuildGraph() { |
86
|
|
|
$expected = "digraph Unit Test {graph [fontsize=10, fontname=\"Verdana\"]\nnode [fontsize=10, fontname=\"Verdana\"];\nedge [fontsize=10, fontname=\"Verdana\"];\nsize=\"100\";node [shape=rect];rankdir=TB;\"Team:Alpha\" [URL = \"[[Team:Alpha]]\", label = \"Alpha\"]; \"Team:Beta\" [URL = \"[[Team:Beta]]\", label = \"Beta\"]; \"Person:Alexander Gesinn\" -> \"Team:Alpha\" [label=\"Casted\",fontcolor=black,color=black]; \"Person:Sebastian Schmid\" -> \"Team:Beta\" [label=\"Casted\",fontcolor=black,color=black]; \"Person:Alexander Gesinn\" -> \"Team:Beta\" [label=\"Casted\",fontcolor=black,color=black]; \"Team:Alpha\" -> \"Team:Beta\" [label=\"Part of Team \",fontcolor=red,color=red];}\n"; |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
print('----------actual------------'); |
90
|
|
|
print($this->graphFormatter->getGraph()); |
91
|
|
|
print('-------------'); |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
print('------expected-------'); |
95
|
|
|
print($expected); |
96
|
|
|
print('-------------'); |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
$this->assertEquals( $this->graphFormatter->getGraph(), $expected ); |
100
|
|
|
} |
101
|
|
|
*/ |
102
|
|
|
} |
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: