diff --git a/templates/EditableOption.ss b/templates/EditableOption.ss
index 0e00e33..6496179 100644
--- a/templates/EditableOption.ss
+++ b/templates/EditableOption.ss
@@ -3,9 +3,9 @@
<% end_if %>
\ No newline at end of file
diff --git a/templates/FieldEditor.ss b/templates/FieldEditor.ss
index b3a6b68..633fe18 100755
--- a/templates/FieldEditor.ss
+++ b/templates/FieldEditor.ss
@@ -1,4 +1,8 @@
-
+<% require css(userforms/css/FieldEditor.css) %>
+<% require javascript(sapphire/thirdparty/jquery-ui/jquery-ui-1.8rc3.custom.js) %>
+<% require javascript(userforms/javascript/UserForm.js) %>
+
+
- <% include AddField %>
-
-
-
Form Options
- <% control FormOptions %>
- $FieldHolder
- <% end_control %>
-
+ <% if canEdit %>
+
+ <% end_if %>
\ No newline at end of file
diff --git a/templates/Includes/AddField.ss b/templates/Includes/AddField.ss
deleted file mode 100644
index 63efc95..0000000
--- a/templates/Includes/AddField.ss
+++ /dev/null
@@ -1,14 +0,0 @@
-<% if canEdit %>
-
-<% end_if %>
\ No newline at end of file
diff --git a/tests/EditableFormFieldTest.php b/tests/EditableFormFieldTest.php
new file mode 100644
index 0000000..b088e81
--- /dev/null
+++ b/tests/EditableFormFieldTest.php
@@ -0,0 +1,45 @@
+objFromFixture('EditableDropdown', 'basic-dropdown');
+
+ $option1 = $this->objFromFixture('EditableOption', 'option-1');
+ $option2 = $this->objFromFixture('EditableOption', 'option-2');
+
+ $dropdown->Options()->add($option1);
+ $dropdown->Options()->add($option2);
+
+ $field = $dropdown->getFormField();
+
+
+ $this->assertThat($field, $this->isInstanceOf('DropdownField'));
+ $values = $field->getSource();
+
+ $this->assertEquals(array('Option 1' => 'Option 1', 'Option 2' => 'Option 2'), $values);
+ }
+
+ function testEditableRadioField() {
+ $radio = $this->objFromFixture('EditableRadioField', 'radio-field');
+
+ $option1 = $this->objFromFixture('EditableOption', 'option-1');
+ $option2 = $this->objFromFixture('EditableOption', 'option-2');
+
+ $radio->Options()->add($option1);
+ $radio->Options()->add($option2);
+
+ $field = $radio->getFormField();
+
+ $this->assertThat($field, $this->isInstanceOf('OptionsetField'));
+ $values = $field->getSource();
+
+ $this->assertEquals(array('Option 1' => 'Option 1', 'Option 2' => 'Option 2'), $values);
+ }
+}
\ No newline at end of file
diff --git a/tests/EditableFormFields.yml b/tests/EditableFormFields.yml
new file mode 100644
index 0000000..3c2ce44
--- /dev/null
+++ b/tests/EditableFormFields.yml
@@ -0,0 +1,62 @@
+EditableOption:
+ option-1:
+ Name: Option1
+ Title: Option 1
+ Sort: 1
+
+ option-2:
+ Name: Option2
+ Title: Option 2
+ Sort: 2
+
+ department-1:
+ Name: dept1
+ Title: sales@example.com
+
+ department-2:
+ Name: dept2
+ Title: accounts@example.com
+
+EditableTextField:
+ basic-text:
+ Name: basic-text-name
+ Title: Basic Text Field
+
+ required-text:
+ Name: required-text-field
+ Title: Required Text Field
+ CustomErrorMessage: Custom Error Message
+ RightTitle: Right Title
+ Required: true
+
+EditableRadioField:
+ radio-field:
+ Name: radio-option
+ Title: Radio Option
+
+EditableDropdown:
+ basic-dropdown:
+ Name: basic-dropdown
+ Title: Basic Dropdown Field
+ Options: =>EditableOption.option-1, =>EditableOption.option-2
+
+ department-dropdown:
+ Name: department
+ Title: Department
+ Options: =>EditableOption.department-1, =>EditableOption.department-2
+
+EditableCheckbox:
+ checkbox-1:
+ Name: checkbox-1
+ Title: Checkbox 1
+
+EditableEmailField:
+ email-field:
+ Name: email-field
+ Title: Email
+
+EditableCheckboxGroupField:
+ checkbox-group:
+ Name: check-box-group
+ Title: Check box group
+ Options: =>EditableOption.option-1, =>EditableOption.option-2
\ No newline at end of file
diff --git a/tests/FieldEditorTest.php b/tests/FieldEditorTest.php
new file mode 100644
index 0000000..515650e
--- /dev/null
+++ b/tests/FieldEditorTest.php
@@ -0,0 +1,37 @@
+objFromFixture('SubmittedFormField', 'submitted-form-field-1');
+ $form = $field->Parent();
+
+ $this->assertEquals($form->FieldValues()->Count(), 2);
+ $form->delete();
+
+ $fields = DataObject::get('SubmittedFormField', "ParentID = '$form->ID'");
+
+ $this->assertNull($fields);
+ }
+
+ function testGetFormattedValue() {
+ $field = $this->objFromFixture('SubmittedFormField', 'submitted-form-field-1');
+
+ $this->assertEquals('1', $field->getFormattedValue());
+
+ $textarea = $this->objFromFixture('SubmittedFormField', 'submitted-textarea-1');
+
+ $text = "I am here testing
\nTesting until I cannot
\nI love my testing";
+
+ $this->assertEquals($text, $textarea->getFormattedValue());
+ }
+
+ function testFileGetLink() {
+ $field = $this->objFromFixture('SubmittedFileField', 'submitted-file-1');
+
+ // @todo add checks for if no file can be downloaded
+ $this->assertContains('my-file.jpg', $field->getLink());
+
+ }
+ function testFileGetFormattedValue() {
+ $field = $this->objFromFixture('SubmittedFileField', 'submitted-file-1');
+
+ // @todo add checks for if no file can be downloaded
+ $this->assertContains('Download File', $field->getFormattedValue());
+ }
+}
+
+
+class SubmittedFormTest_Controller extends Controller {
+
+ function ReportField() {
+ return new Form($this, 'ReportField', new FieldSet(new SubmittedFormReportField('Report'), new FieldSet()));
+ }
+}
diff --git a/tests/SubmittedFormTest.yml b/tests/SubmittedFormTest.yml
new file mode 100644
index 0000000..8bcd3df
--- /dev/null
+++ b/tests/SubmittedFormTest.yml
@@ -0,0 +1,43 @@
+UserDefinedForm:
+ form-page:
+ Title: Form
+
+ form-page-2:
+ Title: Second Form
+
+File:
+ uploaded-file:
+ Name: My File
+ Filename: my-file.jpg
+
+SubmittedForm:
+ submitted-form-1:
+ Parent: =>UserDefinedForm.form-page
+
+ submitted-form-2:
+ Parent: =>UserDefinedForm.form-page-2
+
+SubmittedFormField:
+ submitted-form-field-1:
+ Parent: =>SubmittedForm.submitted-form-1
+ Name: field-1
+ Title: Field 1
+ Value: 1
+
+ submitted-textarea-1:
+ Parent: =>SubmittedForm.submitted-form-2
+ Name: field 2
+ Title: Field 2
+ Value: |
+ I am here testing
+ Testing until I cannot
+ I love my testing
+
+SubmittedFileField:
+ submitted-file-1:
+ Name: File Field
+ Title: File
+ Parent: =>SubmittedForm.submitted-form-1
+ UploadedFile: =>File.uploaded-file
+
+
\ No newline at end of file
diff --git a/tests/UserDefinedFormControllerTest.php b/tests/UserDefinedFormControllerTest.php
new file mode 100644
index 0000000..ccb96e1
--- /dev/null
+++ b/tests/UserDefinedFormControllerTest.php
@@ -0,0 +1,196 @@
+setupFormFrontend();
+
+ $controller = new UserDefinedForm_Controller($form);
+
+ $this->autoFollowRedirection = false;
+ $this->clearEmails();
+
+ // load the form
+ $this->get($form->URLSegment);
+ $response = $this->submitForm('Form_Form', null, array('basic-text-name' => 'Basic Value'));
+
+ // should have a submitted form field now
+ $submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'");
+ $this->assertDOSAllMatch(array('Name' => 'basic-text-name', 'Value' => 'Basic Value', 'Title' => 'Basic Text Field'), $submitted);
+
+ // check emails
+ $this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject');
+ $email = $this->findEmail('test@example.com', 'no-reply@example.com', 'Email Subject');
+
+ // assert that the email has the field title and the value html email
+ $parser = new CSSContentParser($email['content']);
+ $title = $parser->getBySelector('strong');
+
+ $this->assertEquals('Basic Text Field', (string) $title[0], 'Email contains the field name');
+
+ $value = $parser->getBySelector('dd');
+ $this->assertEquals('Basic Value', (string) $value[0], 'Email contains the value');
+
+ // no html
+ $this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
+ $nohtml = $this->findEmail('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
+
+ $this->assertContains('Basic Text Field - Basic Value', $nohtml['content'], 'Email contains no html');
+
+ // no data
+ $this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
+ $nodata = $this->findEmail('nodata@example.com', 'no-reply@example.com', 'Email Subject');
+
+ $parser = new CSSContentParser($nodata['content']);
+ $list = $parser->getBySelector('dl');
+
+ $this->assertFalse(isset($list[0]), 'Email contains no fields');
+
+ // check to see if the user was redirected (301)
+ $this->assertEquals($response->getStatusCode(), 302);
+ $this->assertStringEndsWith('finished', $response->getHeader('Location'));
+ }
+
+ function testFinished() {
+ $form = $this->setupFormFrontend();
+ $response = $this->get($form->URLSegment.'/finished');
+
+ $this->assertContains($form->OnCompleteMessage ,$response->getBody());
+ }
+
+ function testForm() {
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $controller = new UserDefinedForm_Controller($form);
+
+ // test form
+ $this->assertEquals($controller->Form()->Name(), 'Form', 'The form is referenced as Form');
+
+ $this->assertEquals($controller->Form()->Fields()->Count(), 2);
+ $this->assertEquals($controller->Form()->Actions()->Count(), 1);
+ $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 0);
+
+ $requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
+ $controller = new UserDefinedForm_Controller($requiredForm);
+
+ $this->assertEquals($controller->Form()->Fields()->Count(), 2);
+ $this->assertEquals($controller->Form()->Actions()->Count(), 1);
+ $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 1);
+ }
+
+ function testgetFormFields() {
+ // generating the fieldset of fields
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $controller = new UserDefinedForm_Controller($form);
+
+ $fields = $controller->getFormFields();
+
+ $this->assertEquals($fields->Count(), 1);
+
+ // custom error message on a form field
+ $requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
+ $controller = new UserDefinedForm_Controller($requiredForm);
+
+ UserDefinedForm::$required_identifier = "*";
+
+ $fields = $controller->getFormFields();
+
+ $this->assertEquals($fields->First()->getCustomValidationMessage(), 'Custom Error Message');
+ }
+
+ function testGetFormActions() {
+ // generating the fieldset of actions
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $controller = new UserDefinedForm_Controller($form);
+ $actions = $controller->getFormActions();
+
+ // by default will have 1 submit button which links to process
+ $expected = new FieldSet(new FormAction('process', 'Submit'));
+
+ $this->assertEquals($actions, $expected);
+
+ // the custom popup should have a reset button and a custom text
+ $custom = $this->objFromFixture('UserDefinedForm', 'form-with-reset-and-custom-action');
+ $controller = new UserDefinedForm_Controller($custom);
+
+ $actions = $controller->getFormActions();
+
+ $expected = new FieldSet(new FormAction('process', 'Custom Button'));
+ $expected->push(new ResetFormAction("clearForm"));
+
+ $this->assertEquals($actions, $expected);
+ }
+
+ function testArrayToJson() {
+ $array = array('1' => 'one', '2' => 'two');
+ $string = "{\n1:\"one\", 2:\"two\"\n}\n";
+ $this->assertEquals(UserDefinedForm_Controller::array2json($array), $string);
+ }
+
+
+ function testRenderingIntoFormTemplate() {
+ $form = $this->setupFormFrontend();
+
+ $form->Content = 'This is some content without a form nested between it';
+ $form->doPublish();
+
+ $controller = new UserDefinedForm_Controller($form);
+
+ // check to see if $Form is replaced to inside the content
+ $index = new ArrayData($controller->index());
+ $parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
+
+ $this->checkTemplateIsCorrect($parser);
+ }
+
+ function testRenderingIntoTemplateWithSubstringReplacement() {
+ $form = $this->setupFormFrontend();
+
+ $controller = new UserDefinedForm_Controller($form);
+
+ // check to see if $Form is replaced to inside the content
+ $index = new ArrayData($controller->index());
+ $parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
+
+ $this->checkTemplateIsCorrect($parser);
+ }
+
+ function setupFormFrontend() {
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ $this->logInWithPermission('ADMIN');
+
+ $form->doPublish();
+
+ $member = Member::currentUser();
+ $member->logOut();
+
+ return $form;
+ }
+
+ function checkTemplateIsCorrect($parser) {
+ $this->assertArrayHasKey(0, $parser->getBySelector('form#Form_Form'));
+
+ // check for the input
+ $this->assertArrayHasKey(0, $parser->getBySelector('input.text'));
+
+ // check for the label and the text
+ $label = $parser->getBySelector('label.left');
+ $this->assertArrayHasKey(0, $label);
+
+ $this->assertEquals((string) $label[0][0], "Basic Text Field", "Label contains correct field name");
+
+ // check for the action
+ $action = $parser->getBySelector('input.action');
+ $this->assertArrayHasKey(0, $action);
+
+ $this->assertEquals((string) $action[0]['value'], "Submit", "Submit button has default text");
+ }
+}
\ No newline at end of file
diff --git a/tests/UserDefinedFormEditorTest.php b/tests/UserDefinedFormEditorTest.php
deleted file mode 100644
index aabf5ef..0000000
--- a/tests/UserDefinedFormEditorTest.php
+++ /dev/null
@@ -1,102 +0,0 @@
-logInWithPermission('ADMIN');
-
- $this->form = new UserDefinedForm();
- $this->form->write();
- }
-
- function testPublishingNormalField() {
- $id = $this->form->ID;
-
- // test a normal field
- $field = new EditableFormField();
- $field->write();
-
- $this->form->Fields()->add($field);
-
- // upon adding it, it shouldn't be on the live site
- $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $id");
- $this->assertFalse($live);
-
- // upon publishing the field should exist
- $this->form->doPublish();
- $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $id");
- $this->assertEquals($live->Fields()->Count(), 1);
- }
-
- function testPublishingMultipleOptions() {
- $id = $this->form->ID;
- $this->form->Fields()->removeAll();
-
- // test a editable option field
- $dropdown = new EditableDropdown();
- $dropdown->write();
-
- $checkbox = new EditableCheckboxGroupField();
- $checkbox->write();
-
- $option = new EditableOption();
- $option->write();
-
- $option2 = new EditableOption();
- $option2->write();
-
- $dropdown->Options()->add($option);
- $checkbox->Options()->add($option2);
-
- $this->form->Fields()->add($dropdown);
- $this->form->Fields()->add($checkbox);
-
- // upon adding it, it shouldn't be on the live site
- $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $id");
- $this->assertFalse($live);
-
- // and when published it should exist and the option
- $this->form->doPublish();
- $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $id");
- $this->assertEquals($live->Fields()->Count(), 2);
-
- // check they have options attached
- foreach($live->Fields() as $field) {
- $this->assertEquals($field->Options()->Count(), 1);
- }
- }
-
- function testUnpublishing() {
- $id = $this->form->ID;
- $this->form->Fields()->removeAll();
- $this->form->Fields()->add(new EditableFormField());
- $this->form->doUnPublish();
- $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $id");
- $stage = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $id");
- $this->assertEquals($live, false);
- $this->assertEquals($stage->Fields()->Count(), 1);
- }
-
- function testDuplicatingPage() {
- $this->form->Fields()->add(new EditableFormField());
- $form_copy = $this->form->duplicate();
-
- $this->assertEquals($this->form->Fields()->Count(), $form_copy->Fields()->Count());
- }
-
- function tearDown() {
- $this->form->delete();
-
- parent::tearDown();
- }
-}
\ No newline at end of file
diff --git a/tests/UserDefinedFormFieldTest.php b/tests/UserDefinedFormFieldTest.php
deleted file mode 100644
index 7cb7c35..0000000
--- a/tests/UserDefinedFormFieldTest.php
+++ /dev/null
@@ -1,28 +0,0 @@
-Name = "$field";
- $object->Title = "$field";
- $object->write();
-
- $this->assertEquals($field, $object->Name);
- $object->delete();
- }
- }
-}
\ No newline at end of file
diff --git a/tests/UserDefinedFormTest.php b/tests/UserDefinedFormTest.php
new file mode 100644
index 0000000..f0d3055
--- /dev/null
+++ b/tests/UserDefinedFormTest.php
@@ -0,0 +1,221 @@
+logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $form->SubmitButtonText = 'Button Text';
+ $form->write();
+ $form->doPublish();
+ $origVersion = $form->Version;
+
+ $form->SubmitButtonText = 'Updated Button Text';
+ $form->write();
+ $form->doPublish();
+
+ // check published site
+ $updated = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
+ $this->assertEquals($updated->SubmitButtonText, 'Updated Button Text');
+
+ $form->doRollbackTo($origVersion);
+
+ $orignal = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
+ $this->assertEquals($orignal->SubmitButtonText, 'Button Text');
+ }
+
+ function testGetCMSFields() {
+ // ensure all the tabs are present.
+ // @todo a common bug with this is translations messing up the tabs.
+ // @todo only logic we should check for is that the tablelistfield filter
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $fields = $form->getCMSFields();
+
+ $this->assertTrue($fields->dataFieldByName('Fields') !== null);
+ $this->assertTrue($fields->dataFieldByName('EmailRecipients') != null);
+ $this->assertTrue($fields->dataFieldByName('Reports') != null);
+ $this->assertTrue($fields->dataFieldByName('OnCompleteMessage') != null);
+ }
+
+ function testEmailRecipientPopup() {
+ $this->logInWithPermission('ADMIN');
+
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $popup = new UserDefinedForm_EmailRecipient();
+
+ $fields = $popup->getCMSFields_forPopup();
+
+ $this->assertTrue($fields->dataFieldByName('EmailSubject') !== null);
+ $this->assertTrue($fields->dataFieldByName('EmailFrom') !== null);
+ $this->assertTrue($fields->dataFieldByName('EmailAddress') !== null);
+ $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->write();
+
+ $fields = $popup->getCMSFields_forPopup();
+ $this->assertThat($fields->fieldByName('SendEmailToFieldID'), $this->isInstanceOf('DropdownField'));
+
+ // if the front end has checkboxs or dropdown they can select from that can also be used to send things
+ $dropdown = $this->objFromFixture('EditableDropdown', 'department-dropdown');
+ $form->Fields()->add($dropdown);
+
+ $fields = $popup->getCMSFields_forPopup();
+ $this->assertTrue($fields->dataFieldByName('SendEmailToFieldID') !== null);
+
+ $popup->delete();
+ }
+
+ function testPublishing() {
+ $this->logInWithPermission('ADMIN');
+
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ $form->write();
+
+ $form->doPublish();
+
+ $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
+
+ $this->assertNotNull($live);
+ $this->assertEquals($live->Fields()->Count(), 1);
+
+ $dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
+ $form->Fields()->add($dropdown);
+
+ $stage = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
+ $this->assertEquals($stage->Fields()->Count(), 2);
+
+ // should not have published the dropdown
+ $liveDropdown = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $dropdown->ID");
+ $this->assertFalse($liveDropdown);
+
+ // when publishing it should have added it
+ $form->doPublish();
+
+ $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
+ $this->assertEquals($live->Fields()->Count(), 2);
+
+ // edit the title
+ $text = $form->Fields()->First();
+
+ $text->Title = 'Edited title';
+ $text->write();
+
+ $liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
+ $this->assertFalse($liveText->Title == $text->Title);
+
+ $form->doPublish();
+
+ $liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
+ $this->assertTrue($liveText->Title == $text->Title);
+ }
+
+ function testUnpublishing() {
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ $form->write();
+
+ $form->doPublish();
+
+ // assert that it exists and has a field
+ $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
+
+ $this->assertTrue(isset($live));
+ $this->assertEquals(DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value(), 1);
+
+ // unpublish
+ $form->doUnpublish();
+
+ $this->assertFalse(Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"));
+ $this->assertEquals(DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value(), 0);
+
+ }
+
+ function testDoRevertToLive() {
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ $form->SubmitButtonText = 'Button Text';
+ $form->doPublish();
+ $text = $form->Fields()->First();
+
+ $form->SubmitButtonText = 'Edited Button Text';
+ $form->write();
+
+ $text->Title = 'Edited title';
+ $text->write();
+
+ // check that the published version is not updated
+ $liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
+
+ $revertTo = $liveText->Title;
+
+ $this->assertFalse($revertTo == $text->Title);
+
+ // revert back to the live data
+ $form->doRevertToLive();
+
+ $check = Versioned::get_one_by_stage("EditableFormField", "Stage", "\"EditableFormField\".\"ID\" = $text->ID");
+
+ $this->assertEquals($check->Title, $revertTo);
+
+ // check the edited buttoned
+ $liveForm = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
+ $revertedForm = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
+
+ $this->assertEquals($liveForm->SubmitButtonText, $revertedForm->SubmitButtonText);
+ }
+
+ function testDuplicatingForm() {
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $duplicate = $form->duplicate();
+
+ $this->assertEquals($form->Fields()->Count(), $duplicate->Fields()->Count());
+ $this->assertEquals($form->EmailRecipients()->Count(), $form->EmailRecipients()->Count());
+
+ // can't compare object since the dates/ids change
+ $this->assertEquals($form->Fields()->First()->Title, $duplicate->Fields()->First()->Title);
+ }
+
+ /**
+ * @todo once getIsModifiedOnStage is implemented will need to implement this
+ */
+ function testGetIsModifiedOnStage() {
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $this->assertTrue($form->getIsModifiedOnStage());
+ }
+
+ function testFormOptions() {
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+
+ $fields = $form->getFormOptions();
+ $submit = $fields->fieldByName('SubmitButtonText');
+ $reset = $fields->fieldByName('ShowClearButton');
+
+ $this->assertEquals($submit->Title(), 'Text on submit button:');
+ $this->assertEquals($reset->Title(), 'Show Clear Form Button');
+ }
+}
\ No newline at end of file
diff --git a/tests/UserDefinedFormTest.yml b/tests/UserDefinedFormTest.yml
new file mode 100644
index 0000000..43d5a42
--- /dev/null
+++ b/tests/UserDefinedFormTest.yml
@@ -0,0 +1,87 @@
+EditableOption:
+ option-1:
+ Name: Option1
+ Title: Option 1
+ Sort: 1
+
+ option-2:
+ Name: Option2
+ Title: Option 2
+ Sort: 2
+ department-1:
+ Name: dept1
+ Title: sales@example.com
+
+ department-2:
+ Name: dept2
+ Title: accounts@example.com
+
+UserDefinedForm_EmailRecipient:
+ recipient-1:
+ EmailAddress: test@example.com
+ EmailSubject: Email Subject
+ EmailFrom: no-reply@example.com
+
+ no-html:
+ EmailAddress: nohtml@example.com
+ EmailSubject: Email Subject
+ EmailFrom: no-reply@example.com
+ SendPlain: true
+
+ no-data:
+ EmailAddress: nodata@example.com
+ EmailSubject: Email Subject
+ EmailFrom: no-reply@example.com
+ HideFormData: true
+
+EditableTextField:
+ basic-text:
+ Name: basic-text-name
+ Title: Basic Text Field
+
+ required-text:
+ Name: required-text-field
+ Title: Required Text Field
+ CustomErrorMessage: Custom Error Message
+ RightTitle: Right Title
+ Required: true
+
+EditableDropdown:
+ basic-dropdown:
+ Name: basic-dropdown
+ Title: Basic Dropdown Field
+ Options: =>EditableOption.option-1, =>EditableOption.option-2
+
+ department-dropdown:
+ Name: department
+ Title: Department
+ Options: =>EditableOption.department-1, =>EditableOption.department-2
+
+EditableCheckbox:
+ checkbox-1:
+ Name: checkbox-1
+ Title: Checkbox 1
+
+EditableEmailField:
+ email-field:
+ Name: email-field
+ Title: Email
+
+UserDefinedForm:
+ basic-form-page:
+ Title: User Defined Form
+ Fields: =>EditableTextField.basic-text
+ EmailRecipients: =>UserDefinedForm_EmailRecipient.recipient-1, =>UserDefinedForm_EmailRecipient.no-html, =>UserDefinedForm_EmailRecipient.no-data
+
+ form-with-reset-and-custom-action:
+ Title: Form with Reset Action
+ SubmitButtonText: Custom Button
+ ShowClearButton: true
+
+ validation-form:
+ Title: Validation Form
+ Fields: =>EditableTextField.required-text
+
+
+
+
\ No newline at end of file
diff --git a/tests/templates/UserDefinedFormControllerTest.ss b/tests/templates/UserDefinedFormControllerTest.ss
new file mode 100644
index 0000000..0779827
--- /dev/null
+++ b/tests/templates/UserDefinedFormControllerTest.ss
@@ -0,0 +1,5 @@
+
+
+$Content
+$Form
+
\ No newline at end of file