-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: validation rule matches
and differs
#8122
Merged
kenjis
merged 5 commits into
codeigniter4:develop
from
kenjis:fix-validation-matches-and-differs
Nov 7, 2023
Merged
fix: validation rule matches
and differs
#8122
kenjis
merged 5 commits into
codeigniter4:develop
from
kenjis:fix-validation-matches-and-differs
Nov 7, 2023
+137
−19
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matches
and differs
matches
and differs
CI3's behaviors: public function test_rule_matches()
{
$rules = array(
array('field' => 'foo', 'label' => 'label', 'rules' => 'required'),
array('field' => 'bar', 'label' => 'label2', 'rules' => 'matches[foo]')
);
$values_base = array('foo' => 'sample');
$this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'sample'))));
$this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => ''))));
$this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => 'Sample'))));
$this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => ' sample'))));
$this->assertFalse($this->run_rules($rules, []));
$this->assertFalse($this->run_rules($rules, ['foo' => null]));
$this->assertFalse($this->run_rules($rules, ['bar' => null]));
$this->assertFalse($this->run_rules($rules, ['foo' => null, 'bar' => null]));
$this->assertTrue($this->run_rules($rules, ['foo' => 1.2, 'bar' => 1.2]));
$this->assertFalse($this->run_rules($rules, ['foo' => 1.2, 'bar' => 2.3]));
$this->assertTrue($this->run_rules($rules, ['foo' => true, 'bar' => true]));
}
public function test_rule_differs()
{
$rules = array(
array('field' => 'foo', 'label' => 'label', 'rules' => 'required'),
array('field' => 'bar', 'label' => 'label2', 'rules' => 'differs[foo]')
);
$values_base = array('foo' => 'sample');
$this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'does_not_match'))));
$this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'Sample'))));
$this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => ' sample'))));
$this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => 'sample'))));
$this->assertFalse($this->run_rules($rules, []));
$this->assertFalse($this->run_rules($rules, ['foo' => null]));
$this->assertFalse($this->run_rules($rules, ['bar' => null]));
$this->assertFalse($this->run_rules($rules, ['foo' => null, 'bar' => null]));
$this->assertFalse($this->run_rules($rules, ['foo' => 1.2, 'bar' => 1.2]));
$this->assertTrue($this->run_rules($rules, ['foo' => 1.2, 'bar' => 2.3]));
$this->assertFalse($this->run_rules($rules, ['foo' => true, 'bar' => true]));
} |
0200da4
to
36c0de9
Compare
5 tasks
d90fc02
to
b156c13
Compare
add docs. |
b156c13
to
b154cae
Compare
👋 Hi, @kenjis! |
b154cae
to
db0ad7e
Compare
MGatner
reviewed
Nov 5, 2023
MGatner
approved these changes
Nov 7, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
breaking change
Pull requests that may break existing functionalities
bug
Verified issues on the current code behavior or pull requests that will fix them
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Note: Adding
?string
in CI4 makes the behavior different from that of CI3. There may be similar bugs in other Traditional Rules.Checklist: