mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
BUGFIX: fixed conflict of Versioned extension functions. MINOR: added tests for publishing multiple option fields
This commit is contained in:
parent
2d46d7ff69
commit
70f05b891e
@ -119,14 +119,14 @@ class UserDefinedForm extends Page {
|
||||
|
||||
if($live) {
|
||||
foreach($live as $field) {
|
||||
$field->deleteFromStage('Live');
|
||||
$field->doDeleteFromStage('Live');
|
||||
}
|
||||
}
|
||||
|
||||
// publish the draft pages
|
||||
if($this->Fields()) {
|
||||
foreach($this->Fields() as $field) {
|
||||
$field->publish('Stage', 'Live');
|
||||
$field->doPublish('Stage', 'Live');
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ class UserDefinedForm extends Page {
|
||||
public function doUnpublish() {
|
||||
if($this->Fields()) {
|
||||
foreach($this->Fields() as $field) {
|
||||
$field->deleteFromStage('Live');
|
||||
$field->doDeleteFromStage('Live');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,25 @@ class EditableFormField extends DataObject {
|
||||
return $this->Parent()->canEdit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish this Form Field to the live site
|
||||
*
|
||||
* Wrapper for the {@link Versioned} publish function
|
||||
*/
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
|
||||
$this->publish($fromStage, $toStage, $createNewVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this form from a given stage
|
||||
*
|
||||
* Wrapper for the {@link Versioned} deleteFromStage function
|
||||
*/
|
||||
public function doDeleteFromStage($stage) {
|
||||
$this->deleteFromStage($stage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show this form on load or not
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function publish($fromStage, $toStage, $createNewVersion = false) {
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
|
||||
$live = Versioned::get_by_stage("EditableOption", "Live", "\"EditableOption\".\"ParentID\" = $this->ID");
|
||||
|
||||
if($live) {
|
||||
@ -41,7 +41,7 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
}
|
||||
}
|
||||
|
||||
parent::publish($fromStage, $toStage, $createNewVersion);
|
||||
$this->publish($fromStage, $toStage, $createNewVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,14 +51,14 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteFromStage($stage) {
|
||||
public function doDeleteFromStage($stage) {
|
||||
if($this->Options()) {
|
||||
foreach($this->Options() as $option) {
|
||||
$option->deleteFromStage($stage);
|
||||
}
|
||||
}
|
||||
|
||||
parent::deleteFromStage($stage);
|
||||
$this->deleteFromStage($stage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,31 +13,76 @@ class UserDefinedFormEditorTest extends FunctionalTest {
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->logInWithPermssion('ADMIN');
|
||||
|
||||
$this->form = new UserDefinedForm();
|
||||
$this->form->write();
|
||||
}
|
||||
|
||||
function testPublishing() {
|
||||
$this->logInWithPermssion('ADMIN');
|
||||
|
||||
function testPublishingNormalField() {
|
||||
$id = $this->form->ID;
|
||||
$this->form->Fields()->add(new EditableFormField());
|
||||
|
||||
// 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();
|
||||
$whereClause = defined('DB::USE_ANSI_SQL') ? "\"UserDefinedForm_Live\".\"ID\" = $id" : "UserDefinedForm_Live.ID = $id";
|
||||
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", $whereClause);
|
||||
$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();
|
||||
$whereClauseStage = defined('DB::USE_ANSI_SQL') ? "\"UserDefinedForm\".\"ID\" = $id" : "UserDefinedForm.ID = $id";
|
||||
$whereClauseLive = defined('DB::USE_ANSI_SQL') ? "\"UserDefinedForm_Live\".\"ID\" = $id" : "UserDefinedForm_Live.ID = $id";
|
||||
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", $whereClauseLive);
|
||||
$stage = Versioned::get_one_by_stage("UserDefinedForm", "Stage", $whereClauseStage);
|
||||
$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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user