2009-06-27 06:00:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-06-27 06:00:10 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class ConfirmedPasswordFieldTest extends SapphireTest {
|
2014-01-07 05:16:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testSetValue() {
|
2009-06-27 06:00:10 +02:00
|
|
|
$field = new ConfirmedPasswordField('Test', 'Testing', 'valueA');
|
|
|
|
$this->assertEquals('valueA', $field->Value());
|
2011-10-29 06:01:52 +02:00
|
|
|
$this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->Value());
|
|
|
|
$this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value());
|
2009-06-27 06:00:10 +02:00
|
|
|
$field->setValue('valueB');
|
|
|
|
$this->assertEquals('valueB', $field->Value());
|
2011-10-29 06:01:52 +02:00
|
|
|
$this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_Password]')->Value());
|
|
|
|
$this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value());
|
2009-06-27 06:00:10 +02:00
|
|
|
}
|
2011-02-25 05:01:46 +01:00
|
|
|
|
2013-06-20 04:08:46 +02:00
|
|
|
public function testHashHidden() {
|
|
|
|
$field = new ConfirmedPasswordField('Password', 'Password', 'valueA');
|
|
|
|
$field->setCanBeEmpty(true);
|
|
|
|
|
|
|
|
$this->assertEquals('valueA', $field->Value());
|
|
|
|
$this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->Value());
|
|
|
|
$this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value());
|
|
|
|
|
|
|
|
$member = new Member();
|
|
|
|
$member->Password = "valueB";
|
|
|
|
$member->write();
|
|
|
|
|
|
|
|
$form = new Form($this, 'Form', new FieldList($field), new FieldList());
|
|
|
|
$form->loadDataFrom($member);
|
|
|
|
|
|
|
|
$this->assertEquals('', $field->Value());
|
|
|
|
$this->assertEquals('', $field->children->fieldByName($field->getName() . '[_Password]')->Value());
|
|
|
|
$this->assertEquals('', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value());
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testSetShowOnClick() {
|
2011-02-25 05:01:46 +01:00
|
|
|
//hide by default and display show/hide toggle button
|
|
|
|
$field = new ConfirmedPasswordField('Test', 'Testing', 'valueA', null, true);
|
|
|
|
$fieldHTML = $field->Field();
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertContains("showOnClickContainer", $fieldHTML,
|
|
|
|
"Test class for hiding/showing the form contents is set");
|
|
|
|
$this->assertContains("showOnClick", $fieldHTML,
|
|
|
|
"Test class for hiding/showing the form contents is set");
|
2011-02-25 05:01:46 +01:00
|
|
|
|
|
|
|
//show all by default
|
|
|
|
$field = new ConfirmedPasswordField('Test', 'Testing', 'valueA', null, false);
|
|
|
|
$fieldHTML = $field->Field();
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertNotContains("showOnClickContainer", $fieldHTML,
|
|
|
|
"Test class for hiding/showing the form contents is set");
|
|
|
|
$this->assertNotContains("showOnClick", $fieldHTML,
|
|
|
|
"Test class for hiding/showing the form contents is set");
|
2011-02-25 05:01:46 +01:00
|
|
|
}
|
2014-01-07 05:16:58 +01:00
|
|
|
|
|
|
|
public function testValidation() {
|
|
|
|
$field = new ConfirmedPasswordField('Test', 'Testing', array(
|
|
|
|
"_Password" => "abc123",
|
|
|
|
"_ConfirmPassword" => "abc123"
|
|
|
|
));
|
|
|
|
$validator = new RequiredFields();
|
|
|
|
$form = new Form($this, 'Form', new FieldList($field), new FieldList(), $validator);
|
2014-11-12 03:19:12 +01:00
|
|
|
$this->assertTrue(
|
|
|
|
$field->validate($validator),
|
|
|
|
"Validates when both passwords are the same"
|
|
|
|
);
|
2014-01-07 05:16:58 +01:00
|
|
|
$field->setName("TestNew"); //try changing name of field
|
2014-11-12 03:19:12 +01:00
|
|
|
$this->assertTrue(
|
|
|
|
$field->validate($validator),
|
|
|
|
"Validates when field name is changed"
|
|
|
|
);
|
2014-01-07 05:16:58 +01:00
|
|
|
//non-matching password should make the field invalid
|
|
|
|
$field->setValue(array(
|
|
|
|
"_Password" => "abc123",
|
|
|
|
"_ConfirmPassword" => "123abc"
|
|
|
|
));
|
2014-11-12 03:19:12 +01:00
|
|
|
$this->assertFalse(
|
|
|
|
$field->validate($validator),
|
|
|
|
"Does not validate when passwords differ"
|
|
|
|
);
|
2014-01-07 05:16:58 +01:00
|
|
|
}
|
|
|
|
|
2009-06-27 06:00:10 +02:00
|
|
|
}
|