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
|
|
|
'graphName' => "Unit Test", |
24
|
|
|
'graphSize' => "100", |
25
|
|
|
'nodeShape' => "rect", |
26
|
|
|
'nodeLabel' => "displaytitle", |
27
|
|
|
'rankDir' => "TB", |
28
|
|
|
'wordWrapLimit' => "20", |
29
|
|
|
'parentRelation' => "parent", |
30
|
|
|
'enableGraphLink' => "yes", |
31
|
|
|
'showGraphLabel' => "yes", |
32
|
|
|
'showGraphColor' => "yes", |
33
|
|
|
'showGraphLegend' => "yes", |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
private $graphFormatter; |
37
|
|
|
|
38
|
|
|
private $nodes = []; |
39
|
|
|
|
40
|
|
|
protected function setUp() { |
41
|
|
|
parent::setUp(); |
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 = |
75
|
|
|
'<div class="graphlegend"><div class="graphlegenditem" style="color: black">black: Casted</div><div class="graphlegenditem" style="color: red">red: Part of Team </div></div>'; |
76
|
|
|
|
77
|
|
|
$this->assertEquals( $this->graphFormatter->getGraphLegend(), $expected ); |
78
|
|
|
} |
79
|
|
|
} |
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: