diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index a2e00cc64e7b..100cf1535495 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -256,6 +256,29 @@ static function ($value, $data, &$error, $field) { ); } + public function testClosureRuleWithLabel(): void + { + $this->validation->setRules([ + 'secret' => [ + 'label' => 'シークレット', + 'rules' => ['required', static fn ($value) => $value === 'abc'], + 'errors' => [ + // Specify the array key for the closure rule. + 1 => 'The {field} is invalid', + ], + ], + ]); + + $data = ['secret' => 'xyz']; + $return = $this->validation->run($data); + + $this->assertFalse($return); + $this->assertSame( + ['secret' => 'The シークレット is invalid'], + $this->validation->getErrors() + ); + } + /** * @see https://github.com/codeigniter4/CodeIgniter4/issues/5368 *