Completed
Push — master ( 0e2bb1...d48330 )
by WEBEWEB
02:01
created

AbstractNavigationNodeTest::testSetIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Tests\Navigation;
13
14
use WBW\Bundle\CoreBundle\Navigation\NavigationInterface;
15
use WBW\Bundle\CoreBundle\Navigation\NavigationNode;
16
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase;
17
use WBW\Bundle\CoreBundle\Tests\Fixtures\Navigation\TestNavigationNode;
18
19
/**
20
 * Abstract navigation node test.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\CoreBundle\Tests\Navigation
24
 */
25
class AbstractNavigationNodeTest extends AbstractTestCase {
26
27
    /**
28
     * Tests the addNode() method.
29
     *
30
     * @return void
31
     */
32
    public function testAddNode(): void {
33
34
        // Set a Navigation node mock.
35
        $node = new TestNavigationNode("node");
36
37
        $obj = new TestNavigationNode("id");
38
39
        $this->assertSame($obj, $obj->addNode($node));
40
        $this->assertEquals([$node], $obj->getNodes());
41
42
        $this->assertSame($obj, $node->getParent());
43
        $this->assertSame($obj, $node->getAlphabeticalTreeNodeParent());
44
    }
45
46
    /**
47
     * Tests the clearNode() method.
48
     *
49
     * @return void
50
     */
51
    public function testClearNode(): void {
52
53
        // Set a Navigation node mock.
54
        $node = new TestNavigationNode("node");
55
56
        $obj = new TestNavigationNode("id");
57
58
        $this->assertSame($obj, $obj->addNode($node));
59
        $this->assertEquals([$node], $obj->getNodes());
60
61
        $this->assertSame($obj, $obj->clearNodes());
62
        $this->assertEquals([], $obj->getNodes());
63
    }
64
65
    /**
66
     * Tests the getFirstNode() method.
67
     *
68
     * @return void
69
     */
70
    public function testGetFirstNode(): void {
71
72
        // Set a Navigation node mock.
73
        $node = new TestNavigationNode("node");
74
75
        $obj = new TestNavigationNode("id");
76
77
        $this->assertSame($obj, $obj->addNode($node));
78
        $this->assertSame($node, $obj->getFirstNode());
79
    }
80
81
    /**
82
     * Tests the getLastNode() method.
83
     *
84
     * @return void
85
     */
86
    public function testGetLastNode(): void {
87
88
        // Set a Navigation node mock.
89
        $node = new TestNavigationNode("node");
90
91
        $obj = new TestNavigationNode("id");
92
93
        $this->assertSame($obj, $obj->addNode($node));
94
        $this->assertSame($node, $obj->getLastNode());
95
    }
96
97
    /**
98
     * Tests the getNodeAt() method.
99
     *
100
     * @return void
101
     */
102
    public function testGetNodeAt(): void {
103
104
        // Set a Navigation node mock.
105
        $node = new TestNavigationNode("node");
106
107
        $obj = new TestNavigationNode("id");
108
109
        $this->assertSame($obj, $obj->addNode($node));
110
        $this->assertNull($obj->getNodeAt(-1));
111
        $this->assertSame($node, $obj->getNodeAt(0));
112
        $this->assertNull($obj->getNodeAt(1));
113
    }
114
115
    /**
116
     * Tests the getNodeById() method.
117
     *
118
     * @return void
119
     */
120
    public function testGetNodeById(): void {
121
122
        // Set the Navigation mocks.
123
        $node1 = new TestNavigationNode("id1");
124
        $node2 = new TestNavigationNode("id2");
125
126
        $obj = new TestNavigationNode("id");
127
        $obj->addNode($node1);
128
129
        $this->assertNull($obj->getNodeById($node2->getId()));
130
        $this->assertNull($obj->getNodeById($node2->getId(), true));
131
132
        $this->assertSame($node1, $obj->getNodeById($node1->getId()));
133
        $this->assertSame($node1, $obj->getNodeById($node1->getId(), true));
134
135
        $node1->addNode($node2);
136
        $this->assertNull($obj->getNodeById($node2->getId()));
137
        $this->assertSame($node2, $obj->getNodeById($node2->getId(), true));
138
    }
139
140
    /**
141
     * Tests the isDisplayable() method.
142
     *
143
     * @return void
144
     */
145
    public function testIsDisplayable(): void {
146
147
        $obj = new TestNavigationNode("id");
148
149
        $this->assertSame($obj, $obj->addNode(new NavigationNode("node")));
150
151
        $this->assertFalse($obj->isDisplayable());
152
153
        $this->assertNotSame($obj, $obj->getLastNode()->setActive(true));
154
        $this->assertNotSame($obj, $obj->getLastNode()->setEnable(true));
155
        $this->assertTrue($obj->isDisplayable());
156
    }
157
158
    /**
159
     * Tests the removeNode() method.
160
     *
161
     * @return void
162
     */
163
    public function testRemoveNode(): void {
164
165
        // Set a Navigation node mock.
166
        $node = new TestNavigationNode("node");
167
168
        $obj = new TestNavigationNode("id");
169
170
        $this->assertSame($obj, $obj->removeNode($node));
171
172
        $this->assertSame($obj, $obj->addNode($node));
173
        $this->assertEquals([$node], $obj->getNodes());
174
175
        $this->assertSame($obj, $obj->removeNode($node));
176
        $this->assertEquals([], $obj->getNodes());
177
    }
178
179
    /**
180
     * Tests the setActive() method.
181
     *
182
     * @return void
183
     */
184
    public function testSetActive(): void {
185
186
        $obj = new TestNavigationNode("id");
187
188
        $obj->setActive(true);
189
        $this->assertTrue($obj->getActive());
190
    }
191
192
    /**
193
     * Tests the setEnable() method.
194
     *
195
     * @return void
196
     */
197
    public function testSetEnable(): void {
198
199
        $obj = new TestNavigationNode("id");
200
201
        $obj->setEnable(true);
202
        $this->assertTrue($obj->getEnable());
203
    }
204
205
    /**
206
     * Tests the setIcon() method.
207
     *
208
     * @return void
209
     */
210
    public function testSetIcon(): void {
211
212
        $obj = new TestNavigationNode("id");
213
214
        $obj->setIcon("icon");
215
        $this->assertEquals("icon", $obj->getIcon());
216
    }
217
218
    /**
219
     * Tests the setMatcher() method.
220
     *
221
     * @return void
222
     */
223
    public function testSetMatcher(): void {
224
225
        $obj = new TestNavigationNode("id");
226
227
        $obj->setMatcher(NavigationInterface::NAVIGATION_MATCHER_ROUTER);
228
        $this->assertEquals(NavigationInterface::NAVIGATION_MATCHER_ROUTER, $obj->getMatcher());
229
    }
230
231
    /**
232
     * Tests the setTarget() method.
233
     *
234
     * @return void
235
     */
236
    public function testSetTarget(): void {
237
238
        $obj = new TestNavigationNode("id");
239
240
        $obj->setTarget("_blank");
241
        $this->assertEquals("_blank", $obj->getTarget());
242
    }
243
244
    /**
245
     * Tests the setUri() method.
246
     *
247
     * @return void
248
     */
249
    public function testSetUri(): void {
250
251
        $obj = new TestNavigationNode("id");
252
253
        $obj->setURI("route");
254
        $this->assertEquals("route", $obj->getUri());
255
    }
256
257
    /**
258
     * Tests the size() method.
259
     *
260
     * @return void
261
     */
262
    public function testSize(): void {
263
264
        // Set a Navigation node mock.
265
        $node = new TestNavigationNode("node");
266
267
        $obj = new TestNavigationNode("id");
268
269
        $this->assertEquals(0, $obj->size());
270
271
        $this->assertSame($obj, $obj->addNode($node));
272
        $this->assertEquals(1, $obj->size());
273
    }
274
275
    /**
276
     * Tests the __construct() method.
277
     *
278
     * @return void
279
     */
280
    public function test__construct(): void {
281
282
        $obj = new TestNavigationNode("id");
283
284
        $this->assertFalse($obj->getActive());
285
        $this->assertNotEquals("", $obj->getAlphabeticalTreeNodeLabel());
286
        $this->assertNull($obj->getAlphabeticalTreeNodeParent());
287
        $this->assertFalse($obj->getEnable());
288
        $this->assertNull($obj->getFirstNode());
289
        $this->assertNull($obj->getIcon());
290
        $this->assertNotEquals("", $obj->getId());
291
        $this->assertEquals("id", $obj->getLabel());
292
        $this->assertNull($obj->getLastNode());
293
        $this->assertEquals(NavigationInterface::NAVIGATION_MATCHER_URL, $obj->getMatcher());
294
        $this->assertEquals([], $obj->getNodes());
295
        $this->assertNull($obj->getParent());
296
        $this->assertNull($obj->getTarget());
297
        $this->assertNull($obj->getUri());
298
        $this->assertTrue($obj->getVisible());
299
    }
300
}
301