|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class UserFormsVersionedTest extends SapphireTest |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
protected static $fixture_file = 'UserDefinedFormTest.yml'; |
|
7
|
|
|
|
|
8
|
|
|
public function setUp() |
|
9
|
|
|
{ |
|
10
|
|
|
parent::setUp(); |
|
11
|
|
|
Versioned::reading_stage('Stage'); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function testPublishing() |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var UserDefinedForm $form */ |
|
17
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'filtered-form-page'); |
|
18
|
|
|
|
|
19
|
|
|
// Get id of options |
|
20
|
|
|
$optionID = $this->idFromFixture('EditableOption', 'option-3'); |
|
21
|
|
|
$this->assertEmpty(Versioned::get_one_by_stage('EditableOption', 'Live', array('"ID" = ?' => $optionID))); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
// Publishing writes this to live |
|
24
|
|
|
$form->doPublish(); |
|
25
|
|
|
$liveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $optionID, false); |
|
26
|
|
|
$this->assertNotEmpty($liveVersion); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
// Add new option, and repeat publish process |
|
29
|
|
|
/** @var EditableCheckboxGroupField $list */ |
|
30
|
|
|
$list = $this->objFromFixture('EditableCheckboxGroupField', 'checkbox-group'); |
|
31
|
|
|
$newOption = new EditableOption(); |
|
32
|
|
|
$newOption->Title = 'New option'; |
|
|
|
|
|
|
33
|
|
|
$newOption->Value = 'ok'; |
|
|
|
|
|
|
34
|
|
|
$newOption->write(); |
|
35
|
|
|
$newOptionID = $newOption->ID; |
|
36
|
|
|
$list->Options()->add($newOption); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$form->doPublish(); |
|
39
|
|
|
|
|
40
|
|
|
// Un-modified option should not create a new version |
|
41
|
|
|
$newLiveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $optionID, false); |
|
42
|
|
|
$this->assertNotEmpty($newLiveVersion); |
|
|
|
|
|
|
43
|
|
|
$this->assertEquals($liveVersion, $newLiveVersion); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
// New option is successfully published |
|
46
|
|
|
$newOptionLiveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $newOptionID, false); |
|
47
|
|
|
$this->assertNotEmpty($newOptionLiveVersion); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.