ENHANCEMENT: Implemented tests to complete email recipients class. APICHANGE: changed *FieldSettings() to *Setting()

This commit is contained in:
Will Rossiter 2010-09-07 22:44:43 +00:00
parent 8a80dfa592
commit bc0d4c7692
6 changed files with 51 additions and 17 deletions

View File

@ -831,6 +831,7 @@ class UserDefinedForm_EmailRecipient extends DataObject {
// if they have multiple options
if($multiOptionFields || $validEmailFields) {
if($multiOptionFields && $validEmailFields) {
$multiOptionFields->merge($validEmailFields);

View File

@ -116,7 +116,7 @@ class EditableFormField extends DataObject {
*
* @return Array Return all the Settings
*/
public function getFieldSettings() {
public function getSettings() {
return (!empty($this->CustomSettings)) ? unserialize($this->CustomSettings) : array();
}
@ -126,7 +126,7 @@ class EditableFormField extends DataObject {
*
* @param Array the custom settings
*/
public function setFieldSettings($settings = array()) {
public function setSettings($settings = array()) {
$this->CustomSettings = serialize($settings);
}
@ -137,11 +137,11 @@ class EditableFormField extends DataObject {
* @param String key
* @param String value
*/
public function setFieldSetting($key, $value) {
$settings = $this->getFieldSettings();
public function setSetting($key, $value) {
$settings = $this->getSettings();
$settings[$key] = $value;
$this->setFieldSettings($settings);
$this->setSettings($settings);
}
/**
@ -152,7 +152,7 @@ class EditableFormField extends DataObject {
* @return String
*/
public function getSetting($setting) {
$settings = $this->getFieldSettings();
$settings = $this->getSettings();
if(isset($settings) && count($settings) > 0) {
if(isset($settings[$setting])) {
return $settings[$setting];
@ -299,7 +299,7 @@ class EditableFormField extends DataObject {
// custom settings
if(isset($data['CustomSettings'])) {
$this->setFieldSettings($data['CustomSettings']);
$this->setSettings($data['CustomSettings']);
}
// custom validation
@ -309,9 +309,11 @@ class EditableFormField extends DataObject {
if(is_array($value)) {
$fieldValue = (isset($value['Value'])) ? $value['Value'] : '';
if(isset($value['ConditionOption']) && $value['ConditionOption'] == "Blank" || $value['ConditionOption'] == "NotBlank") {
$fieldValue = "";
}
$rules[] = array(
'Display' => (isset($value['Display'])) ? $value['Display'] : "",
'ConditionField' => (isset($value['ConditionField'])) ? $value['ConditionField'] : "",
@ -320,6 +322,7 @@ class EditableFormField extends DataObject {
);
}
}
$this->CustomRules = serialize($rules);
}
$this->write();

View File

@ -107,7 +107,7 @@ class UserFormsMigrationTask extends MigrationTask {
$result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first();
if($result) {
$field->setFieldSettings(array(
$field->setSettings(array(
'Size' => $result['Size'],
'MinLength' => $result['MinLength'],
'MaxLength' => $result['MaxLength'],
@ -126,7 +126,7 @@ class UserFormsMigrationTask extends MigrationTask {
$result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first();
if($result) {
$field->setFieldSettings(array(
$field->setSettings(array(
'Content' => $result['Content']
));
}
@ -142,7 +142,7 @@ class UserFormsMigrationTask extends MigrationTask {
$result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first();
if($result) {
$field->setFieldSettings(array(
$field->setSettings(array(
'GroupID' => $result['GroupID']
));
}
@ -158,7 +158,7 @@ class UserFormsMigrationTask extends MigrationTask {
$result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first();
if($result) {
$field->setFieldSettings(array(
$field->setSettings(array(
'Default' => $result['Checked']
));
}

View File

@ -84,7 +84,7 @@ class UserDefinedFormControllerTest extends FunctionalTest {
$this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 1);
}
function testgetFormFields() {
function testGetFormFields() {
// generating the fieldset of fields
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
@ -103,6 +103,18 @@ class UserDefinedFormControllerTest extends FunctionalTest {
$fields = $controller->getFormFields();
$this->assertEquals($fields->First()->getCustomValidationMessage(), 'Custom Error Message');
$this->assertEquals($fields->First()->Title(), 'Required Text Field <span class=\'required-identifier\'>*</span>');
// test custom right title
$field = $form->Fields()->First();
$field->setSetting('RightTitle', 'Right Title');
$field->write();
$controller = new UserDefinedForm_Controller($form);
$fields = $controller->getFormFields();
$this->assertEquals($fields->First()->RightTitle(), "Right Title");
}
function testGetFormActions() {

View File

@ -69,7 +69,7 @@ class UserDefinedFormTest extends FunctionalTest {
$email = $this->objFromFixture('EditableEmailField','email-field');
$form->Fields()->add($email);
$popup->Form = $form;
$popup->FormID = $form->ID;
$popup->write();
$fields = $popup->getCMSFields_forPopup();
@ -85,6 +85,25 @@ class UserDefinedFormTest extends FunctionalTest {
$popup->delete();
}
function testCanEditAndDeleteRecipient() {
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$this->logInWithPermission('ADMIN');
foreach($form->EmailRecipients() as $recipient) {
$this->assertTrue($recipient->canEdit());
$this->assertTrue($recipient->canDelete());
}
$member = Member::currentUser();
$member->logOut();
$this->logInWithPermission('SITETREE_VIEW_ALL');
foreach($form->EmailRecipients() as $recipient) {
$this->assertFalse($recipient->canEdit());
$this->assertFalse($recipient->canDelete());
}
}
function testPublishing() {
$this->logInWithPermission('ADMIN');

View File

@ -43,7 +43,6 @@ EditableTextField:
Name: required-text-field
Title: Required Text Field
CustomErrorMessage: Custom Error Message
RightTitle: Right Title
Required: true
EditableDropdown: