Completed
Push — master ( e1a919...c5c436 )
by Ruud
28:05 queued 15:36
created

Tests/unit/Helper/Menu/MenuItemTest.php (1 issue)

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