mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge branch '5.7' into 5.8
This commit is contained in:
commit
ce2fe31bdd
2
client/thirdparty/jquery-3.4.1.min.js
vendored
Normal file
2
client/thirdparty/jquery-3.4.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -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'
|
||||
);
|
||||
|
@ -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)) {
|
||||
|
@ -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
|
||||
|
15
tests/Extension/UserFormBlockStub.php
Normal file
15
tests/Extension/UserFormBlockStub.php
Normal 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;
|
||||
}
|
77
tests/Extension/UserFormFieldEditorExtensionTest.php
Normal file
77
tests/Extension/UserFormFieldEditorExtensionTest.php
Normal 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);
|
||||
}
|
||||
}
|
23
tests/Extension/UserFormFieldEditorExtensionTest.yml
Normal file
23
tests/Extension/UserFormFieldEditorExtensionTest.yml
Normal 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
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user