public function validate(Validation $validation, $attribute)
{
if (!$this->hasOption('origField')) {
throw new Exception('Original field must be set');
}
$allowEmpty = $this->getOption('allowEmpty');
$value = $validation->getValue($attribute);
if ($allowEmpty && (is_scalar($value) && (string) $value === '' || is_null($value))) {
return true;
}
$origField = $this->getOption('origField');
$origValue = $validation->getValue($origField);
if (is_string($value) && $value == $origValue) {
return true;
}
$message = $this->hasOption('message') ? $this->getOption('message') : 'Value not confirmed';
$validation->appendMessage(new Validation\Message($message, $attribute, 'ConfirmationOfValidator'));
return false;
}
public function testValidateInvalidValue() { $validation = Stub::make('Phalcon\\Validation', array('getValue' => array('value', 'value'), 'appendMessage' => true)); $validator = new ConfirmationOf(array('origField' => 'original')); $this->assertFalse($validator->validate($validation, 'confirmation')); }