@@ -50,3 +50,63 @@ function testFormEvents(Form $form): void
5050 assertType (Form::class, $ form );
5151 };
5252}
53+
54+
55+ // Issue #350: addRule() must accept validators with a second $arg parameter
56+ function testAddRuleValidatorOneParam (Form $ form ): void
57+ {
58+ $ form ->addText ('field ' )
59+ ->addRule (fn (Nette \Forms \Control $ input ): bool => (bool ) $ input ->getValue ());
60+ }
61+
62+
63+ function testAddRuleValidatorTwoParams (Form $ form ): void
64+ {
65+ $ form ->addInteger ('num ' )
66+ ->addRule (
67+ fn (Nette \Forms \Control $ input , mixed $ arg ): bool => $ input ->getValue () > $ arg ,
68+ 'Must be greater than %d ' ,
69+ 0 ,
70+ );
71+ }
72+
73+
74+ function testAddRuleStaticCallableWithArg (Form $ form ): void
75+ {
76+ $ form ->addInteger ('num ' )
77+ ->addRule (
78+ [CustomValidators::class, 'validateDivisibility ' ],
79+ 'Must be divisible by %d ' ,
80+ 8 ,
81+ );
82+ }
83+
84+
85+ // addCondition() with one-parameter handler
86+ function testAddConditionOneParam (Form $ form ): void
87+ {
88+ $ form ->addText ('field ' )
89+ ->addCondition (fn (Nette \Forms \Control $ input ): bool => (bool ) $ input ->getValue ())
90+ ->setRequired ();
91+ }
92+
93+
94+ // addCondition() with two-parameter handler
95+ function testAddConditionTwoParams (Form $ form ): void
96+ {
97+ $ form ->addInteger ('num ' )
98+ ->addCondition (
99+ fn (Nette \Forms \Control $ input , mixed $ arg ): bool => $ input ->getValue () > $ arg ,
100+ 0 ,
101+ )
102+ ->setRequired ();
103+ }
104+
105+
106+ class CustomValidators
107+ {
108+ public static function validateDivisibility (Nette \Forms \Control $ input , mixed $ arg ): bool
109+ {
110+ return $ input ->getValue () % $ arg === 0 ;
111+ }
112+ }
0 commit comments