Skip to content
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

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Oct 29, 2023

Description

Note: Adding ?string in CI4 makes the behavior different from that of CI3. There may be similar bugs in other Traditional Rules.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added bug Verified issues on the current code behavior or pull requests that will fix them breaking change Pull requests that may break existing functionalities labels Oct 29, 2023
@kenjis kenjis marked this pull request as draft October 29, 2023 21:15
@kenjis kenjis changed the title fix: validation strict rule matches and differs fix: validation rule matches and differs Oct 29, 2023
@kenjis
Copy link
Member Author

kenjis commented Oct 29, 2023

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]));
	}

@kenjis kenjis force-pushed the fix-validation-matches-and-differs branch from 0200da4 to 36c0de9 Compare October 29, 2023 21:44
@kenjis kenjis added the docs needed Pull requests needing documentation write-ups and/or revisions. label Oct 30, 2023
@kenjis kenjis force-pushed the fix-validation-matches-and-differs branch from d90fc02 to b156c13 Compare November 2, 2023 07:57
@kenjis kenjis removed the docs needed Pull requests needing documentation write-ups and/or revisions. label Nov 2, 2023
@kenjis kenjis marked this pull request as ready for review November 2, 2023 07:57
@kenjis
Copy link
Member Author

kenjis commented Nov 2, 2023

add docs.

@kenjis kenjis force-pushed the fix-validation-matches-and-differs branch from b156c13 to b154cae Compare November 2, 2023 08:02
@github-actions github-actions bot added the stale Pull requests with conflicts label Nov 3, 2023
Copy link

github-actions bot commented Nov 3, 2023

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@kenjis kenjis force-pushed the fix-validation-matches-and-differs branch from b154cae to db0ad7e Compare November 3, 2023 00:43
@kenjis kenjis removed the stale Pull requests with conflicts label Nov 3, 2023
@kenjis kenjis merged commit eebec16 into codeigniter4:develop Nov 7, 2023
62 checks passed
@kenjis kenjis deleted the fix-validation-matches-and-differs branch November 7, 2023 21:47
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants