File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -1631,4 +1631,50 @@ public function testRequireWithoutWithWildCard(): void
1631
1631
$ this ->validation ->getError ('a.1.c ' )
1632
1632
);
1633
1633
}
1634
+
1635
+ /**
1636
+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/8128
1637
+ */
1638
+ public function testRuleWithMultiDimensionalArrayAndAsterisk (): 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
+ }
1634
1680
}
You can’t perform that action at this time.
0 commit comments