From b03808f1c6da450fa4457edaf1dbab1ff1b6aedd Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 28 Jun 2022 15:53:40 +0900 Subject: [PATCH 1/2] test: add test cases --- tests/system/Validation/ValidationTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index 4c63b689a995..c43b7d997d88 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -440,6 +440,7 @@ public function testRulesSetup($rules, $expected, array $errors = []) $data = ['foo' => '']; $this->validation->setRules(['foo' => $rules], $errors); $this->validation->run($data); + $this->assertSame($expected, $this->validation->getError('foo')); } @@ -468,6 +469,10 @@ public function rulesSetupProvider(): Generator ['rules' => 'min_length[10]'], 'The foo field must be at least 10 characters in length.', ], + [ + ['rules' => ['min_length[10]']], + 'The foo field must be at least 10 characters in length.', + ], [ [ 'label' => 'Foo Bar', @@ -475,6 +480,13 @@ public function rulesSetupProvider(): Generator ], 'The Foo Bar field must be at least 10 characters in length.', ], + [ + [ + 'label' => 'Foo Bar', + 'rules' => ['min_length[10]'], + ], + 'The Foo Bar field must be at least 10 characters in length.', + ], [ [ 'label' => 'Foo Bar', From 2217a4f78d3629212f05fc1d324a61f47c72c106 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 28 Jun 2022 15:54:48 +0900 Subject: [PATCH 2/2] docs: add sample code of rules as array --- user_guide_src/source/libraries/validation/006.php | 5 +++++ user_guide_src/source/libraries/validation/007.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/user_guide_src/source/libraries/validation/006.php b/user_guide_src/source/libraries/validation/006.php index 24a771f70e31..5f7cbf645ab2 100644 --- a/user_guide_src/source/libraries/validation/006.php +++ b/user_guide_src/source/libraries/validation/006.php @@ -4,3 +4,8 @@ 'username' => 'required', 'password' => 'required|min_length[10]', ]); +// or +$validation->setRules([ + 'username' => 'required', + 'password' => ['required', 'min_length[10]'], +]); diff --git a/user_guide_src/source/libraries/validation/007.php b/user_guide_src/source/libraries/validation/007.php index b211d9c1cec5..cb12c5a61a79 100644 --- a/user_guide_src/source/libraries/validation/007.php +++ b/user_guide_src/source/libraries/validation/007.php @@ -4,3 +4,8 @@ 'username' => ['label' => 'Username', 'rules' => 'required'], 'password' => ['label' => 'Password', 'rules' => 'required|min_length[10]'], ]); +// or +$validation->setRules([ + 'username' => ['label' => 'Username', 'rules' => 'required'], + 'password' => ['label' => 'Password', 'rules' => ['required', 'min_length[10]']], +]);