@@ -85,6 +85,11 @@ public function assertNodeRecievesValidValues($node)
85
85
);
86
86
}
87
87
88
+ /**
89
+ * @param $name
90
+ *
91
+ * @return \Kalnoy\Nestedset\Node
92
+ */
88
93
public function findCategory ($ name )
89
94
{
90
95
return Category::whereName ($ name )->first ();
@@ -93,6 +98,7 @@ public function findCategory($name)
93
98
public function testTreeNotBroken ()
94
99
{
95
100
$ this ->assertTreeNotBroken ();
101
+ $ this ->assertFalse (Category::isBroken ());
96
102
}
97
103
98
104
public function nodeValues ($ node )
@@ -123,9 +129,11 @@ public function testRecievesValidValuesWhenAppendedTo()
123
129
124
130
$ root ->append ($ node );
125
131
132
+ $ this ->assertTrue ($ node ->hasMoved ());
126
133
$ this ->assertEquals ($ accepted , $ this ->nodeValues ($ node ));
127
134
$ this ->assertTreeNotBroken ();
128
135
$ this ->assertFalse ($ node ->isDirty ());
136
+ $ this ->assertTrue ($ node ->isDescendantOf ($ root ));
129
137
}
130
138
131
139
public function testRecievesValidValuesWhenPrependedTo ()
@@ -134,8 +142,10 @@ public function testRecievesValidValuesWhenPrependedTo()
134
142
$ node = new Category ([ 'name ' => 'test ' ]);
135
143
$ root ->prepend ($ node );
136
144
145
+ $ this ->assertTrue ($ node ->hasMoved ());
137
146
$ this ->assertEquals (array ($ root ->_lft + 1 , $ root ->_lft + 2 , $ root ->id ), $ this ->nodeValues ($ node ));
138
147
$ this ->assertTreeNotBroken ();
148
+ $ this ->assertTrue ($ node ->isDescendantOf ($ root ));
139
149
}
140
150
141
151
public function testRecievesValidValuesWhenInsertedAfter ()
@@ -144,6 +154,7 @@ public function testRecievesValidValuesWhenInsertedAfter()
144
154
$ node = new Category ([ 'name ' => 'test ' ]);
145
155
$ node ->after ($ target )->save ();
146
156
157
+ $ this ->assertTrue ($ node ->hasMoved ());
147
158
$ this ->assertEquals (array ($ target ->_rgt + 1 , $ target ->_rgt + 2 , $ target ->parent ->id ), $ this ->nodeValues ($ node ));
148
159
$ this ->assertTreeNotBroken ();
149
160
$ this ->assertFalse ($ node ->isDirty ());
@@ -155,6 +166,7 @@ public function testRecievesValidValuesWhenInsertedBefore()
155
166
$ node = new Category ([ 'name ' => 'test ' ]);
156
167
$ node ->before ($ target )->save ();
157
168
169
+ $ this ->assertTrue ($ node ->hasMoved ());
158
170
$ this ->assertEquals (array ($ target ->_lft , $ target ->_lft + 1 , $ target ->parent ->id ), $ this ->nodeValues ($ node ));
159
171
$ this ->assertTreeNotBroken ();
160
172
}
@@ -166,6 +178,7 @@ public function testCategoryMovesDown()
166
178
167
179
$ target ->append ($ node );
168
180
181
+ $ this ->assertTrue ($ node ->hasMoved ());
169
182
$ this ->assertNodeRecievesValidValues ($ node );
170
183
$ this ->assertTreeNotBroken ();
171
184
}
@@ -177,6 +190,7 @@ public function testCategoryMovesUp()
177
190
178
191
$ target ->append ($ node );
179
192
193
+ $ this ->assertTrue ($ node ->hasMoved ());
180
194
$ this ->assertTreeNotBroken ();
181
195
$ this ->assertNodeRecievesValidValues ($ node );
182
196
}
@@ -221,12 +235,18 @@ public function testGetsAncestorsDirect()
221
235
$ this ->assertEquals (array (1 , 5 , 7 ), $ path );
222
236
}
223
237
224
- public function testDescendantsQueried ()
238
+ public function testDescendants ()
225
239
{
226
240
$ node = $ this ->findCategory ('mobile ' );
227
241
$ descendants = $ node ->descendants ()->lists ('name ' );
242
+ $ expected = array ('nokia ' , 'samsung ' , 'galaxy ' , 'sony ' );
243
+
244
+ $ this ->assertEquals ($ expected , $ descendants );
245
+
246
+ $ descendants = $ node ->getDescendants ()->lists ('name ' );
228
247
229
- $ this ->assertEquals (array ('nokia ' , 'samsung ' , 'galaxy ' , 'sony ' ), $ descendants );
248
+ $ this ->assertEquals (count ($ descendants ), $ node ->getDescendantCount ());
249
+ $ this ->assertEquals ($ expected , $ descendants );
230
250
}
231
251
232
252
public function testWithDepthWorks ()
@@ -256,6 +276,13 @@ public function testParentIdAttributeAccessorAppendsNode()
256
276
$ node ->save ();
257
277
258
278
$ this ->assertEquals (5 , $ node ->parent_id );
279
+ $ this ->assertEquals (5 , $ node ->getParentId ());
280
+
281
+ $ node ->parent_id = null ;
282
+ $ node ->save ();
283
+
284
+ $ this ->assertEquals (null , $ node ->parent_id );
285
+ $ this ->assertTrue ($ node ->isRoot ());
259
286
}
260
287
261
288
/**
@@ -292,28 +319,30 @@ public function testFailsToSaveNodeUntilParentIsSaved()
292
319
$ node ->appendTo ($ parent )->save ();
293
320
}
294
321
295
- public function testGetsSiblings ()
322
+ public function testSiblings ()
296
323
{
297
324
$ node = $ this ->findCategory ('samsung ' );
298
325
$ siblings = $ node ->siblings ()->lists ('id ' );
326
+ $ next = $ node ->nextSiblings ()->lists ('id ' );
327
+ $ prev = $ node ->prevSiblings ()->lists ('id ' );
299
328
300
329
$ this ->assertEquals (array (6 , 9 ), $ siblings );
301
- }
330
+ $ this ->assertEquals (array (9 ), $ next );
331
+ $ this ->assertEquals (array (6 ), $ prev );
302
332
303
- public function testGetsNextSiblings ()
304
- {
305
- $ node = $ this ->findCategory ('samsung ' );
306
- $ siblings = $ node ->nextSiblings ()->lists ('id ' );
333
+ $ siblings = $ node ->getSiblings ()->lists ('id ' );
334
+ $ next = $ node ->getNextSiblings ()->lists ('id ' );
335
+ $ prev = $ node ->getPrevSiblings ()->lists ('id ' );
307
336
308
- $ this ->assertEquals (array (9 ), $ siblings );
309
- }
337
+ $ this ->assertEquals (array (6 , 9 ), $ siblings );
338
+ $ this ->assertEquals (array (9 ), $ next );
339
+ $ this ->assertEquals (array (6 ), $ prev );
310
340
311
- public function testGetsPrevSiblings ()
312
- {
313
- $ node = $ this ->findCategory ('samsung ' );
314
- $ siblings = $ node ->prevSiblings ()->lists ('id ' );
341
+ $ next = $ node ->getNextSibling ();
342
+ $ prev = $ node ->getPrevSibling ();
315
343
316
- $ this ->assertEquals (array (6 ), $ siblings );
344
+ $ this ->assertEquals (9 , $ next ->id );
345
+ $ this ->assertEquals (6 , $ prev ->id );
317
346
}
318
347
319
348
public function testFetchesReversed ()
0 commit comments