diff --git a/tests/NestedSetsBehaviorTest.php b/tests/NestedSetsBehaviorTest.php index a675ae5..845070d 100644 --- a/tests/NestedSetsBehaviorTest.php +++ b/tests/NestedSetsBehaviorTest.php @@ -2052,7 +2052,7 @@ public function testPrependToWithRunValidationParameterUsingStrictValidation(): ); } - public function testProtectedApplyTreeAttributeConditionRemainAccessibleToSubclasses(): void + public function testProtectedApplyTreeAttributeConditionRemainsAccessibleToSubclasses(): void { $this->createDatabase(); @@ -2085,4 +2085,45 @@ public function testProtectedApplyTreeAttributeConditionRemainAccessibleToSubcla '\'Tree\' attribute condition should be applied correctly when \'treeAttribute\' is enabled.', ); } + + public function testProtectedBeforeInsertNodeRemainsAccessibleToSubclasses(): void + { + $this->createDatabase(); + + $testNode = new ExtendableMultipleTree([ + 'name' => 'Extensibility Test Node', + 'tree' => 1, + ]); + + $extendableBehavior = $testNode->getBehavior('nestedSetsBehavior'); + + self::assertInstanceOf( + ExtendableNestedSetsBehavior::class, + $extendableBehavior, + '\'ExtendableMultipleTree\' should use \'ExtendableNestedSetsBehavior\'.', + ); + + $extendableBehavior->exposedBeforeInsertNode(5, 1); + + self::assertTrue( + $extendableBehavior->wasMethodCalled('beforeInsertNode'), + '\'beforeInsertNode\' method should remain protected to allow subclass customization.', + ); + + self::assertEquals( + 5, + $testNode->lft, + '\'beforeInsertNode\' should set the \'left\' attribute correctly.', + ); + self::assertEquals( + 6, + $testNode->rgt, + '\'beforeInsertNode\' should set the \'right\' attribute correctly.', + ); + self::assertEquals( + 1, + $testNode->depth, + '\'beforeInsertNode\' should set the \'depth\' attribute correctly.', + ); + } }