2010-09-03 07:06:13 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
|
|
|
|
class UserDefinedFormTest extends FunctionalTest {
|
|
|
|
|
|
|
|
static $fixture_file = 'userforms/tests/UserDefinedFormTest.yml';
|
|
|
|
|
|
|
|
|
|
|
|
function testRollbackToVersion() {
|
2012-05-07 12:00:18 +02:00
|
|
|
$this->markTestSkipped(
|
|
|
|
'UserDefinedForm::rollback() has not been implemented completely'
|
|
|
|
);
|
2010-09-03 07:06:13 +02:00
|
|
|
|
2012-05-07 12:00:18 +02:00
|
|
|
// @todo
|
2010-09-03 07:06:13 +02:00
|
|
|
$this->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() {
|
|
|
|
$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);
|
2014-10-27 16:38:14 +01:00
|
|
|
$this->assertTrue($fields->dataFieldByName('Submissions') != null);
|
2010-09-03 07:06:13 +02:00
|
|
|
$this->assertTrue($fields->dataFieldByName('OnCompleteMessage') != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testEmailRecipientPopup() {
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
|
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
|
|
|
|
|
|
|
$popup = new UserDefinedForm_EmailRecipient();
|
|
|
|
|
2012-04-22 21:17:42 +02:00
|
|
|
$fields = $popup->getCMSFields();
|
2010-09-03 07:06:13 +02:00
|
|
|
|
|
|
|
$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);
|
2010-09-08 00:44:43 +02:00
|
|
|
|
2010-09-03 07:06:13 +02:00
|
|
|
// add an email field, it should now add a or from X address picker
|
|
|
|
$email = $this->objFromFixture('EditableEmailField','email-field');
|
|
|
|
$form->Fields()->add($email);
|
2010-09-08 00:44:43 +02:00
|
|
|
|
|
|
|
$popup->FormID = $form->ID;
|
2010-09-03 07:06:13 +02:00
|
|
|
$popup->write();
|
|
|
|
|
2012-04-22 21:17:42 +02:00
|
|
|
$fields = $popup->getCMSFields();
|
2010-09-03 07:06:13 +02:00
|
|
|
$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);
|
|
|
|
|
2012-04-22 21:17:42 +02:00
|
|
|
$fields = $popup->getCMSFields();
|
2010-09-03 07:06:13 +02:00
|
|
|
$this->assertTrue($fields->dataFieldByName('SendEmailToFieldID') !== null);
|
|
|
|
|
|
|
|
$popup->delete();
|
|
|
|
}
|
2015-07-16 05:06:53 +02:00
|
|
|
|
|
|
|
function testGetEmailBodyContent() {
|
|
|
|
$recipient = new UserDefinedForm_EmailRecipient();
|
|
|
|
|
|
|
|
$emailBody = 'not html';
|
|
|
|
$emailBodyHtml = '<p>html</p>';
|
|
|
|
|
|
|
|
$recipient->EmailBody = $emailBody;
|
|
|
|
$recipient->EmailBodyHtml = $emailBodyHtml;
|
|
|
|
$recipient->write();
|
|
|
|
|
|
|
|
$this->assertEquals($recipient->SendPlain, 0);
|
|
|
|
$this->assertEquals($recipient->getEmailBodyContent(), $emailBodyHtml);
|
|
|
|
|
|
|
|
$recipient->SendPlain = 1;
|
|
|
|
$recipient->write();
|
|
|
|
|
|
|
|
$this->assertEquals($recipient->getEmailBodyContent(), $emailBody);
|
|
|
|
|
|
|
|
$recipient->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetEmailTemplateDropdownValues() {
|
|
|
|
$recipient = new UserDefinedForm_EmailRecipient();
|
|
|
|
|
|
|
|
$defaultValues = array('SubmittedFormEmail' => 'SubmittedFormEmail');
|
|
|
|
|
|
|
|
$this->assertEquals($recipient->getEmailTemplateDropdownValues(), $defaultValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testEmailTemplateExists() {
|
|
|
|
$recipient = new UserDefinedForm_EmailRecipient();
|
|
|
|
|
|
|
|
// Set the default template
|
|
|
|
$recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues()));
|
|
|
|
$recipient->write();
|
|
|
|
|
|
|
|
// The default template exists
|
|
|
|
$this->assertTrue($recipient->emailTemplateExists());
|
|
|
|
|
|
|
|
// A made up template doesn't exists
|
|
|
|
$this->assertFalse($recipient->emailTemplateExists('MyTemplateThatsNotThere'));
|
|
|
|
|
|
|
|
$recipient->delete();
|
|
|
|
}
|
|
|
|
|
2010-09-08 00:44:43 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:06:13 +02:00
|
|
|
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");
|
2012-05-07 12:00:18 +02:00
|
|
|
$this->assertNull($liveDropdown);
|
2010-09-03 07:06:13 +02:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2012-05-07 12:00:18 +02:00
|
|
|
$this->assertNull(Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"));
|
2010-09-03 07:06:13 +02:00
|
|
|
$this->assertEquals(DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value(), 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDoRevertToLive() {
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
2012-05-07 12:00:18 +02:00
|
|
|
$field = $form->Fields()->First();
|
2010-09-03 07:06:13 +02:00
|
|
|
|
2012-05-07 12:00:18 +02:00
|
|
|
$field->Title = 'Title';
|
|
|
|
$field->write();
|
2010-09-03 07:06:13 +02:00
|
|
|
|
2012-05-07 12:00:18 +02:00
|
|
|
$form->doPublish();
|
|
|
|
|
|
|
|
$field->Title = 'Edited title';
|
|
|
|
$field->write();
|
2010-09-03 07:06:13 +02:00
|
|
|
|
2012-05-07 12:00:18 +02:00
|
|
|
// check that the published version is not updated
|
|
|
|
$live = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $field->ID");
|
|
|
|
$this->assertEquals('Title', $live->Title);
|
2010-09-03 07:06:13 +02:00
|
|
|
|
|
|
|
// revert back to the live data
|
|
|
|
$form->doRevertToLive();
|
2012-05-07 12:00:18 +02:00
|
|
|
$form->flushCache();
|
2010-09-03 07:06:13 +02:00
|
|
|
|
2012-05-07 12:00:18 +02:00
|
|
|
$check = Versioned::get_one_by_stage("EditableFormField", "Stage", "\"EditableFormField\".\"ID\" = $field->ID");
|
2010-09-03 07:06:13 +02:00
|
|
|
|
2012-05-07 12:00:18 +02:00
|
|
|
$this->assertEquals('Title', $check->Title);
|
2010-09-03 07:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|