ItemListTest::canAddMultipleItems()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
namespace CarlosIO\Geckoboard\Tests\Widgets;
4
5
use CarlosIO\Geckoboard\Data\ItemList\Label;
6
use CarlosIO\Geckoboard\Data\ItemList\Title;
7
use CarlosIO\Geckoboard\Widgets\ItemList;
8
9
class ItemListTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @test
13
     */
14
    public function getDataWithNoItems()
15
    {
16
        $widget = new ItemList();
17
18
        $json = json_encode($widget->getData());
19
        $this->assertEquals('[]', $json);
20
    }
21
22
    /**
23
     * @test
24
     */
25
    public function canAddSingleItem()
26
    {
27
        $widget = new ItemList();
28
29
        $title = new Title();
30
        $title->setText('Title text');
31
        $title->setHighlight(true);
32
33
        $label = new Label();
34
        $label->setName('Label name');
35
        $label->setColor('red');
36
37
        $widget->addItem($title, $label, 'description');
38
        $json = json_encode($widget->getData());
39
        $this->assertEquals('[{"title":{"text":"Title text","highlight":true},"label":{"name":"Label name","color":"red"},"description":"description"}]', $json);
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function canAddMultipleItems()
46
    {
47
        $widget = new ItemList();
48
49
        $title = new Title();
50
        $title->setText('Title text');
51
        $title->setHighlight(true);
52
53
        $title2 = new Title();
54
        $title2->setText('Title2 text');
55
        $title2->setHighlight(false);
56
57
        $label = new Label();
58
        $label->setName('Label name');
59
        $label->setColor('red');
60
61
        $label2 = new Label();
62
        $label2->setName('Label2 name');
63
        $label2->setColor('blue');
64
65
        $widget->addItem($title, $label, 'description1');
66
        $widget->addItem($title2, $label2, 'description2');
67
        $json = json_encode($widget->getData());
68
        $this->assertEquals('[{"title":{"text":"Title text","highlight":true},"label":{"name":"Label name","color":"red"},"description":"description1"},{"title":{"text":"Title2 text","highlight":false},"label":{"name":"Label2 name","color":"blue"},"description":"description2"}]', $json);
69
    }
70
71
    /**
72
     * @test
73
     */
74
    public function canHaveNoLabel()
75
    {
76
        $widget = new ItemList();
77
78
        $title = new Title();
79
        $title->setText('Title text');
80
        $title->setHighlight(true);
81
82
        $widget->addItem($title, null, 'description');
83
        $json = json_encode($widget->getData());
84
        $this->assertEquals('[{"title":{"text":"Title text","highlight":true},"description":"description"}]', $json);
85
    }
86
}
87