-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #558 from open-sausages/pulls/4.2/fix-publishing
BUG Use non-destructive publishing for editable options
- Loading branch information
Showing
3 changed files
with
112 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
|
||
class UserFormsVersionedTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'UserDefinedFormTest.yml'; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
Versioned::reading_stage('Stage'); | ||
} | ||
|
||
public function testPublishing() | ||
{ | ||
/** @var UserDefinedForm $form */ | ||
$form = $this->objFromFixture('UserDefinedForm', 'filtered-form-page'); | ||
|
||
// Get id of options | ||
$optionID = $this->idFromFixture('EditableOption', 'option-3'); | ||
$this->assertEmpty(Versioned::get_one_by_stage('EditableOption', 'Live', array('"ID" = ?' => $optionID))); | ||
|
||
// Publishing writes this to live | ||
$form->doPublish(); | ||
$liveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $optionID, false); | ||
$this->assertNotEmpty($liveVersion); | ||
|
||
// Add new option, and repeat publish process | ||
/** @var EditableCheckboxGroupField $list */ | ||
$list = $this->objFromFixture('EditableCheckboxGroupField', 'checkbox-group'); | ||
$newOption = new EditableOption(); | ||
$newOption->Title = 'New option'; | ||
$newOption->Value = 'ok'; | ||
$newOption->write(); | ||
$newOptionID = $newOption->ID; | ||
$list->Options()->add($newOption); | ||
|
||
$form->doPublish(); | ||
|
||
// Un-modified option should not create a new version | ||
$newLiveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $optionID, false); | ||
$this->assertNotEmpty($newLiveVersion); | ||
$this->assertEquals($liveVersion, $newLiveVersion); | ||
|
||
// New option is successfully published | ||
$newOptionLiveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $newOptionID, false); | ||
$this->assertNotEmpty($newOptionLiveVersion); | ||
} | ||
} |