diff --git a/code/UserDefinedForm.php b/code/UserDefinedForm.php index 03c657e..b32376c 100755 --- a/code/UserDefinedForm.php +++ b/code/UserDefinedForm.php @@ -387,7 +387,7 @@ class UserDefinedForm_Controller extends Page_Controller { $errorMessage = ($editableField->CustomErrorMessage) ? $editableField->CustomErrorMessage : $errorMessage; $field->setCustomValidationMessage($errorMessage); - + // set the right title on this field if($right = $editableField->getSetting('RightTitle')) { $field->setRightTitle($right); @@ -831,6 +831,7 @@ class UserDefinedForm_EmailRecipient extends DataObject { // if they have multiple options if($multiOptionFields || $validEmailFields) { + if($multiOptionFields && $validEmailFields) { $multiOptionFields->merge($validEmailFields); diff --git a/code/editor/EditableFormField.php b/code/editor/EditableFormField.php index 9d9acfd..9eccc05 100755 --- a/code/editor/EditableFormField.php +++ b/code/editor/EditableFormField.php @@ -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(); diff --git a/code/migration/UserFormsMigrationTask.php b/code/migration/UserFormsMigrationTask.php index 1316cb6..11faeeb 100644 --- a/code/migration/UserFormsMigrationTask.php +++ b/code/migration/UserFormsMigrationTask.php @@ -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'] )); } diff --git a/tests/UserDefinedFormControllerTest.php b/tests/UserDefinedFormControllerTest.php index ccb96e1..eb811c8 100644 --- a/tests/UserDefinedFormControllerTest.php +++ b/tests/UserDefinedFormControllerTest.php @@ -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 *'); + + // 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() { diff --git a/tests/UserDefinedFormTest.php b/tests/UserDefinedFormTest.php index f0d3055..e438298 100644 --- a/tests/UserDefinedFormTest.php +++ b/tests/UserDefinedFormTest.php @@ -64,12 +64,12 @@ class UserDefinedFormTest extends FunctionalTest { $this->assertTrue($fields->dataFieldByName('HideFormData') !== null); $this->assertTrue($fields->dataFieldByName('SendPlain') !== null); $this->assertTrue($fields->dataFieldByName('EmailBody') !== null); - + // add an email field, it should now add a or from X address picker $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'); diff --git a/tests/UserDefinedFormTest.yml b/tests/UserDefinedFormTest.yml index 43d5a42..6989faa 100644 --- a/tests/UserDefinedFormTest.yml +++ b/tests/UserDefinedFormTest.yml @@ -43,7 +43,6 @@ EditableTextField: Name: required-text-field Title: Required Text Field CustomErrorMessage: Custom Error Message - RightTitle: Right Title Required: true EditableDropdown: