Created
March 19, 2014 16:28
-
-
Save monachilada/9645492 to your computer and use it in GitHub Desktop.
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
<? | |
public function testNestedValidation() { | |
Validator::add('match', function($value, $format = null, array $options = array()) { | |
$options += array( | |
'against' => '', | |
'values' => array() | |
); | |
extract($options); | |
if (array_key_exists($against, $values)) { | |
return $values[$against] == $value; | |
} | |
return false; | |
}); | |
$rulesDash = array( | |
'password_set' => array( | |
array( | |
'notEmpty', | |
'required' => false, | |
'skipEmpty' => true, | |
'message' => 'You have to choose a password.' | |
), | |
array( | |
'lengthBetween', | |
'min' => 8, | |
'required' => false, | |
'skipEmpty' => true, | |
'message' => 'That password is not quite long enough.' | |
) | |
), | |
'password_repeat' => array( | |
array( | |
'match', | |
'against' => 'password_set', | |
'required' => false, | |
'message' => 'Those passwords do not match.' | |
) | |
) | |
); | |
$rulesDot = array( | |
'password.set' => array( | |
array( | |
'notEmpty', | |
'required' => false, | |
'skipEmpty' => true, | |
'message' => 'You have to choose a password.' | |
), | |
array( | |
'lengthBetween', | |
'min' => 8, | |
'required' => false, | |
'skipEmpty' => true, | |
'message' => 'That password is not quite long enough.' | |
) | |
), | |
'password.repeat' => array( | |
array( | |
'match', | |
'against' => 'password.set', | |
'required' => false, | |
'message' => 'Those passwords do not match.' | |
) | |
) | |
); | |
$dataDash = array( | |
'password_set' => 'q1w2e3r4t5', | |
'password_repeat' => 'q1w2e3r4t5' | |
); | |
$dataDot = array( | |
'password.set' => 'q1w2e3r4t5', | |
'password.repeat' => 'q1w2e3r4t5' | |
); | |
$dataDashEmpty = array( | |
'password_set' => '', | |
'password_repeat' => '' | |
); | |
$dataDotEmpty = array( | |
'password.set' => '', | |
'password.repeat' => '' | |
); | |
$dataDashNoMatch = array( | |
'password_set' => 'q1w2e3r4t5', | |
'password_repeat' => '5t4r3e2w1q' | |
); | |
$dataDotNoMatch = array( | |
'password.set' => 'q1w2e3r4t5', | |
'password.repeat' => '5t4r3e2w1q' | |
); | |
$resultDash = Validator::check($dataDash, $rulesDash); | |
$resultDot = Validator::check($dataDot, $rulesDot); | |
$resultDashEmpty = Validator::check($dataDashEmpty, $rulesDash); | |
$resultDotEmpty = Validator::check($dataDotEmpty, $rulesDot); | |
$this->assertEqual($resultDot, $resultDash, $resultDashEmpty, $resultDotEmpty); | |
$resultDashNoMatch = Validator::check($dataDashNoMatch, $rulesDash); | |
$resultDotNoMatch = Validator::check($dataDotNoMatch, $rulesDot); | |
$this->assertEqual($resultDotNoMatch['password.repeat'], $resultDashNoMatch['password_repeat']); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment