Merge branch '5.7' into 5.8

This commit is contained in:
Steve Boyd 2021-01-17 15:58:55 +13:00
commit ce2fe31bdd
8 changed files with 141 additions and 1 deletions

2
client/thirdparty/jquery-3.4.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -65,7 +65,7 @@ class UserDefinedFormController extends PageController
// load the jquery
if (!$page->config()->get('block_default_userforms_js')) {
Requirements::javascript('//code.jquery.com/jquery-3.4.1.min.js');
Requirements::javascript('silverstripe/userforms:client/thirdparty/jquery-3.4.1.min.js');
Requirements::javascript(
'silverstripe/userforms:client/thirdparty/jquery-validate/jquery.validate.min.js'
);

View File

@ -196,6 +196,7 @@ class UserFormFieldEditorExtension extends DataExtension
$live = Versioned::get_by_stage(EditableFormField::class, Versioned::LIVE)
->filter([
'ParentID' => $this->owner->ID,
'ParentClass' => get_class($this->owner),
]);
if (!empty($seenIDs)) {

View File

@ -413,6 +413,11 @@ class EditableFormField extends DataObject
{
parent::onBeforeWrite();
$formField = $this->getFormField();
if ($formField && !$formField->hasData()) {
$this->Required = false;
}
// Set a field name.
if (!$this->Name) {
// New random name

View File

@ -0,0 +1,15 @@
<?php
namespace SilverStripe\UserForms\Tests\Extension;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\UserForms\UserForm;
/**
* A stand in for e.g. dnadesigned/silverstripe-elemental-userforms
*/
class UserFormBlockStub extends DataObject implements TestOnly
{
use UserForm;
}

View File

@ -0,0 +1,77 @@
<?php
namespace SilverStripe\UserForms\Tests\Extension;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\Versioned\Versioned;
class UserFormFieldEditorExtensionTest extends SapphireTest
{
protected static $fixture_file = 'UserFormFieldEditorExtensionTest.yml';
protected static $extra_dataobjects = [
UserFormBlockStub::class,
];
protected function setUp()
{
parent::setUp();
$page = $this->objFromFixture(UserDefinedForm::class, 'page');
$block = $this->objFromFixture(UserFormBlockStub::class, 'block');
$page->publishRecursive();
$block->publishRecursive();
}
public function testOrphanRemovalDoesNotAffectOtherClassesWithTheSameID()
{
$page = $this->objFromFixture(UserDefinedForm::class, 'page');
$block = $this->objFromFixture(UserFormBlockStub::class, 'block');
// assert setup
$this->assertSame($page->ID, $block->ID);
$this->assertCount(1, $page->Fields());
$this->assertCount(3, $block->Fields());
// ensure setup has affected live mode too
$origReadingMode = Versioned::get_reading_mode();
Versioned::set_reading_mode(Versioned::LIVE);
$initialLivePage = UserDefinedForm::get()->First();
$initialLiveBlock = UserFormBlockStub::get()->First();
$this->assertSame($initialLivePage->ID, $initialLiveBlock->ID);
$this->assertCount(1, $initialLivePage->Fields());
$this->assertCount(3, $initialLiveBlock->Fields());
Versioned::set_reading_mode($origReadingMode);
// execute change
$newField = new EditableEmailField();
$newField->update([
'Name' => 'basic_email_name',
'Title' => 'Page Email Field'
]);
$page->Fields()->add($newField);
$page->publishRecursive();
// assert effect of change
$checkPage = UserDefinedForm::get()->First();
$checkBlock = UserFormBlockStub::get()->First();
$this->assertCount(2, $checkPage->Fields());
$this->assertCount(3, $checkBlock->Fields());
// ensure this is true for live mode too
$origReadingMode = Versioned::get_reading_mode();
Versioned::set_reading_mode(Versioned::LIVE);
$checkLivePage = UserDefinedForm::get()->First();
$checkLiveBlock = UserFormBlockStub::get()->First();
$this->assertCount(2, $checkLivePage->Fields());
$this->assertCount(3, $checkLiveBlock->Fields());
Versioned::set_reading_mode($origReadingMode);
}
}

View File

@ -0,0 +1,23 @@
SilverStripe\UserForms\Model\UserDefinedForm:
page:
ID: 9999
SilverStripe\UserForms\Tests\Extension\UserFormBlockStub:
block:
ID: 9999
SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
page-text-field:
Name: basic_text_name
Title: Page Text Field
Parent: =>SilverStripe\UserForms\Model\UserDefinedForm.page
block-text-field-1:
Name: basic_text_name_2
Title: Block Text Field
Parent: =>SilverStripe\UserForms\Tests\Extension\UserFormBlockStub.block
block-text-field-2:
Name: basic_text_name_3
Title: Block Text Field
Parent: =>SilverStripe\UserForms\Tests\Extension\UserFormBlockStub.block
block-text-field-3:
Name: basic_text_name_4
Title: Block Text Field
Parent: =>SilverStripe\UserForms\Tests\Extension\UserFormBlockStub.block

View File

@ -10,6 +10,7 @@ use SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableCheckbox;
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
use SilverStripe\UserForms\Model\EditableFormField\EditableOption;
use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
@ -292,4 +293,20 @@ class EditableFormFieldTest extends FunctionalTest
$field = $this->objFromFixture(EditableTextField::class, $fieldName);
$this->assertEquals($expected, $field->isDisplayed($data));
}
public function testChangingDataFieldTypeToDatalessRemovesRequiredSetting()
{
$requiredTextField = $this->objFromFixture(EditableTextField::class, 'required-text');
$fieldId = $requiredTextField->ID;
$this->assertTrue((bool)$requiredTextField->Required);
$literalField = $requiredTextField->newClassInstance(EditableLiteralField::class);
$this->assertTrue((bool)$literalField->Required);
$literalField->write();
$this->assertFalse((bool)$literalField->Required);
$updatedField = EditableFormField::get()->byId($fieldId);
$this->assertFalse((bool)$updatedField->Required);
}
}