|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CarlosIO\Geckoboard\Tests\Widgets; |
|
4
|
|
|
|
|
5
|
|
|
use CarlosIO\Geckoboard\Widgets\LineChart; |
|
6
|
|
|
|
|
7
|
|
|
class LineChartTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Test with an empty dataset. |
|
11
|
|
|
*/ |
|
12
|
|
|
public function testJsonForAnEmptyData() |
|
13
|
|
|
{ |
|
14
|
|
|
$widget = new LineChart(); |
|
15
|
|
|
$json = json_encode($widget->getData()); |
|
16
|
|
|
$this->assertJsonStringEqualsJsonString('{"item":[], "settings": {"axisx": [], "axisy": [], "colour": "ff9900"} }', $json); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Test with a full dataset. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testJsonWithValidData() |
|
23
|
|
|
{ |
|
24
|
|
|
$widget = new LineChart(); |
|
25
|
|
|
$widget->setItems(array(1, 1.23)); |
|
26
|
|
|
$widget->setColour('ff0000'); |
|
27
|
|
|
$widget->setAxis(LineChart::DIMENSION_X, array('min', 'max')); |
|
28
|
|
|
$widget->setAxis(LineChart::DIMENSION_Y, array('bottom', 'top')); |
|
29
|
|
|
|
|
30
|
|
|
$current = json_encode($widget->getData()); |
|
31
|
|
|
$expected = <<<EOF |
|
32
|
|
|
{ "item": [ "1", "1.23"], |
|
33
|
|
|
"settings" : { |
|
34
|
|
|
"axisx" : [ "min", "max" ], |
|
35
|
|
|
"axisy" : [ "bottom", "top" ], |
|
36
|
|
|
"colour": "ff0000" |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
EOF; |
|
40
|
|
|
$this->assertJsonStringEqualsJsonString($expected, $current); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @expectedException InvalidArgumentException |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testThrowsExceptionOnInvalidColour() |
|
47
|
|
|
{ |
|
48
|
|
|
$widget = new LineChart(); |
|
49
|
|
|
$widget->setColour('invalid'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @expectedException InvalidArgumentException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testThrowsExceptionOnInvalidItems() |
|
56
|
|
|
{ |
|
57
|
|
|
$widget = new LineChart(); |
|
58
|
|
|
$widget->setItems(array('foo', 'bar')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @expectedException InvalidArgumentException |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testThrowsExceptionOnInvalidAxisDimension() |
|
65
|
|
|
{ |
|
66
|
|
|
$widget = new LineChart(); |
|
67
|
|
|
$widget->setAxis('z', array('foo', 'bar')); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|