|
3 | 3 | namespace Tests\Becklyn\Menu\Item; |
4 | 4 |
|
5 | 5 | use Becklyn\Menu\Item\MenuItem; |
6 | | -use Becklyn\Menu\Sorter\MenuItemSorter; |
7 | 6 | use Becklyn\Menu\Target\LazyRoute; |
8 | 7 | use PHPUnit\Framework\TestCase; |
9 | 8 |
|
@@ -349,4 +348,65 @@ public function testAnyCurrent () : void |
349 | 348 | self::assertTrue($both->isCurrentAncestor()); |
350 | 349 | self::assertTrue($both->isAnyCurrent()); |
351 | 350 | } |
| 351 | + |
| 352 | + |
| 353 | + /** |
| 354 | + * |
| 355 | + */ |
| 356 | + public function testRemoveChild () : void |
| 357 | + { |
| 358 | + $root = new MenuItem(); |
| 359 | + $child = $root->createChild("1"); |
| 360 | + $otherRoot = new MenuItem(); |
| 361 | + $otherChild = $otherRoot->createChild("other"); |
| 362 | + |
| 363 | + self::assertCount(1, $root->getChildren()); |
| 364 | + self::assertSame($child, $root->getChildren()[0]); |
| 365 | + self::assertSame($root, $child->getParent()); |
| 366 | + self::assertCount(1, $otherRoot->getChildren()); |
| 367 | + self::assertSame($otherChild, $otherRoot->getChildren()[0]); |
| 368 | + self::assertSame($otherRoot, $otherChild->getParent()); |
| 369 | + |
| 370 | + // should change nothing -> wrong parent |
| 371 | + $root->removeChild($otherChild); |
| 372 | + |
| 373 | + self::assertCount(1, $root->getChildren()); |
| 374 | + self::assertSame($child, $root->getChildren()[0]); |
| 375 | + self::assertSame($root, $child->getParent()); |
| 376 | + self::assertCount(1, $otherRoot->getChildren()); |
| 377 | + self::assertSame($otherChild, $otherRoot->getChildren()[0]); |
| 378 | + self::assertSame($otherRoot, $otherChild->getParent()); |
| 379 | + |
| 380 | + $root->removeChild($child); |
| 381 | + |
| 382 | + self::assertCount(0, $root->getChildren()); |
| 383 | + self::assertSame(null, $child->getParent()); |
| 384 | + self::assertCount(1, $otherRoot->getChildren()); |
| 385 | + self::assertSame($otherChild, $otherRoot->getChildren()[0]); |
| 386 | + self::assertSame($otherRoot, $otherChild->getParent()); |
| 387 | + } |
| 388 | + |
| 389 | + |
| 390 | + /** |
| 391 | + * |
| 392 | + */ |
| 393 | + public function testRemoveAllChildren () : void |
| 394 | + { |
| 395 | + $root = new MenuItem(); |
| 396 | + $child1 = $root->createChild("1"); |
| 397 | + $child2 = $root->createChild("2"); |
| 398 | + |
| 399 | + self::assertContains($child1, $root->getChildren()); |
| 400 | + self::assertContains($child2, $root->getChildren()); |
| 401 | + self::assertSame($root, $child1->getParent()); |
| 402 | + self::assertSame($root, $child2->getParent()); |
| 403 | + |
| 404 | + $root->removeAllChildren(); |
| 405 | + |
| 406 | + |
| 407 | + |
| 408 | + self::assertEmpty($root->getChildren()); |
| 409 | + self::assertSame(null, $child1->getParent()); |
| 410 | + self::assertSame(null, $child2->getParent()); |
| 411 | + } |
352 | 412 | } |
0 commit comments