BUGFIX: fixed conflict of Versioned extension functions. MINOR: added tests for publishing multiple option fields

This commit is contained in:
Will Rossiter 2009-12-12 08:59:20 +00:00
parent 2d46d7ff69
commit 70f05b891e
4 changed files with 81 additions and 17 deletions

View File

@ -119,14 +119,14 @@ class UserDefinedForm extends Page {
if($live) { if($live) {
foreach($live as $field) { foreach($live as $field) {
$field->deleteFromStage('Live'); $field->doDeleteFromStage('Live');
} }
} }
// publish the draft pages // publish the draft pages
if($this->Fields()) { if($this->Fields()) {
foreach($this->Fields() as $field) { foreach($this->Fields() as $field) {
$field->publish('Stage', 'Live'); $field->doPublish('Stage', 'Live');
} }
} }
@ -144,7 +144,7 @@ class UserDefinedForm extends Page {
public function doUnpublish() { public function doUnpublish() {
if($this->Fields()) { if($this->Fields()) {
foreach($this->Fields() as $field) { foreach($this->Fields() as $field) {
$field->deleteFromStage('Live'); $field->doDeleteFromStage('Live');
} }
} }

View File

@ -81,6 +81,25 @@ class EditableFormField extends DataObject {
return $this->Parent()->canEdit(); 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 * Show this form on load or not
* *

View File

@ -27,7 +27,7 @@ class EditableMultipleOptionField extends EditableFormField {
* *
* @return void * @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"); $live = Versioned::get_by_stage("EditableOption", "Live", "\"EditableOption\".\"ParentID\" = $this->ID");
if($live) { 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 * @return void
*/ */
public function deleteFromStage($stage) { public function doDeleteFromStage($stage) {
if($this->Options()) { if($this->Options()) {
foreach($this->Options() as $option) { foreach($this->Options() as $option) {
$option->deleteFromStage($stage); $option->deleteFromStage($stage);
} }
} }
parent::deleteFromStage($stage); $this->deleteFromStage($stage);
} }
/** /**

View File

@ -13,31 +13,76 @@ class UserDefinedFormEditorTest extends FunctionalTest {
function setUp() { function setUp() {
parent::setUp(); parent::setUp();
$this->logInWithPermssion('ADMIN');
$this->form = new UserDefinedForm(); $this->form = new UserDefinedForm();
$this->form->write(); $this->form->write();
} }
function testPublishing() { function testPublishingNormalField() {
$this->logInWithPermssion('ADMIN');
$id = $this->form->ID; $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(); $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", "\"UserDefinedForm_Live\".\"ID\" = $id");
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", $whereClause);
$this->assertEquals($live->Fields()->Count(), 1); $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() { function testUnpublishing() {
$id = $this->form->ID; $id = $this->form->ID;
$this->form->Fields()->removeAll(); $this->form->Fields()->removeAll();
$this->form->Fields()->add(new EditableFormField()); $this->form->Fields()->add(new EditableFormField());
$this->form->doUnPublish(); $this->form->doUnPublish();
$whereClauseStage = defined('DB::USE_ANSI_SQL') ? "\"UserDefinedForm\".\"ID\" = $id" : "UserDefinedForm.ID = $id"; $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $id");
$whereClauseLive = defined('DB::USE_ANSI_SQL') ? "\"UserDefinedForm_Live\".\"ID\" = $id" : "UserDefinedForm_Live.ID = $id"; $stage = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $id");
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", $whereClauseLive);
$stage = Versioned::get_one_by_stage("UserDefinedForm", "Stage", $whereClauseStage);
$this->assertEquals($live, false); $this->assertEquals($live, false);
$this->assertEquals($stage->Fields()->Count(), 1); $this->assertEquals($stage->Fields()->Count(), 1);
} }