@@ -1111,17 +1111,17 @@ public function testRulesForSingleRuleWithAsteriskWillReturnError(): void
11111111 $ request = new IncomingRequest ($ config , new URI (), 'php://input ' , new UserAgent ());
11121112
11131113 $ this ->validation ->setRules ([
1114- 'id_user.* ' => 'numeric ' ,
1115- 'name_user.* ' => 'alpha ' ,
1116- 'contacts.*.name ' => 'required ' ,
1114+ 'id_user.* ' => 'numeric ' ,
1115+ 'name_user.* ' => 'alpha ' ,
1116+ 'contacts.friends. *.name ' => 'required ' ,
11171117 ]);
11181118
11191119 $ this ->validation ->withRequest ($ request ->withMethod ('post ' ))->run ();
11201120 $ this ->assertSame ([
11211121 'id_user.0 ' => 'The id_user.* field must contain only numbers. ' ,
11221122 'name_user.0 ' => 'The name_user.* field may only contain alphabetical characters. ' ,
11231123 'name_user.2 ' => 'The name_user.* field may only contain alphabetical characters. ' ,
1124- 'contacts.friends.0.name ' => 'The contacts.*.name field is required. ' ,
1124+ 'contacts.friends.0.name ' => 'The contacts.friends. *.name field is required. ' ,
11251125 ], $ this ->validation ->getErrors ());
11261126
11271127 $ this ->assertSame (
@@ -1130,8 +1130,8 @@ public function testRulesForSingleRuleWithAsteriskWillReturnError(): void
11301130 $ this ->validation ->getError ('name_user.* ' )
11311131 );
11321132 $ this ->assertSame (
1133- 'The contacts.*.name field is required. ' ,
1134- $ this ->validation ->getError ('contacts.*.name ' )
1133+ 'The contacts.friends. *.name field is required. ' ,
1134+ $ this ->validation ->getError ('contacts.friends. *.name ' )
11351135 );
11361136 }
11371137
@@ -1228,17 +1228,17 @@ public function testTranslatedLabelTagReplacement(): void
12281228 }
12291229
12301230 /**
1231- * @dataProvider provideDotNotationOnIfExistRule
1231+ * @dataProvider provideIfExistRuleWithAsterisk
12321232 *
12331233 * @see https://github.com/codeigniter4/CodeIgniter4/issues/4521
12341234 */
1235- public function testDotNotationOnIfExistRule (bool $ expected , array $ rules , array $ data ): void
1235+ public function testIfExistRuleWithAsterisk (bool $ expected , array $ rules , array $ data ): void
12361236 {
12371237 $ actual = $ this ->validation ->setRules ($ rules )->run ($ data );
12381238 $ this ->assertSame ($ expected , $ actual );
12391239 }
12401240
1241- public static function provideDotNotationOnIfExistRule (): iterable
1241+ public static function provideIfExistRuleWithAsterisk (): iterable
12421242 {
12431243 yield 'dot-on-end-fail ' => [
12441244 false ,
@@ -1613,7 +1613,7 @@ public function testRuleWithLeadingAsterisk(): void
16131613 /**
16141614 * @see https://github.com/codeigniter4/CodeIgniter4/issues/5942
16151615 */
1616- public function testRequireWithoutWithWildCard (): void
1616+ public function testRequireWithoutWithAsterisk (): void
16171617 {
16181618 $ data = [
16191619 'a ' => [
@@ -1631,4 +1631,50 @@ public function testRequireWithoutWithWildCard(): void
16311631 $ this ->validation ->getError ('a.1.c ' )
16321632 );
16331633 }
1634+
1635+ /**
1636+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/8128
1637+ */
1638+ public function testRuleWithAsteriskToMultiDimensionalArray (): void
1639+ {
1640+ $ data = [
1641+ 'contacts ' => [
1642+ 'name ' => 'Joe Smith ' ,
1643+ 'just ' => [
1644+ 'friends ' => [
1645+ [
1646+ 'name ' => 'Fred Flinstone ' ,
1647+ ],
1648+ [
1649+ 'name ' => 'Wilma ' ,
1650+ ],
1651+ ],
1652+ ],
1653+ ],
1654+ ];
1655+
1656+ $ this ->validation ->setRules (
1657+ ['contacts.just.friends.*.name ' => 'required|max_length[1] ' ]
1658+ );
1659+ $ this ->assertFalse ($ this ->validation ->run ($ data ));
1660+ $ this ->assertSame (
1661+ [
1662+ 'contacts.just.friends.0.name ' => 'The contacts.just.friends.*.name field cannot exceed 1 characters in length. ' ,
1663+ 'contacts.just.friends.1.name ' => 'The contacts.just.friends.*.name field cannot exceed 1 characters in length. ' ,
1664+ ],
1665+ $ this ->validation ->getErrors ()
1666+ );
1667+
1668+ $ this ->validation ->reset ();
1669+ $ this ->validation ->setRules (
1670+ ['contacts.*.name ' => 'required|max_length[1] ' ]
1671+ );
1672+ $ this ->assertFalse ($ this ->validation ->run ($ data ));
1673+ $ this ->assertSame (
1674+ // The data for `contacts.*.name` does not exist. So it is interpreted
1675+ // as `null`, and this error message returns.
1676+ ['contacts.*.name ' => 'The contacts.*.name field is required. ' ],
1677+ $ this ->validation ->getErrors ()
1678+ );
1679+ }
16341680}
0 commit comments