Skip to content

Commit ef732e0

Browse files
committed
test: add tests for required_with
1 parent 647afc3 commit ef732e0

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/system/Validation/RulesTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,44 @@ public function requiredWithProvider(): Generator
614614
];
615615
}
616616

617+
/**
618+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/7557
619+
*
620+
* @dataProvider RequiredWithAndOtherRuleProvider
621+
*/
622+
public function testRequiredWithAndOtherRule(bool $expected, array $data): void
623+
{
624+
$this->validation->setRules([
625+
'mustBeADate' => 'required_with[otherField]|permit_empty|valid_date',
626+
]);
627+
628+
$result = $this->validation->run($data);
629+
630+
$this->assertSame($expected, $result);
631+
}
632+
633+
public function RequiredWithAndOtherRuleProvider(): Generator
634+
{
635+
yield from [
636+
// `otherField` and `mustBeADate` do not exist
637+
[true, []],
638+
// `mustBeADate` does not exist
639+
[false, ['otherField' => 'exists']],
640+
// ``otherField` does not exist
641+
[true, ['mustBeADate' => '2023-06-12']],
642+
[true, ['mustBeADate' => '']],
643+
[true, ['mustBeADate' => null]],
644+
[true, ['mustBeADate' => []]],
645+
// `otherField` and `mustBeADate` exist
646+
[true, ['mustBeADate' => '', 'otherField' => '']],
647+
[true, ['mustBeADate' => '2023-06-12', 'otherField' => 'exists']],
648+
[true, ['mustBeADate' => '2023-06-12', 'otherField' => '']],
649+
[false, ['mustBeADate' => '', 'otherField' => 'exists']],
650+
[false, ['mustBeADate' => [], 'otherField' => 'exists']],
651+
[false, ['mustBeADate' => null, 'otherField' => 'exists']],
652+
];
653+
}
654+
617655
/**
618656
* @dataProvider requiredWithoutProvider
619657
*/

0 commit comments

Comments
 (0)