@@ -25,6 +25,8 @@ public function setUp()
25
25
$ data = include __DIR__ .'/data/categories.php ' ;
26
26
27
27
Capsule::table ('categories ' )->insert ($ data );
28
+
29
+ Category::resetActionsPerformed ();
28
30
}
29
31
30
32
public function tearDown ()
@@ -250,7 +252,7 @@ public function testDescendants()
250
252
{
251
253
$ node = $ this ->findCategory ('mobile ' );
252
254
$ descendants = $ node ->descendants ()->lists ('name ' );
253
- $ expected = array ('nokia ' , 'samsung ' , 'galaxy ' , 'sony ' );
255
+ $ expected = array ('nokia ' , 'samsung ' , 'galaxy ' , 'sony ' , ' lenovo ' );
254
256
255
257
$ this ->assertEquals ($ expected , $ descendants );
256
258
@@ -358,8 +360,6 @@ public function testSoftDeletedNodeisDeletedWhenParentIsDeleted()
358
360
359
361
$ this ->assertTreeNotBroken ();
360
362
361
- $ this ->dumpTree ();
362
-
363
363
$ this ->assertNull ($ this ->findCategory ('samsung ' , true ));
364
364
$ this ->assertNull ($ this ->findCategory ('sony ' ));
365
365
}
@@ -382,16 +382,16 @@ public function testSiblings()
382
382
$ next = $ node ->nextSiblings ()->lists ('id ' );
383
383
$ prev = $ node ->prevSiblings ()->lists ('id ' );
384
384
385
- $ this ->assertEquals (array (6 , 9 ), $ siblings );
386
- $ this ->assertEquals (array (9 ), $ next );
385
+ $ this ->assertEquals (array (6 , 9 , 10 ), $ siblings );
386
+ $ this ->assertEquals (array (9 , 10 ), $ next );
387
387
$ this ->assertEquals (array (6 ), $ prev );
388
388
389
389
$ siblings = $ node ->getSiblings ()->lists ('id ' );
390
390
$ next = $ node ->getNextSiblings ()->lists ('id ' );
391
391
$ prev = $ node ->getPrevSiblings ()->lists ('id ' );
392
392
393
- $ this ->assertEquals (array (6 , 9 ), $ siblings );
394
- $ this ->assertEquals (array (9 ), $ next );
393
+ $ this ->assertEquals (array (6 , 9 , 10 ), $ siblings );
394
+ $ this ->assertEquals (array (9 , 10 ), $ next );
395
395
$ this ->assertEquals (array (6 ), $ prev );
396
396
397
397
$ next = $ node ->getNextSibling ();
@@ -417,7 +417,7 @@ public function testToTreeBuildsWithDefaultOrder()
417
417
418
418
$ root = $ tree ->first ();
419
419
$ this ->assertEquals ('mobile ' , $ root ->name );
420
- $ this ->assertEquals (3 , count ($ root ->children ));
420
+ $ this ->assertEquals (4 , count ($ root ->children ));
421
421
}
422
422
423
423
public function testToTreeBuildsWithCustomOrder ()
@@ -431,7 +431,7 @@ public function testToTreeBuildsWithCustomOrder()
431
431
432
432
$ root = $ tree ->first ();
433
433
$ this ->assertEquals ('mobile ' , $ root ->name );
434
- $ this ->assertEquals (3 , count ($ root ->children ));
434
+ $ this ->assertEquals (4 , count ($ root ->children ));
435
435
$ this ->assertEquals ($ root , $ root ->children ->first ()->parent );
436
436
}
437
437
@@ -443,8 +443,8 @@ public function testToTreeWithSpecifiedRoot()
443
443
$ tree1 = \Kalnoy \Nestedset \Collection::make ($ nodes )->toTree (5 );
444
444
$ tree2 = \Kalnoy \Nestedset \Collection::make ($ nodes )->toTree ($ node );
445
445
446
- $ this ->assertEquals (3 , $ tree1 ->count ());
447
- $ this ->assertEquals (3 , $ tree2 ->count ());
446
+ $ this ->assertEquals (4 , $ tree1 ->count ());
447
+ $ this ->assertEquals (4 , $ tree2 ->count ());
448
448
}
449
449
450
450
public function testToTreeBuildsWithDefaultOrderAndMultipleRootNodes ()
@@ -458,7 +458,7 @@ public function testToTreeBuildsWithRootItemIdProvided()
458
458
{
459
459
$ tree = Category::whereBetween ('_lft ' , array (8 , 17 ))->get ()->toTree (5 );
460
460
461
- $ this ->assertEquals (3 , count ($ tree ));
461
+ $ this ->assertEquals (4 , count ($ tree ));
462
462
463
463
$ root = $ tree [1 ];
464
464
$ this ->assertEquals ('samsung ' , $ root ->name );
@@ -501,7 +501,7 @@ public function testDefaultCategoryIsSavedAsRoot()
501
501
$ node = new Category ([ 'name ' => 'test ' ]);
502
502
$ node ->save ();
503
503
504
- $ this ->assertEquals (19 , $ node ->_lft );
504
+ $ this ->assertEquals (21 , $ node ->_lft );
505
505
$ this ->assertTreeNotBroken ();
506
506
507
507
$ this ->assertTrue ($ node ->isRoot ());
@@ -545,7 +545,7 @@ public function testCreatesNode()
545
545
{
546
546
$ node = Category::create ([ 'name ' => 'test ' ]);
547
547
548
- $ this ->assertEquals (19 , $ node ->getLft ());
548
+ $ this ->assertEquals (21 , $ node ->getLft ());
549
549
}
550
550
551
551
public function testCreatesViaRelationship ()
@@ -604,4 +604,16 @@ public function testDescendantsByNode()
604
604
605
605
$ this ->assertEquals ([ 3 , 4 ], $ res );
606
606
}
607
+
608
+ public function testMultipleDeletionsDoNotBrakeTree ()
609
+ {
610
+ $ category = $ this ->findCategory ('mobile ' );
611
+
612
+ foreach ($ category ->children ()->take (2 )->get () as $ child )
613
+ {
614
+ $ child ->forceDelete ();
615
+ }
616
+
617
+ $ this ->assertTreeNotBroken ();
618
+ }
607
619
}
0 commit comments