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
|
|
|
* |
15
|
|
|
* @author Sebastian Schmid (gesinn.it) |
16
|
|
|
*/ |
17
|
|
|
class GraphFormatterTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
/* |
20
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Help:Graph_format |
21
|
|
|
*/ |
22
|
|
|
private $options; |
23
|
|
|
|
24
|
|
|
private $graphFormatter; |
25
|
|
|
|
26
|
|
|
private $nodes = []; |
27
|
|
|
|
28
|
|
|
protected function setUp() { |
29
|
|
|
parent::setUp(); |
30
|
|
|
|
31
|
|
|
$this->options->graphName = 'Unit Test'; |
32
|
|
|
$this->options->graphSize = '100'; |
33
|
|
|
$this->options->nodeShape = 'rect'; |
34
|
|
|
$this->options->nodeLabel = 'displaytitle'; |
35
|
|
|
$this->options->rankDir = 'TB'; |
36
|
|
|
$this->options->wordWrapLimit = '20'; |
37
|
|
|
$this->options->parentRelation = 'parent'; |
38
|
|
|
$this->options->enableGraphLink = 'yes'; |
39
|
|
|
$this->options->showGraphLabel = 'yes'; |
40
|
|
|
$this->options->showGraphColor = 'yes'; |
41
|
|
|
$this->options->showGraphLegend = 'yes'; |
42
|
|
|
|
43
|
|
|
$this->graphFormatter = new GraphFormatter( $this->options ); |
44
|
|
|
|
45
|
|
|
$this->nodes = []; |
46
|
|
|
|
47
|
|
|
$node1 = new GraphNode( 'Team:Alpha' ); |
48
|
|
|
$node1->setLabel( "Alpha" ); |
49
|
|
|
$node1->addParentNode( "Casted", "Person:Alexander Gesinn" ); |
50
|
|
|
$this->nodes[] = $node1; |
51
|
|
|
|
52
|
|
|
$node2 = new GraphNode( 'Team:Beta' ); |
53
|
|
|
$node2->setLabel( "Beta" ); |
54
|
|
|
$node2->addParentNode( "Casted", "Person:Sebastian Schmid" ); |
55
|
|
|
$node2->addParentNode( "Casted", "Person:Alexander Gesinn" ); |
56
|
|
|
$node2->addParentNode( "Part of Team ", "Team:Alpha" ); |
57
|
|
|
$this->nodes[] = $node2; |
58
|
|
|
|
59
|
|
|
$this->graphFormatter->buildGraph( $this->nodes ); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testCanConstruct() { |
63
|
|
|
$this->assertInstanceOf( GraphFormatter::class, new GraphFormatter( $this->options ) ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetWordWrappedText() { |
67
|
|
|
$text = 'Lorem ipsum dolor sit amet'; |
68
|
|
|
$expected = 'Lorem \nipsum \ndolor sit \namet'; |
69
|
|
|
|
70
|
|
|
$this->assertEquals( GraphFormatter::getWordWrappedText( $text, 10 ), $expected ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testGetGraphLegend() { |
74
|
|
|
$expected = "<div class=\"graphlegend\">". |
75
|
|
|
"<div class=\"graphlegenditem\" style=\"color: black\">black: Casted</div>". |
76
|
|
|
"<div class=\"graphlegenditem\" style=\"color: red\">red: Part of Team </div>". |
77
|
|
|
"</div>"; |
78
|
|
|
|
79
|
|
|
$this->assertEquals( $this->graphFormatter->getGraphLegend(), $expected ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testBuildGraph(){ |
83
|
|
|
$expected = "digraph Unit Test {graph [fontsize=10, fontname=\"Verdana\"]\n". |
84
|
|
|
"node [fontsize=10, fontname=\"Verdana\"];\n". |
85
|
|
|
"edge [fontsize=10, fontname=\"Verdana\"];\n". |
86
|
|
|
"size=\"100\";node [shape=rect];rankdir=TB;". |
87
|
|
|
"\"Team:Alpha\" [URL = \"[[Team:Alpha]]\", label = \"Alpha\"]; ". |
88
|
|
|
"\"Team:Beta\" [URL = \"[[Team:Beta]]\", label = \"Beta\"]; ". |
89
|
|
|
"\"Person:Alexander Gesinn\" -> \"Team:Alpha\" [label=\"Casted\",fontcolor=black,color=black]; ". |
90
|
|
|
"\"Person:Sebastian Schmid\" -> \"Team:Beta\" [label=\"Casted\",fontcolor=black,color=black]; ". |
91
|
|
|
"\"Person:Alexander Gesinn\" -> \"Team:Beta\" [label=\"Casted\",fontcolor=black,color=black]; ". |
92
|
|
|
"\"Team:Alpha\" -> \"Team:Beta\" [label=\"Part of Team \",fontcolor=red,color=red];}"; |
93
|
|
|
|
94
|
|
|
$this->assertEquals( $this->graphFormatter->getGraph(), $expected); |
95
|
|
|
} |
96
|
|
|
} |
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: