Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

Tests/unit/Helper/Menu/MenuItemTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\Helper\Menu;
4
5
use Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder;
6
use Kunstmaan\AdminBundle\Helper\Menu\MenuItem;
7
use Kunstmaan\AdminBundle\Helper\Menu\TopMenuItem;
8
use PHPUnit\Framework\TestCase;
9
10
class MenuItemTest extends TestCase
11
{
12
    /**
13
     * @var MenuItem
14
     */
15
    protected $object;
16
17
    /**
18
     * Sets up the fixture, for example, opens a network connection.
19
     * This method is called before a test is executed.
20
     */
21
    protected function setUp()
22
    {
23
        /* @var $menuBuilder MenuBuilder */
24
        $menuBuilder = $this->getMockBuilder('Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder')
25
            ->disableOriginalConstructor()
26
            ->getMock();
27
28
        $this->object = new MenuItem($menuBuilder);
29
    }
30
31
    public function testGetMenu()
32
    {
33
        /* @var $menuBuilder MenuBuilder */
34
        $menuBuilder = $this->getMockBuilder('Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder')
35
            ->disableOriginalConstructor()
36
            ->getMock();
37
38
        $object = new MenuItem($menuBuilder);
39
        $this->assertEquals($menuBuilder, $object->getMenu());
40
    }
41
42
    public function testGetSetLabel()
43
    {
44
        $this->object->setLabel('label');
45
        $this->assertEquals('label', $this->object->getLabel());
46
    }
47
48
    public function testGetSetUniqueId()
49
    {
50
        $this->object->setUniqueId('uniqueId');
51
        $this->assertEquals('uniqueId', $this->object->getUniqueId());
52
    }
53
54
    public function testGetSetRole()
55
    {
56
        $this->object->setRole('ROLE_CUSTOM');
57
        $this->assertEquals('ROLE_CUSTOM', $this->object->getRole());
58
    }
59
60
    public function testGetSetChildren()
61
    {
62
        $this->object->setChildren(['test' => 'ok']);
63
        $this->assertNotEmpty($this->object->getChildren());
64
        $this->assertNotNull($this->object->getChildren()['test']);
65
    }
66
67 View Code Duplication
    public function testGetSetOffline()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $this->object->setOffline(true);
70
        $this->assertTrue($this->object->getOffline());
71
        $this->object->setOffline(false);
72
        $this->assertFalse($this->object->getOffline());
73
        $this->object->setOffline(true);
74
        $this->assertTrue($this->object->getOffline());
75
    }
76
77 View Code Duplication
    public function testGetSetFolder()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $this->object->setFolder(true);
80
        $this->assertTrue($this->object->getFolder());
81
        $this->object->setFolder(false);
82
        $this->assertFalse($this->object->getFolder());
83
        $this->object->setFolder(true);
84
        $this->assertTrue($this->object->getFolder());
85
    }
86
87
    public function testGetSetParent()
88
    {
89
        /* @var $menuBuilder MenuBuilder */
90
        $menuBuilder = $this->getMockBuilder('Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder')
91
            ->disableOriginalConstructor()
92
            ->getMock();
93
        $parent = new MenuItem($menuBuilder);
94
        $this->object->setParent($parent);
95
        $this->assertEquals($parent, $this->object->getParent());
96
    }
97
98
    public function testGetSetRoute()
99
    {
100
        $params = array('id' => 5);
101
        $this->object->setRoute('ARoute', $params);
102
103
        $this->assertEquals('ARoute', $this->object->getRoute());
104
        $this->assertEquals($params, $this->object->getRouteParams());
105
    }
106
107
    public function testGetSetRouteParams()
108
    {
109
        $params = array('id' => 1);
110
        $this->object->setRouteParams($params);
111
        $this->assertEquals($params, $this->object->getRouteParams());
112
    }
113
114 View Code Duplication
    public function testGetChildren()
115
    {
116
        $child1 = new MenuItem($this->object->getMenu());
117
        $child1->setAppearInNavigation(true);
118
        $child2 = new MenuItem($this->object->getMenu());
119
        $child2->setAppearInNavigation(true);
120
        $children = array($child1, $child2);
121
122
        $menuBuilder = $this->getMockBuilder('Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder')
123
            ->disableOriginalConstructor()
124
            ->getMock();
125
        $menuBuilder->expects($this->once())
126
            ->method('getChildren')
127
            ->will($this->returnValue($children));
128
129
        /* @var $menuBuilder MenuBuilder */
130
        $parent = new MenuItem($menuBuilder);
131
        $result = $parent->getChildren();
132
        $this->assertEquals(2, count($result));
133
        $this->assertEquals($children, $result);
134
    }
135
136 View Code Duplication
    public function testGetNavigationChildren()
137
    {
138
        $child1 = new MenuItem($this->object->getMenu());
139
        $child1->setAppearInNavigation(true);
140
        $child2 = new MenuItem($this->object->getMenu());
141
        $child2->setAppearInNavigation(false);
142
        $children = array($child1, $child2);
143
144
        $menuBuilder = $this->getMockBuilder('Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder')
145
            ->disableOriginalConstructor()
146
            ->getMock();
147
        $menuBuilder->expects($this->once())
148
            ->method('getChildren')
149
            ->will($this->returnValue($children));
150
151
        /* @var $menuBuilder MenuBuilder */
152
        $parent = new MenuItem($menuBuilder);
153
        $result = $parent->getNavigationChildren();
154
        $this->assertEquals(1, count($result));
155
        $this->assertEquals(array($child1), $result);
156
    }
157
158
    public function testGetTopChildren()
159
    {
160
        $child1 = new MenuItem($this->object->getMenu());
161
        $child2 = new TopMenuItem($this->object->getMenu());
162
        $children = array($child1, $child2);
163
164
        $menuBuilder = $this->getMockBuilder('Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder')
165
            ->disableOriginalConstructor()
166
            ->getMock();
167
        $menuBuilder->expects($this->once())
168
            ->method('getChildren')
169
            ->will($this->returnValue($children));
170
171
        /* @var $menuBuilder MenuBuilder */
172
        $parent = new MenuItem($menuBuilder);
173
        $result = $parent->getTopChildren();
174
        $this->assertEquals(1, count($result));
175
        $this->assertEquals(array($child2), $result);
176
    }
177
178
    public function testAddGetAttributes()
179
    {
180
        $attributes = array('attribute1' => 1, 'attribute2' => 2);
181
        $this->object->addAttributes($attributes);
182
        $this->assertEquals($attributes, $this->object->getAttributes());
183
    }
184
185
    public function testGetSetActive()
186
    {
187
        $this->object->setActive(true);
188
        $this->assertTrue($this->object->getActive());
189
    }
190
191
    public function testGetSetAppearInNavigation()
192
    {
193
        $this->object->setAppearInNavigation(true);
194
        $this->assertTrue($this->object->getAppearInNavigation());
195
    }
196
197
    public function testGetSetWeight()
198
    {
199
        $this->object->setWeight(10);
200
        $this->assertEquals(10, $this->object->getWeight());
201
    }
202
}
203