FIX: ConfirmedPassword field correctly reports mismatching passwords

added testFormValidation to prove #4780
This commit is contained in:
Christopher Darling 2015-11-18 13:11:31 +00:00
parent b943a0c6dd
commit e9b833f5f0
2 changed files with 22 additions and 1 deletions

View File

@ -264,6 +264,7 @@ class ConfirmedPasswordField extends FormField {
} else {
if($value || (!$value && $this->canBeEmpty)) {
$this->value = $value;
$this->confirmValue = $value;
}
}
@ -273,7 +274,7 @@ class ConfirmedPasswordField extends FormField {
->setValue($this->value);
$this->children->fieldByName($this->getName() . '[_ConfirmPassword]')
->setValue($this->value);
->setValue($this->confirmValue);
}
return $this;

View File

@ -71,5 +71,25 @@ class ConfirmedPasswordFieldTest extends SapphireTest {
));
$this->assertFalse($field->validate($validator));
}
public function testFormValidation() {
$form = new Form(
new Controller(),
'Form',
new FieldList($field = new ConfirmedPasswordField('Password')),
new FieldList()
);
$form->loadDataFrom(array(
'Password' => array(
'_Password' => '123',
'_ConfirmPassword' => '999',
)
));
$this->assertEquals('123', $field->children->first()->Value());
$this->assertEquals('999', $field->children->last()->Value());
$this->assertNotEquals($field->children->first()->Value(), $field->children->last()->Value());
}
}