Merge branch '5.8' into 5.9

This commit is contained in:
Maxime Rainville 2021-05-28 14:36:23 +12:00
commit 9e66b403be
2 changed files with 38 additions and 22 deletions

View File

@ -31,21 +31,20 @@ class UserFormFieldEditorExtensionTest extends SapphireTest
// assert setup // assert setup
$this->assertSame($page->ID, $block->ID); $this->assertSame($page->ID, $block->ID);
$this->assertCount(1, $page->Fields()); $this->assertCount(2, $page->Fields(), 'Draft UserForm page starts with 2 fields');
$this->assertCount(3, $block->Fields()); $this->assertCount(3, $block->Fields(), 'Draft UserForm block starts with 3 fields');
// ensure setup has affected live mode too // ensure setup has affected live mode too
$origReadingMode = Versioned::get_reading_mode(); $origReadingMode = Versioned::get_reading_mode();
Versioned::withVersionedMode(function () {
Versioned::set_reading_mode(Versioned::LIVE); Versioned::set_reading_mode(Versioned::LIVE);
$initialLivePage = UserDefinedForm::get()->First(); $initialLivePage = UserDefinedForm::get()->First();
$initialLiveBlock = UserFormBlockStub::get()->First(); $initialLiveBlock = UserFormBlockStub::get()->First();
$this->assertSame($initialLivePage->ID, $initialLiveBlock->ID); $this->assertSame($initialLivePage->ID, $initialLiveBlock->ID);
$this->assertCount(1, $initialLivePage->Fields()); $this->assertCount(2, $initialLivePage->Fields(), 'Live UserForm page starst with 2 fields');
$this->assertCount(3, $initialLiveBlock->Fields()); $this->assertCount(3, $initialLiveBlock->Fields(), 'Live UserForm block starst with 3 fields');
});
Versioned::set_reading_mode($origReadingMode);
// execute change // execute change
$newField = new EditableEmailField(); $newField = new EditableEmailField();
@ -57,21 +56,32 @@ class UserFormFieldEditorExtensionTest extends SapphireTest
$page->publishRecursive(); $page->publishRecursive();
// assert effect of change // assert effect of change
/** @var UserDefinedForm $checkPage */
$checkPage = UserDefinedForm::get()->First(); $checkPage = UserDefinedForm::get()->First();
$checkBlock = UserFormBlockStub::get()->First(); $checkBlock = UserFormBlockStub::get()->First();
$this->assertCount(2, $checkPage->Fields()); $this->assertCount(3, $checkPage->Fields(), 'Field has been added to draft user form page');
$this->assertCount(3, $checkBlock->Fields()); $this->assertCount(
3,
$checkBlock->Fields(),
'Draft userform block with same ID is not affected'
);
// ensure this is true for live mode too // ensure this is true for live mode too
$origReadingMode = Versioned::get_reading_mode(); Versioned::withVersionedMode(function () {
Versioned::set_reading_mode(Versioned::LIVE); Versioned::set_reading_mode(Versioned::LIVE);
$checkLivePage = UserDefinedForm::get()->First(); $checkLivePage = UserDefinedForm::get()->First();
$checkLiveBlock = UserFormBlockStub::get()->First(); $checkLiveBlock = UserFormBlockStub::get()->First();
$this->assertCount(2, $checkLivePage->Fields()); $this->assertCount(
$this->assertCount(3, $checkLiveBlock->Fields()); 3,
$checkLivePage->Fields(),
Versioned::set_reading_mode($origReadingMode); 'Field has been added to live user form page'
);
$this->assertCount(
3,
$checkLiveBlock->Fields(),
'Live userform block with same ID is not affected'
);
});
} }
} }

View File

@ -4,6 +4,12 @@ SilverStripe\UserForms\Model\UserDefinedForm:
SilverStripe\UserForms\Tests\Extension\UserFormBlockStub: SilverStripe\UserForms\Tests\Extension\UserFormBlockStub:
block: block:
ID: 9999 ID: 9999
SilverStripe\UserForms\Model\EditableFormField\EditableFormStep:
pageFirstStep:
Title: First Step
Parent: =>SilverStripe\UserForms\Model\UserDefinedForm.page
SilverStripe\UserForms\Model\EditableFormField\EditableTextField: SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
page-text-field: page-text-field:
Name: basic_text_name Name: basic_text_name