|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Grafizzi\Graph\Tests\DotFilterTest: 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
|
|
|
require 'vendor/autoload.php'; |
|
27
|
|
|
|
|
28
|
|
|
use Grafizzi\Graph\Filter\DotFilter; |
|
29
|
|
|
use Pimple\Container; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* DotFilter test case. |
|
33
|
|
|
*/ |
|
34
|
|
|
class DotFilterTest extends BaseFilterTest { |
|
35
|
|
|
|
|
36
|
|
|
const INVALID_FORMAT = 'some unlikely to be valid format'; |
|
37
|
|
|
/** |
|
38
|
|
|
* File to copy to. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
private $out = null; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Prepares the environment before running a test. |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function setUp() : void { |
|
48
|
|
|
parent::setUp(); |
|
49
|
|
|
$dotFilter = new DotFilter(); |
|
50
|
|
|
$dotFilter->setDic(new Container()); |
|
51
|
|
|
$this->filters[] = $dotFilter; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Tests DotFilter->filter() |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testFilter() { |
|
58
|
|
|
$in = 'digraph G { foo -> bar ; }'; |
|
59
|
|
|
list($out, ) = $this->filters[0]->filter($in); |
|
60
|
|
|
$this->assertIsString($out, 'Dot filter returns string output'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testImageHappy() { |
|
64
|
|
|
/** @var \Grafizzi\Graph\Filter\DotFilter $filter */ |
|
65
|
|
|
$filter = reset($this->filters); |
|
66
|
|
|
$this->assertEmpty($filter->formats, "Filter formats is initially null"); |
|
67
|
|
|
$this->assertEquals(0, count($filter->formats), "Filter formats list is initially empty"); |
|
68
|
|
|
|
|
69
|
|
|
$image = $filter->image('svg'); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertIsArray($filter->formats, "Filter formats is an array"); |
|
72
|
|
|
$this->assertTrue(count($filter->formats) >= 1, "There is at least one format available from the DotFilter."); |
|
73
|
|
|
|
|
74
|
|
|
// TODO check actual image generation once it is actually performed. |
|
75
|
|
|
$this->assertTrue($image, 'Image generation succeeds.'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testImageSadFormatNoException() { |
|
79
|
|
|
/** @var \Grafizzi\Graph\Filter\DotFilter $filter */ |
|
80
|
|
|
$filter = reset($this->filters); |
|
81
|
|
|
|
|
82
|
|
|
$image = $filter->image(self::INVALID_FORMAT); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertEmpty($image, "Image is not generated when the image format is invalid"); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testImageSadFormatException() { |
|
88
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
89
|
|
|
/** @var \Grafizzi\Graph\Filter\DotFilter $filter */ |
|
90
|
|
|
$filter = new DotFilter(); |
|
91
|
|
|
$dic = new Container(); |
|
92
|
|
|
$dic['use_exceptions'] = TRUE; |
|
93
|
|
|
$filter->setDic($dic); |
|
94
|
|
|
|
|
95
|
|
|
$filter->image(self::INVALID_FORMAT); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|