Merge pull request #754 from creative-commoners/pulls/5.0/allow-empty-field-titles

FIX Allow editable form fields to have nullable titles rather than fallback to Name
This commit is contained in:
Dylan Wagstaff 2018-03-26 11:05:06 +13:00 committed by GitHub
commit 0a9f3f4365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 211 additions and 19 deletions

View File

@ -44,7 +44,7 @@ class EditableCheckbox extends EditableFormField
public function getFormField() public function getFormField()
{ {
$field = CheckboxField::create($this->Name, $this->Title, $this->CheckedDefault) $field = CheckboxField::create($this->Name, $this->Title ?: false, $this->CheckedDefault)
->setFieldHolderTemplate(__CLASS__ . '_holder') ->setFieldHolderTemplate(__CLASS__ . '_holder')
->setTemplate(__CLASS__); ->setTemplate(__CLASS__);

View File

@ -25,7 +25,7 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField
public function getFormField() public function getFormField()
{ {
$field = UserFormsCheckboxSetField::create($this->Name, $this->Title, $this->getOptionsMap()) $field = UserFormsCheckboxSetField::create($this->Name, $this->Title ?: false, $this->getOptionsMap())
->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder') ->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder')
->setTemplate(UserFormsCheckboxSetField::class); ->setTemplate(UserFormsCheckboxSetField::class);

View File

@ -35,7 +35,7 @@ class EditableCountryDropdownField extends EditableFormField
public function getFormField() public function getFormField()
{ {
$field = DropdownField::create($this->Name, $this->Title) $field = DropdownField::create($this->Name, $this->Title ?: false)
->setSource(i18n::getData()->getCountries()) ->setSource(i18n::getData()->getCountries())
->setFieldHolderTemplate(EditableFormField::class . '_holder') ->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(EditableDropdown::class); ->setTemplate(EditableDropdown::class);

View File

@ -58,7 +58,7 @@ class EditableDateField extends EditableFormField
? DBDatetime::now()->Format('Y-m-d') ? DBDatetime::now()->Format('Y-m-d')
: $this->Default; : $this->Default;
$field = FormField::create($this->Name, $this->Title, $defaultValue) $field = FormField::create($this->Name, $this->Title ?: false, $defaultValue)
->setFieldHolderTemplate(EditableFormField::class . '_holder') ->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(EditableFormField::class); ->setTemplate(EditableFormField::class);

View File

@ -60,7 +60,7 @@ class EditableDropdown extends EditableMultipleOptionField
*/ */
public function getFormField() public function getFormField()
{ {
$field = DropdownField::create($this->Name, $this->Title, $this->getOptionsMap()) $field = DropdownField::create($this->Name, $this->Title ?: false, $this->getOptionsMap())
->setFieldHolderTemplate(EditableFormField::class . '_holder') ->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(__CLASS__); ->setTemplate(__CLASS__);

View File

@ -30,7 +30,7 @@ class EditableEmailField extends EditableFormField
public function getFormField() public function getFormField()
{ {
$field = EmailField::create($this->Name, $this->Title, $this->Default) $field = EmailField::create($this->Name, $this->Title ?: false, $this->Default)
->setFieldHolderTemplate(EditableFormField::class . '_holder') ->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(EditableFormField::class); ->setTemplate(EditableFormField::class);

View File

@ -97,7 +97,7 @@ class EditableFileField extends EditableFormField
public function getFormField() public function getFormField()
{ {
$field = FileField::create($this->Name, $this->Title) $field = FileField::create($this->Name, $this->Title ?: false)
->setFieldHolderTemplate(EditableFormField::class . '_holder') ->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(__CLASS__); ->setTemplate(__CLASS__);

View File

@ -68,7 +68,7 @@ class EditableFormHeading extends EditableFormField
public function getFormField() public function getFormField()
{ {
$labelField = HeaderField::create('userforms-header', $this->Title) $labelField = HeaderField::create('userforms-header', $this->Title ?: false)
->setHeadingLevel($this->Level); ->setHeadingLevel($this->Level);
$labelField->addExtraClass('FormHeading'); $labelField->addExtraClass('FormHeading');
$labelField->setAttribute('data-id', $this->Name); $labelField->setAttribute('data-id', $this->Name);

View File

@ -54,7 +54,7 @@ class EditableMemberListField extends EditableFormField
} }
$members = Member::map_in_groups($this->GroupID); $members = Member::map_in_groups($this->GroupID);
$field = DropdownField::create($this->Name, $this->Title, $members); $field = DropdownField::create($this->Name, $this->Title ?: false, $members);
$this->doUpdateFormField($field); $this->doUpdateFormField($field);
return $field; return $field;
} }

View File

@ -41,7 +41,7 @@ class EditableNumericField extends EditableFormField
*/ */
public function getFormField() public function getFormField()
{ {
$field = NumericField::create($this->Name, $this->Title, $this->Default) $field = NumericField::create($this->Name, $this->Title ?: false, $this->Default)
->setFieldHolderTemplate(EditableFormField::class . '_holder') ->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(EditableFormField::class) ->setTemplate(EditableFormField::class)
->addExtraClass('number'); ->addExtraClass('number');

View File

@ -35,7 +35,7 @@ class EditableRadioField extends EditableMultipleOptionField
public function getFormField() public function getFormField()
{ {
$field = OptionsetField::create($this->Name, $this->Title, $this->getOptionsMap()) $field = OptionsetField::create($this->Name, $this->Title ?: false, $this->getOptionsMap())
->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder') ->setFieldHolderTemplate(EditableMultipleOptionField::class . '_holder')
->setTemplate('SilverStripe\\UserForms\\FormField\\UserFormsOptionSetField'); ->setTemplate('SilverStripe\\UserForms\\FormField\\UserFormsOptionSetField');

View File

@ -128,12 +128,12 @@ class EditableTextField extends EditableFormField
public function getFormField() public function getFormField()
{ {
if ($this->Rows > 1) { if ($this->Rows > 1) {
$field = TextareaField::create($this->Name, $this->Title, $this->Default) $field = TextareaField::create($this->Name, $this->Title ?: false, $this->Default)
->setFieldHolderTemplate(EditableFormField::class . '_holder') ->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(str_replace('EditableTextField', 'EditableTextareaField', __CLASS__)) ->setTemplate(str_replace('EditableTextField', 'EditableTextareaField', __CLASS__))
->setRows($this->Rows); ->setRows($this->Rows);
} else { } else {
$field = TextField::create($this->Name, $this->Title, $this->Default) $field = TextField::create($this->Name, $this->Title ?: false, $this->Default)
->setFieldHolderTemplate(EditableFormField::class . '_holder') ->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(EditableFormField::class); ->setTemplate(EditableFormField::class);
} }

View File

@ -89,7 +89,9 @@ class UserDefinedFormControllerTest extends FunctionalTest
// check to see if the user was redirected (301) // check to see if the user was redirected (301)
$this->assertEquals($response->getStatusCode(), 302); $this->assertEquals($response->getStatusCode(), 302);
$this->assertStringEndsWith('finished#uff', $response->getHeader('Location')); $location = $response->getHeader('Location');
$this->assertContains('finished', $location);
$this->assertStringEndsWith('#uff', $location);
// check that multiple email addresses are supported in to and from // check that multiple email addresses are supported in to and from
$this->assertEmailSent( $this->assertEmailSent(

View File

@ -18,4 +18,12 @@ class EditableCheckboxGroupFieldTest extends SapphireTest
$checkboxGroup = $this->objFromFixture(EditableCheckboxGroupField::class, 'checkbox-group'); $checkboxGroup = $this->objFromFixture(EditableCheckboxGroupField::class, 'checkbox-group');
$this->assertSame(UserFormsCheckboxSetField::class, $checkboxGroup->getFormField()->getTemplate()); $this->assertSame(UserFormsCheckboxSetField::class, $checkboxGroup->getFormField()->getTemplate());
} }
public function testAllowEmptyTitle()
{
/** @var EditableCheckboxGroupField $field */
$field = EditableCheckboxGroupField::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
} }

View File

@ -0,0 +1,17 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableCheckbox;
class EditableCheckboxTest extends SapphireTest
{
public function testAllowEmptyTitle()
{
/** @var EditableCheckbox $field */
$field = EditableCheckbox::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
}

View File

@ -13,4 +13,12 @@ class EditableCountryDropdownFieldTest extends SapphireTest
$this->assertContains('/images/editabledropdown.png', $field->getIcon()); $this->assertContains('/images/editabledropdown.png', $field->getIcon());
} }
public function testAllowEmptyTitle()
{
/** @var EditableCountryDropdownField $field */
$field = EditableCountryDropdownField::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
} }

View File

@ -0,0 +1,17 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableDateField;
class EditableDateFieldTest extends SapphireTest
{
public function testAllowEmptyTitle()
{
/** @var EditableDateField $field */
$field = EditableDateField::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
}

View File

@ -36,4 +36,12 @@ class EditableDropdownTest extends SapphireTest
$alternateDropdown->write(); $alternateDropdown->write();
$this->assertEquals($formField->getEmptyString(), ''); $this->assertEquals($formField->getEmptyString(), '');
} }
public function testAllowEmptyTitle()
{
/** @var EditableDropdown $field */
$field = EditableDropdown::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
} }

View File

@ -0,0 +1,17 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
class EditableEmailFieldTest extends SapphireTest
{
public function testAllowEmptyTitle()
{
/** @var EditableEmailField $field */
$field = EditableEmailField::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
class EditableFieldGroupTest extends SapphireTest
{
public function testAllowEmptyTitle()
{
/** @var EditableFieldGroup $field */
$field = EditableFieldGroup::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
}

View File

@ -64,4 +64,12 @@ class EditableFileFieldTest extends SapphireTest
$formField = $fileField->getFormField(); $formField = $fileField->getFormField();
$this->assertEquals($formField->getValidator()->getAllowedMaxFileSize(), 262144); $this->assertEquals($formField->getValidator()->getAllowedMaxFileSize(), 262144);
} }
public function testAllowEmptyTitle()
{
/** @var EditableFileField $field */
$field = EditableFileField::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
} }

View File

@ -0,0 +1,17 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading;
class EditableFormHeadingTest extends SapphireTest
{
public function testAllowEmptyTitle()
{
/** @var EditableFormHeading $field */
$field = EditableFormHeading::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep;
class EditableFormStepTest extends SapphireTest
{
public function testAllowEmptyTitle()
{
/** @var EditableFormStep $field */
$field = EditableFormStep::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Group;
use SilverStripe\UserForms\Model\EditableFormField\EditableMemberListField;
class EditableMemberListFieldTest extends SapphireTest
{
protected static $fixture_file = 'EditableMemberListFieldTest.yml';
public function testAllowEmptyTitle()
{
/** @var EditableMemberListField $field */
$field = EditableMemberListField::create();
$field->GroupID = $this->idFromFixture(Group::class, 'a_group');
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
}

View File

@ -0,0 +1,3 @@
SilverStripe\Security\Group:
a_group:
Title: A security group

View File

@ -0,0 +1,17 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableFormField\EditableNumericField;
class EditableNumericFieldTest extends SapphireTest
{
public function testAllowEmptyTitle()
{
/** @var EditableNumericField $field */
$field = EditableNumericField::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
}

View File

@ -3,8 +3,6 @@
namespace SilverStripe\UserForms\Tests\Model\EditableFormField; namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField;
use SilverStripe\UserForms\Model\EditableFormField\EditableCheckboxGroupField;
use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField; use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField;
class EditableRadioFieldTest extends SapphireTest class EditableRadioFieldTest extends SapphireTest
@ -22,4 +20,12 @@ class EditableRadioFieldTest extends SapphireTest
$radio->getFormField()->getTemplate() $radio->getFormField()->getTemplate()
); );
} }
public function testAllowEmptyTitle()
{
/** @var EditableRadioField $field */
$field = EditableRadioField::create();
$field->Name = 'EditableFormField_123456';
$this->assertEmpty($field->getFormField()->Title());
}
} }

View File

@ -20,4 +20,16 @@ class EditableTextFieldTest extends SapphireTest
$this->assertInstanceOf(DropdownField::class, $autocompleteField); $this->assertInstanceOf(DropdownField::class, $autocompleteField);
$this->assertEquals(['foo' => 'foo'], $autocompleteField->getSource()); $this->assertEquals(['foo' => 'foo'], $autocompleteField->getSource());
} }
public function testAllowEmptyTitle()
{
/** @var EditableTextField $field */
$field = EditableTextField::create();
$field->Name = 'EditableFormField_123456';
$field->Rows = 1;
$this->assertEmpty($field->getFormField()->Title());
$field->Rows = 3;
$this->assertEmpty($field->getFormField()->Title());
}
} }

View File

@ -86,9 +86,6 @@ class EditableFormFieldTest extends FunctionalTest
$this->assertEquals(0, $checkbox->EffectiveDisplayRules()->count()); $this->assertEquals(0, $checkbox->EffectiveDisplayRules()->count());
} }
/**
* @covers EditableOption::getValue
*/
public function testEditableOptionEmptyValue() public function testEditableOptionEmptyValue()
{ {
$option = $this->objFromFixture(EditableOption::class, 'option-1'); $option = $this->objFromFixture(EditableOption::class, 'option-1');