API Implement SS4 namespacing, add userforms namespaces

This commit is contained in:
Robbie Averill 2017-08-09 11:55:09 +12:00
parent e11cbc5cfc
commit eaf374adc5
65 changed files with 1324 additions and 219 deletions

65
.upgrade.yml Normal file
View File

@ -0,0 +1,65 @@
mappings:
SecureEditableFileField: SilverStripe\UserForms\Extension\SecureEditableFileField
UserFormFieldEditorExtension: SilverStripe\UserForms\Extension\UserFormFieldEditorExtension
UserFormValidator: SilverStripe\UserForms\Extension\UserFormValidator
GridFieldAddClassesButton: SilverStripe\UserForms\Form\GridFieldAddClassesButton
UserForm: SilverStripe\UserForms\Form\UserForm
UserFormsGridFieldFilterHeader: SilverStripe\UserForms\Form\UserFormsGridFieldFilterHeader
UserFormsCheckboxSetField: SilverStripe\UserForms\FormField\UserFormsCheckboxSetField
UserFormsCompositeField: SilverStripe\UserForms\FormField\UserFormsCompositeField
UserFormsFieldContainer: SilverStripe\UserForms\FormField\UserFormsFieldContainer
UserFormsFieldList: SilverStripe\UserForms\FormField\UserFormsFieldList
UserFormsGroupField: SilverStripe\UserForms\FormField\UserFormsGroupField
UserFormsStepField: SilverStripe\UserForms\FormField\UserFormsStepField
UserformsTreeDropdownField: SilverStripe\UserForms\FormField\UserformsTreeDropdownField
EditableCustomRule: SilverStripe\UserForms\Model\EditableCustomRule
UserDefinedForm: SilverStripe\UserForms\Model\UserDefinedForm
UserDefinedFormController: SilverStripe\UserForms\Model\UserDefinedFormController
EditableCheckbox: SilverStripe\UserForms\Model\EditableFormField\EditableCheckbox
EditableCheckboxGroupField: SilverStripe\UserForms\Model\EditableFormField\EditableCheckboxGroupField
EditableCountryDropdownField: SilverStripe\UserForms\Model\EditableFormField\EditableCountryDropdownField
EditableDateField: SilverStripe\UserForms\Model\EditableFormField\EditableDateField
EditableDateField_FormField: SilverStripe\UserForms\Model\EditableFormField\EditableDateField_FormField
EditableDropdown: SilverStripe\UserForms\Model\EditableFormField\EditableDropdown
EditableEmailField: SilverStripe\UserForms\Model\EditableFormField\EditableEmailField
EditableFieldGroup: SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup
EditableFieldGroupEnd: SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd
EditableFileField: SilverStripe\UserForms\Model\EditableFormField\EditableFileField
EditableFormField: SilverStripe\UserForms\Model\EditableFormField\EditableFormField
EditableFormFieldValidator: SilverStripe\UserForms\Model\EditableFormField\EditableFormFieldValidator
EditableFormHeading: SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading
EditableFormStep: SilverStripe\UserForms\Model\EditableFormField\EditableFormStep
EditableLiteralField: SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField
EditableMemberListField: SilverStripe\UserForms\Model\EditableFormField\EditableMemberListField
EditableMultipleOptionField: SilverStripe\UserForms\Model\EditableFormField\EditableMultipleOptionField
EditableNumericField: SilverStripe\UserForms\Model\EditableFormField\EditableNumericField
EditableOption: SilverStripe\UserForms\Model\EditableFormField\EditableOption
EditableRadioField: SilverStripe\UserForms\Model\EditableFormField\EditableRadioField
EditableTextField: SilverStripe\UserForms\Model\EditableFormField\EditableTextField
UserDefinedForm_EmailRecipient: SilverStripe\UserForms\Model\Recipient\UserDefinedForm_EmailRecipient
UserDefinedForm_EmailRecipientCondition: SilverStripe\UserForms\Model\Recipient\UserDefinedForm_EmailRecipientCondition
UserFormRecipientEmail: SilverStripe\UserForms\Model\Recipient\UserFormRecipientEmail
UserFormRecipientItemRequest: SilverStripe\UserForms\Model\Recipient\UserFormRecipientItemRequest
SubmittedFileField: SilverStripe\UserForms\Model\Submission\SubmittedFileField
SubmittedForm: SilverStripe\UserForms\Model\Submission\SubmittedForm
SubmittedFormField: SilverStripe\UserForms\Model\Submission\SubmittedFormField
DisambiguationSegmentFieldModifier: SilverStripe\UserForms\Modifier\DisambiguationSegmentFieldModifier
UnderscoreSegmentFieldModifier: SilverStripe\UserForms\Modifier\UnderscoreSegmentFieldModifier
UserFormsColumnCleanTask: SilverStripe\UserForms\Task\UserFormsColumnCleanTask
UserFormsUpgradeService: SilverStripe\UserForms\Task\UserFormsUpgradeService
UserFormsUpgradeTask: SilverStripe\UserForms\Task\UserFormsUpgradeTask
UserFormsVersionedTask: SilverStripe\UserForms\Task\UserFormsVersionedTask
UserFormTest: SilverStripe\UserForms\Test\Form\UserFormTest
UserFormsCheckboxSetFieldTest: SilverStripe\UserForms\Test\FormField\UserFormsCheckboxSetFieldTest
EditableCustomRuleTest: SilverStripe\UserForms\Test\Model\EditableCustomRuleTest
UserDefinedFormControllerTest: SilverStripe\UserForms\Test\Model\UserDefinedFormControllerTest
UserDefinedFormControllerTest_Controller: SilverStripe\UserForms\Test\Model\UserDefinedFormControllerTest_Controller
UserDefinedFormTest: SilverStripe\UserForms\Test\Model\UserDefinedFormTest
EditableDropdownTest: SilverStripe\UserForms\Test\Model\EditableFormField\EditableDropdownTest
EditableFileFieldTest: SilverStripe\UserForms\Test\Model\EditableFormField\EditableFileFieldTest
EditableFormFieldTest: SilverStripe\UserForms\Test\Model\EditableFormField\EditableFormFieldTest
EditableLiteralFieldTest: SilverStripe\UserForms\Test\Model\EditableFormField\EditableLiteralFieldTest
SecureEditableFileFieldTest: SilverStripe\UserForms\Test\Model\EditableFormField\SecureEditableFileFieldTest
UserDefinedForm_EmailRecipientConditionTest: SilverStripe\UserForms\Test\Model\Recipient\UserDefinedForm_EmailRecipientConditionTest
UserFormsUpgradeServiceTest: SilverStripe\UserForms\Test\Task\UserFormsUpgradeServiceTest
UserFormsVersionedTaskTest: SilverStripe\UserForms\Test\Task\UserFormsVersionedTaskTest

View File

@ -2,6 +2,6 @@
Name: userformsroutes
After: framework/routes#coreroutes
---
Director:
SilverStripe\Control\Director:
rules:
'UserDefinedForm_Controller//$Action' : 'UserDefinedForm_Controller'
UserDefinedForm_Controller//$Action: UserDefinedForm_Controller

View File

@ -3,14 +3,13 @@ Name: userformssecurity
Only:
ModuleExists: secureassets
---
EditableFileField:
SilverStripe\UserForms\Model\EditableFormField\EditableFileField:
extensions:
- SecureEditableFileField
- SilverStripe\UserForms\Extension\SecureEditableFileField
---
Name: userformsnosecurity
Except:
ModuleExists: secureassets
---
EditableFileField:
hidden: true
SilverStripe\UserForms\Model\EditableFormField\EditableFileField:
hidden: true

View File

@ -1,5 +1,21 @@
<?php
namespace SilverStripe\UserForms\Extension;
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
use SilverStripe\ORM\DB;
use SilverStripe\Assets\Folder;
use SilverStripe\Security\Group;
use SilverStripe\Security\Permission;
use SilverStripe\ORM\DataExtension;
/**
* Provides additional file security for uploaded files when the securefiles module is installed
*
@ -110,7 +126,7 @@ class SecureEditableFileField extends DataExtension
*/
protected function findAdminGroup()
{
singleton('Group')->requireDefaultRecords();
singleton(Group::class)->requireDefaultRecords();
return Permission::get_groups_by_permission('ADMIN')->First();
}

View File

@ -1,5 +1,47 @@
<?php
namespace SilverStripe\UserForms\Extension;
use GridFieldEditableColumns;
use GridFieldOrderableRows;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Tab;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\UserForms\Form\GridFieldAddClassesButton;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\DataExtension;
/**
* @package userforms
*/
@ -10,7 +52,7 @@ class UserFormFieldEditorExtension extends DataExtension
* @var array
*/
private static $has_many = array(
'Fields' => 'EditableFormField'
'Fields' => EditableFormField::class
);
/**
@ -42,7 +84,7 @@ class UserFormFieldEditorExtension extends DataExtension
$this->createInitialFormStep(true);
$editableColumns = new GridFieldEditableColumns();
$fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
$fieldClasses = singleton(EditableFormField::class)->getEditableFieldClasses();
$editableColumns->setDisplayFields(array(
'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
if ($record instanceof EditableFormField) {
@ -60,12 +102,12 @@ class UserFormFieldEditorExtension extends DataExtension
->addComponents(
$editableColumns,
new GridFieldButtonRow(),
GridFieldAddClassesButton::create('EditableTextField')
GridFieldAddClassesButton::create(EditableTextField::class)
->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))
->setButtonClass('ss-ui-action-constructive'),
GridFieldAddClassesButton::create('EditableFormStep')
GridFieldAddClassesButton::create(EditableFormStep::class)
->setButtonName(_t('UserFormFieldEditorExtension.ADD_PAGE_BREAK', 'Add Page Break')),
GridFieldAddClassesButton::create(array('EditableFieldGroup', 'EditableFieldGroupEnd'))
GridFieldAddClassesButton::create(array(EditableFieldGroup::class, EditableFieldGroupEnd::class))
->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD_GROUP', 'Add Field Group')),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
@ -153,7 +195,7 @@ class UserFormFieldEditorExtension extends DataExtension
}
// fetch any orphaned live records
$live = Versioned::get_by_stage("EditableFormField", "Live")
$live = Versioned::get_by_stage(EditableFormField::class, "Live")
->filter(array(
'ParentID' => $original->ID,
));

View File

@ -1,5 +1,20 @@
<?php
namespace SilverStripe\UserForms\Extension;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
use SilverStripe\Forms\RequiredFields;
class UserFormValidator extends RequiredFields
{

View File

@ -1,5 +1,21 @@
<?php
namespace SilverStripe\UserForms\Form;
use Object;
use SilverStripe\Forms\GridField\GridField_FormAction;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
use SilverStripe\Forms\GridField\GridField_ActionProvider;
/**
* A button which allows objects to be created with a specified classname(s)
*/
@ -231,7 +247,7 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
{
$classes = $this->getClassesCreate($grid);
if (empty($classes)) {
throw new SS_HTTPResponse_Exception(400);
throw new HTTPResponse_Exception(400);
}
// Add item to gridfield

View File

@ -1,5 +1,27 @@
<?php
namespace SilverStripe\UserForms\Form;
use ResetFormAction;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FieldList;
use SilverStripe\Control\Session;
use SilverStripe\UserForms\FormField\UserFormsStepField;
use SilverStripe\UserForms\FormField\UserFormsFieldList;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields;
/**
* @package userforms
*/
@ -10,7 +32,7 @@ class UserForm extends Form
* @param Controller $controller
* @param string $name
*/
public function __construct(Controller $controller, $name = 'Form')
public function __construct(Controller $controller, $name = Form::class)
{
$this->controller = $controller;
$this->setRedirectToFormOnValidationError(true);

View File

@ -1,5 +1,34 @@
<?php
namespace SilverStripe\UserForms\Form;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\GridField\GridField_FormAction;
use SilverStripe\View\ArrayData;
use SilverStripe\ORM\SS_List;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
/**
* Extension to the build in SilverStripe {@link GridField} to allow for
* filtering {@link SubmittedForm} objects in the submissions tab by

View File

@ -1,5 +1,12 @@
<?php
namespace SilverStripe\UserForms\FormField;
use SilverStripe\Forms\CheckboxSetField;
/**
* @package userforms
*/

View File

@ -1,5 +1,16 @@
<?php
namespace SilverStripe\UserForms\FormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep;
use SilverStripe\Forms\CompositeField;
/**
* Represents a composite field group, which may contain other groups
*/

View File

@ -1,5 +1,12 @@
<?php
namespace SilverStripe\UserForms\FormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
/**
* Represents a field container which can iteratively process nested fields, converting it into a fieldset
*/

View File

@ -1,5 +1,14 @@
<?php
namespace SilverStripe\UserForms\FormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\Forms\FieldList;
/**
* A list of formfields which allows for iterative processing of nested composite fields
*/

View File

@ -1,5 +1,14 @@
<?php
namespace SilverStripe\UserForms\FormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
/**
* Front end composite field for userforms
*/

View File

@ -1,5 +1,10 @@
<?php
namespace SilverStripe\UserForms\FormField;
/**
* Represents a page step in a form, which may contain form fields or other groups
*/

View File

@ -1,5 +1,15 @@
<?php
namespace SilverStripe\UserForms\FormField;
use SilverStripe\Security\Group;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\TreeDropdownField;
/**
* {@link TreeDropdownField} subclass for handling loading folders through the
* nested {@link FormField} instances of the {@link FieldEditor}
@ -10,7 +20,7 @@
class UserformsTreeDropdownField extends TreeDropdownField
{
public function __construct($name, $title = null, $sourceObject = 'Group', $keyField = 'ID', $labelField = 'TreeTitle', $showSearch = true)
public function __construct($name, $title = null, $sourceObject = Group::class, $keyField = 'ID', $labelField = 'TreeTitle', $showSearch = true)
{
parent::__construct($name, $title, $sourceObject, $keyField, $labelField, $showSearch);

View File

@ -1,5 +1,20 @@
<?php
namespace SilverStripe\UserForms\Model;
use LogicException;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\Control\Controller;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataObject;
/**
* A custom rule for showing / hiding an EditableFormField
* based the value of another EditableFormField.
@ -32,8 +47,8 @@ class EditableCustomRule extends DataObject
);
private static $has_one = array(
'Parent' => 'EditableFormField',
'ConditionField' => 'EditableFormField'
'Parent' => EditableFormField::class,
'ConditionField' => EditableFormField::class
);
/**

View File

@ -1,4 +1,11 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\CheckboxField;
/**
* EditableCheckbox
*

View File

@ -1,4 +1,13 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField;
use SilverStripe\UserForms\Model\EditableCustomRule;
/**
* EditableCheckboxGroup
*

View File

@ -1,5 +1,13 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use CountryDropdownField;
use SilverStripe\UserForms\Model\EditableCustomRule;
/**
* A dropdown field which allows the user to select a country
*

View File

@ -1,4 +1,17 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Forms\DateField;
/**
* EditableDateField
*
@ -46,7 +59,7 @@ class EditableDateField extends EditableFormField
public function getFormField()
{
$defaultValue = $this->DefaultToToday
? SS_Datetime::now()->Format('Y-m-d')
? DBDatetime::now()->Format('Y-m-d')
: $this->Default;
$field = EditableDateField_FormField::create($this->Name, $this->EscapedTitle, $defaultValue)

View File

@ -1,5 +1,18 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\UserForms\Model\EditableCustomRule;
/**
* EditableDropdown
*

View File

@ -1,4 +1,11 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\EmailField;
/**
* EditableEmailField
*

View File

@ -1,5 +1,17 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
use SilverStripe\Forms\LabelField;
use SilverStripe\UserForms\FormField\UserFormsGroupField;
use SilverStripe\Core\Convert;
/**
* Specifies that this ends a group of fields
*/
@ -7,7 +19,7 @@ class EditableFieldGroup extends EditableFormField
{
private static $has_one = array(
'End' => 'EditableFieldGroupEnd'
'End' => EditableFieldGroupEnd::class
);
/**

View File

@ -1,5 +1,16 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
use SilverStripe\Security\Group;
use SilverStripe\Forms\LabelField;
use SilverStripe\Forms\HiddenField;
/**
* Specifies that this ends a group of fields
*/
@ -7,7 +18,7 @@ class EditableFieldGroupEnd extends EditableFormField
{
private static $belongs_to = array(
'Group' => 'EditableFieldGroup'
'Group' => EditableFieldGroup::class
);
/**
@ -33,7 +44,7 @@ class EditableFieldGroupEnd extends EditableFormField
'EditableFieldGroupEnd.FIELD_GROUP_END',
'{group} end',
array(
'group' => ($group && $group->exists()) ? $group->CMSTitle : 'Group'
'group' => ($group && $group->exists()) ? $group->CMSTitle : Group::class
)
);
}

View File

@ -1,5 +1,25 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Assets\Folder;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\FileField;
use SilverStripe\Core\Config\Config;
use SilverStripe\Assets\File;
use SilverStripe\UserForms\Model\Submission\SubmittedFileField;
/**
* Allows a user to add a field that can be used to upload a file.
*
@ -17,7 +37,7 @@ class EditableFileField extends EditableFormField
);
private static $has_one = array(
'Folder' => 'Folder' // From CustomFields
'Folder' => Folder::class // From CustomFields
);
/**
@ -41,7 +61,7 @@ class EditableFileField extends EditableFormField
TreeDropdownField::create(
'FolderID',
_t('EditableUploadField.SELECTUPLOADFOLDER', 'Select upload folder'),
'Folder'
Folder::class
)
);
@ -93,7 +113,7 @@ class EditableFileField extends EditableFormField
$field->getValidator()->setAllowedExtensions(
array_diff(
// filter out '' since this would be a regex problem on JS end
array_filter(Config::inst()->get('File', 'allowed_extensions')),
array_filter(Config::inst()->get(File::class, 'allowed_extensions')),
$this->config()->allowed_extensions_blacklist
)
);
@ -137,9 +157,9 @@ class EditableFileField extends EditableFormField
public function migrateSettings($data)
{
// Migrate 'Folder' setting to 'FolderID'
if (isset($data['Folder'])) {
$this->FolderID = $data['Folder'];
unset($data['Folder']);
if (isset($data[Folder::class])) {
$this->FolderID = $data[Folder::class];
unset($data[Folder::class]);
}
parent::migrateSettings($data);

View File

@ -1,7 +1,79 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\SegmentField;
use GridFieldEditableColumns;
use GridFieldAddNewInlineButton;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\TextField;
use SilverStripe\UserForms\Modifier\UnderscoreSegmentFieldModifier;
use SilverStripe\UserForms\Modifier\DisambiguationSegmentFieldModifier;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LabelField;
use SilverStripe\Core\Config\Config;
use SilverStripe\UserForms\Model\EditableCustomRule;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Control\Controller;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Versioned\Versioned;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Core\Convert;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Core\ClassInfo;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
/**
* Represents the base class of a editable form field
* object like {@link EditableTextField}.
@ -112,7 +184,7 @@ class EditableFormField extends DataObject
* @var array
*/
private static $has_one = array(
"Parent" => "UserDefinedForm",
"Parent" => UserDefinedForm::class,
);
/**
@ -305,7 +377,7 @@ class EditableFormField extends DataObject
))->map('ID', 'Title'));
},
'ConditionOption' => function ($record, $column, $grid) {
$options = Config::inst()->get('EditableCustomRule', 'condition_options');
$options = Config::inst()->get(EditableCustomRule::class, 'condition_options');
return DropdownField::create($column, '', $options);
},
@ -431,7 +503,7 @@ class EditableFormField extends DataObject
$parent = $controller->getRecord($controller->currentPageID());
// Only allow this behaviour on pages using UserFormFieldEditorExtension, such
// as UserDefinedForm page type.
if ($parent && $parent->hasExtension('UserFormFieldEditorExtension')) {
if ($parent && $parent->hasExtension(UserFormFieldEditorExtension::class)) {
return $parent->canEdit($member);
}
}
@ -554,7 +626,7 @@ class EditableFormField extends DataObject
}
// remove any orphans from the "fromStage"
$rules = Versioned::get_by_stage('EditableCustomRule', $toStage)
$rules = Versioned::get_by_stage(EditableCustomRule::class, $toStage)
->filter('ParentID', $this->ID);
if (!empty($seenRuleIDs)) {
@ -574,7 +646,7 @@ class EditableFormField extends DataObject
public function doDeleteFromStage($stage)
{
// Remove custom rules in this stage
$rules = Versioned::get_by_stage('EditableCustomRule', $stage)
$rules = Versioned::get_by_stage(EditableCustomRule::class, $stage)
->filter('ParentID', $this->ID);
foreach ($rules as $rule) {
$rule->deleteFromStage($stage);
@ -611,8 +683,8 @@ class EditableFormField extends DataObject
return false;
}
$stageVersion = Versioned::get_versionnumber_by_stage('EditableFormField', 'Stage', $this->ID);
$liveVersion = Versioned::get_versionnumber_by_stage('EditableFormField', 'Live', $this->ID);
$stageVersion = Versioned::get_versionnumber_by_stage(EditableFormField::class, 'Stage', $this->ID);
$liveVersion = Versioned::get_versionnumber_by_stage(EditableFormField::class, 'Live', $this->ID);
return ($stageVersion && $stageVersion != $liveVersion);
}
@ -742,14 +814,14 @@ class EditableFormField extends DataObject
$prior = 0; // Number of prior group at this level
$stack = array(); // Current stack of nested groups, where the top level = the page
foreach ($fields->map('ID', 'ClassName') as $id => $className) {
if ($className === 'EditableFormStep') {
if ($className === EditableFormStep::class) {
$priorPage = empty($stack) ? $prior : $stack[0];
$stack = array($priorPage + 1);
$prior = 0;
} elseif ($className === 'EditableFieldGroup') {
} elseif ($className === EditableFieldGroup::class) {
$stack[] = $prior + 1;
$prior = 0;
} elseif ($className === 'EditableFieldGroupEnd') {
} elseif ($className === EditableFieldGroupEnd::class) {
$prior = array_pop($stack);
}
if ($id == $this->ID) {
@ -1007,7 +1079,7 @@ class EditableFormField extends DataObject
*/
public function getEditableFieldClasses($includeLiterals = true)
{
$classes = ClassInfo::getValidSubClasses('EditableFormField');
$classes = ClassInfo::getValidSubClasses(EditableFormField::class);
// Remove classes we don't want to display in the dropdown.
$editableFieldClasses = array();
@ -1078,7 +1150,7 @@ class EditableFormField extends DataObject
foreach ($this->EffectiveDisplayRules() as $rule) {
// Get the field which is effected
/** @var EditableFormField $formFieldWatch */
$formFieldWatch = DataObject::get_by_id('EditableFormField', $rule->ConditionFieldID);
$formFieldWatch = DataObject::get_by_id(EditableFormField::class, $rule->ConditionFieldID);
// Skip deleted fields
if (! $formFieldWatch) {
continue;

View File

@ -1,5 +1,14 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableCustomRule;
use SilverStripe\Forms\RequiredFields;
class EditableFormFieldValidator extends RequiredFields
{

View File

@ -1,4 +1,17 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Core\Convert;
/**
* Allows an editor to insert a generic heading into a field
*

View File

@ -1,4 +1,13 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\UserForms\FormField\UserFormsStepField;
use SilverStripe\Forms\LabelField;
/**
* A step in multi-page user form
*

View File

@ -1,5 +1,23 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\HTMLEditor\HTMLEditorSanitiser;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\CompositeField;
/**
* Editable Literal Field. A literal field is just a blank slate where
* you can add your own HTML / Images / Flash
@ -41,17 +59,17 @@ class EditableLiteralField extends EditableFormField
);
/**
* Returns the {@see HtmlEditorConfig} instance to use for sanitisation
* Returns the {@see HTMLEditorConfig} instance to use for sanitisation
*
* @return HtmlEditorConfig
* @return HTMLEditorConfig
*/
protected function getEditorConfig()
{
$editorConfig = $this->config()->editor_config;
if ($editorConfig) {
return HtmlEditorConfig::get($editorConfig);
return HTMLEditorConfig::get($editorConfig);
}
return HtmlEditorConfig::get_active();
return HTMLEditorConfig::get_active();
}
/**
@ -63,13 +81,13 @@ class EditableLiteralField extends EditableFormField
protected function sanitiseContent($content)
{
// Check if sanitisation is enabled
if (!HtmlEditorField::config()->sanitise_server_side) {
if (!HTMLEditorField::config()->sanitise_server_side) {
return $content;
}
// Perform sanitisation
$htmlValue = Injector::inst()->create('HTMLValue', $content);
$santiser = Injector::inst()->create('HtmlEditorSanitiser', $this->getEditorConfig());
$santiser = Injector::inst()->create(HTMLEditorSanitiser::class, $this->getEditorConfig());
$santiser->sanitise($htmlValue);
return $htmlValue->getContent();
}

View File

@ -1,4 +1,15 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Security\Group;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Security\Member;
/**
* Creates an editable field that displays members in a given group
*
@ -13,7 +24,7 @@ class EditableMemberListField extends EditableFormField
private static $plural_name = 'Member List Fields';
private static $has_one = array(
'Group' => 'Group'
'Group' => Group::class
);
/**
@ -30,7 +41,7 @@ class EditableMemberListField extends EditableFormField
'Root.Main',
DropdownField::create(
"GroupID",
_t('EditableFormField.GROUP', 'Group'),
_t('EditableFormField.GROUP', Group::class),
Group::get()->map()
)->setEmptyString(' ')
);

View File

@ -1,5 +1,35 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use GridFieldEditableColumns;
use GridFieldTitleHeader;
use GridFieldOrderableRows;
use GridFieldAddNewInlineButton;
use SilverStripe\UserForms\Model\EditableFormField\EditableOption;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\Tab;
use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\Map;
/**
* Base class for multiple option fields such as {@link EditableDropdownField}
* and radio sets.
@ -25,7 +55,7 @@ class EditableMultipleOptionField extends EditableFormField
private static $abstract = true;
private static $has_many = array(
"Options" => "EditableOption"
"Options" => EditableOption::class
);
/**
@ -118,7 +148,7 @@ class EditableMultipleOptionField extends EditableFormField
}
// remove any orphans from the "fromStage"
$options = Versioned::get_by_stage('EditableOption', $toStage)
$options = Versioned::get_by_stage(EditableOption::class, $toStage)
->filter('ParentID', $this->ID);
if (!empty($seenIDs)) {
@ -140,7 +170,7 @@ class EditableMultipleOptionField extends EditableFormField
public function doDeleteFromStage($stage)
{
// Remove options
$options = Versioned::get_by_stage('EditableOption', $stage)
$options = Versioned::get_by_stage(EditableOption::class, $stage)
->filter('ParentID', $this->ID);
foreach ($options as $option) {
$option->deleteFromStage($stage);
@ -208,7 +238,7 @@ class EditableMultipleOptionField extends EditableFormField
{
$optionSet = $this->Options();
$optionMap = $optionSet->map('Value', 'Title');
if ($optionMap instanceof SS_Map) {
if ($optionMap instanceof Map) {
return $optionMap->toArray();
}
return $optionMap;

View File

@ -1,4 +1,15 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\FieldGroup;
/**
* EditableNumericField
*

View File

@ -1,5 +1,19 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableMultipleOptionField;
use SilverStripe\Core\Convert;
use SilverStripe\Control\Controller;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\ORM\DataObject;
/**
* Base Class for EditableOption Fields such as the ones used in
* dropdown fields and in radio check box groups
@ -21,7 +35,7 @@ class EditableOption extends DataObject
);
private static $has_one = array(
"Parent" => "EditableMultipleOptionField",
"Parent" => EditableMultipleOptionField::class,
);
private static $extensions = array(

View File

@ -1,4 +1,13 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\UserForms\Model\EditableCustomRule;
/**
* EditableRadioField
*

View File

@ -1,4 +1,22 @@
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Control\Email\Email;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\TextField;
/**
* EditableTextField
*
@ -26,7 +44,7 @@ class EditableTextField extends EditableFormField
'family-name' => 'Family name',
'honorific-suffix' => 'Suffix (e.g Jr.)',
'nickname' => 'Nickname',
'email' => 'Email',
'email' => Email::class,
'organization-title' => 'Job title',
'organization' => 'Organization',
'street-address' => 'Street address',

View File

@ -1,5 +1,67 @@
<?php
namespace SilverStripe\UserForms\Model\Recipient;
use GridFieldAddNewInlineButton;
use GridFieldEditableColumns;
use Tabset;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\UserForms\Model\Recipient\UserDefinedForm_EmailRecipientCondition;
use SilverStripe\Control\Email\Email;
use SilverStripe\Control\Session;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\TextField;
use SilverStripe\View\Requirements;
use SilverStripe\UserForms\Model\EditableFormField\EditableMultipleOptionField;
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\Form;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Assets\FileFinder;
use SilverStripe\ORM\DataObject;
/**
* A Form can have multiply members / emails to email the submission
@ -24,14 +86,14 @@ class UserDefinedForm_EmailRecipient extends DataObject
);
private static $has_one = array(
'Form' => 'UserDefinedForm',
'SendEmailFromField' => 'EditableFormField',
'SendEmailToField' => 'EditableFormField',
'SendEmailSubjectField' => 'EditableFormField'
'Form' => UserDefinedForm::class,
'SendEmailFromField' => EditableFormField::class,
'SendEmailToField' => EditableFormField::class,
'SendEmailSubjectField' => EditableFormField::class
);
private static $has_many = array(
'CustomRules' => 'UserDefinedForm_EmailRecipientCondition'
'CustomRules' => UserDefinedForm_EmailRecipientCondition::class
);
private static $summary_fields = array(
@ -55,7 +117,7 @@ class UserDefinedForm_EmailRecipient extends DataObject
{
$fields = parent::summaryFields();
if (isset($fields['EmailAddress'])) {
$fields['EmailAddress'] = _t('UserDefinedForm.EMAILADDRESS', 'Email');
$fields['EmailAddress'] = _t('UserDefinedForm.EMAILADDRESS', Email::class);
}
if (isset($fields['EmailSubject'])) {
$fields['EmailSubject'] = _t('UserDefinedForm.EMAILSUBJECT', 'Subject');
@ -229,7 +291,7 @@ class UserDefinedForm_EmailRecipient extends DataObject
$preview = sprintf(
'<p><a href="%s" target="_blank" class="ss-ui-button">%s</a></p><em>%s</em>',
Controller::join_links(
singleton('CMSPageEditController')->getEditForm()->FormAction(),
singleton(CMSPageEditController::class)->getEditForm()->FormAction(),
"field/EmailRecipients/item/{$this->ID}/preview"
),
_t('UserDefinedForm.PREVIEW_EMAIL', 'Preview email'),
@ -323,8 +385,8 @@ class UserDefinedForm_EmailRecipient extends DataObject
protected function getCanCreateContext($args)
{
// Inspect second parameter to canCreate for a 'Parent' context
if (isset($args[1]['Form'])) {
return $args[1]['Form'];
if (isset($args[1][Form::class])) {
return $args[1][Form::class];
}
// Hack in currently edited page if context is missing
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
@ -433,7 +495,7 @@ class UserDefinedForm_EmailRecipient extends DataObject
{
$templates = array();
$finder = new SS_FileFinder();
$finder = new FileFinder();
$finder->setOption('name_regex', '/^.*\.ss$/');
$found = $finder->find(BASE_PATH . '/' . UserDefinedForm::config()->email_template_directory);

View File

@ -1,5 +1,19 @@
<?php
namespace SilverStripe\UserForms\Model\Recipient;
use LogicException;
use SilverStripe\UserForms\Model\Recipient\UserDefinedForm_EmailRecipient;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\Control\Controller;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\ORM\DataObject;
/**
* Declares a condition that determines whether an email can be sent to a given recipient
@ -37,8 +51,8 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject
);
private static $has_one = array(
'Parent' => 'UserDefinedForm_EmailRecipient',
'ConditionField' => 'EditableFormField'
'Parent' => UserDefinedForm_EmailRecipient::class,
'ConditionField' => EditableFormField::class
);
/**

View File

@ -1,5 +1,12 @@
<?php
namespace SilverStripe\UserForms\Model\Recipient;
use SilverStripe\Control\Email\Email;
/**
* Email that gets sent to the people listed in the Email Recipients when a

View File

@ -1,5 +1,23 @@
<?php
namespace SilverStripe\UserForms\Model\Recipient;
use SilverStripe\Core\Config\Config;
use SilverStripe\View\SSViewer;
use SilverStripe\View\ArrayData;
use SilverStripe\ORM\ArrayList;
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
/**
* Controller that handles requests to EmailRecipient's
*
@ -22,7 +40,7 @@ class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
{
// Enable theme for preview (may be needed for Shortcodes)
Config::nest();
Config::inst()->update('SSViewer', 'theme_enabled', true);
Config::inst()->update(SSViewer::class, 'theme_enabled', true);
$content = $this->customise(new ArrayData(array(
'Body' => $this->record->getEmailBodyContent(),
@ -44,8 +62,8 @@ class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
$data = new ArrayList();
$fields = $this->record->Form()->Fields()->filter(array(
'ClassName:not' => 'EditableLiteralField',
'ClassName:not' => 'EditableFormHeading'
'ClassName:not' => EditableLiteralField::class,
'ClassName:not' => EditableFormHeading::class
));
foreach ($fields as $field) {

View File

@ -1,5 +1,13 @@
<?php
namespace SilverStripe\UserForms\Model\Submission;
use SilverStripe\Assets\File;
use SilverStripe\ORM\FieldType\DBField;
/**
* A file uploaded on a {@link UserDefinedForm} and attached to a single
* {@link SubmittedForm}.
@ -11,7 +19,7 @@ class SubmittedFileField extends SubmittedFormField
{
private static $has_one = array(
"UploadedFile" => "File"
"UploadedFile" => File::class
);
/**

View File

@ -1,4 +1,26 @@
<?php
namespace SilverStripe\UserForms\Model\Submission;
use SilverStripe\Security\Member;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldExportButton;
use SilverStripe\Forms\GridField\GridFieldPrintButton;
use SilverStripe\ORM\DataObject;
/**
* Contents of an UserDefinedForm submission
*
@ -9,12 +31,12 @@ class SubmittedForm extends DataObject
{
private static $has_one = array(
"SubmittedBy" => "Member",
"Parent" => "UserDefinedForm",
"SubmittedBy" => Member::class,
"Parent" => UserDefinedForm::class,
);
private static $has_many = array(
"Values" => "SubmittedFormField"
"Values" => SubmittedFormField::class
);
private static $summary_fields = array(
@ -77,7 +99,7 @@ class SubmittedForm extends DataObject
$values = GridField::create(
'Values',
'SubmittedFormField',
SubmittedFormField::class,
$self->Values()->sort('Created', 'ASC')
);

View File

@ -1,4 +1,12 @@
<?php
namespace SilverStripe\UserForms\Model\Submission;
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
use SilverStripe\ORM\DataObject;
/**
* Data received from a UserDefinedForm submission
*
@ -15,7 +23,7 @@ class SubmittedFormField extends DataObject
);
private static $has_one = array(
"Parent" => "SubmittedForm"
"Parent" => SubmittedForm::class
);
private static $summary_fields = array(

View File

@ -1,5 +1,73 @@
<?php
namespace SilverStripe\UserForms\Model;
use Page;
use HtmlEditorField;
use GridFieldBulkManager;
use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension;
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
use SilverStripe\UserForms\Model\Recipient\UserDefinedForm_EmailRecipient;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\LabelField;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\UserForms\Model\Recipient\UserFormRecipientItemRequest;
use SilverStripe\ORM\DB;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
use SilverStripe\UserForms\Form\UserFormsGridFieldFilterHeader;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldPageCount;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\Forms\GridField\GridFieldExportButton;
use SilverStripe\Forms\GridField\GridFieldPrintButton;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\UserForms\Task\UserFormsUpgradeService;
use SilverStripe\UserForms\Extension\UserFormValidator;
/**
* @package userforms
*/
@ -55,7 +123,7 @@ class UserDefinedForm extends Page
* @var array
*/
private static $extensions = array(
'UserFormFieldEditorExtension'
UserFormFieldEditorExtension::class
);
/**
@ -86,8 +154,8 @@ class UserDefinedForm extends Page
* @var array
*/
private static $has_many = array(
"Submissions" => "SubmittedForm",
"EmailRecipients" => "UserDefinedForm_EmailRecipient"
"Submissions" => SubmittedForm::class,
"EmailRecipients" => UserDefinedForm_EmailRecipient::class
);
/**
@ -156,7 +224,7 @@ class UserDefinedForm extends Page
// Define config for email recipients
$emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
$emailRecipientsConfig->getComponentByType('GridFieldAddNewButton')
$emailRecipientsConfig->getComponentByType(GridFieldAddNewButton::class)
->setButtonName(
_t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
);
@ -170,8 +238,8 @@ class UserDefinedForm extends Page
);
$emailRecipients
->getConfig()
->getComponentByType('GridFieldDetailForm')
->setItemRequestClass('UserFormRecipientItemRequest');
->getComponentByType(GridFieldDetailForm::class)
->setItemRequestClass(UserFormRecipientItemRequest::class);
$fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
$fields->addFieldToTab('Root.Recipients', $emailRecipients);
@ -223,7 +291,7 @@ SQL;
}
}
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields($summaryarray);
$config->getComponentByType(GridFieldDataColumns::class)->setDisplayFields($summaryarray);
/**
* Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
@ -347,7 +415,7 @@ SQL;
// Perform migrations
Injector::inst()
->create('UserFormsUpgradeService')
->create(UserFormsUpgradeService::class)
->setQuiet(true)
->run();

View File

@ -1,5 +1,46 @@
<?php
namespace SilverStripe\UserForms\Model;
use PageController;
use Object;
use SilverStripe\View\Requirements;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\UserForms\Form\UserForm;
use SilverStripe\Forms\Form;
use SilverStripe\Control\Controller;
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
use SilverStripe\Security\Member;
use SilverStripe\ORM\ArrayList;
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
use SilverStripe\Assets\Upload;
use SilverStripe\Assets\File;
use SilverStripe\ORM\ValidationException;
use SilverStripe\UserForms\Model\Recipient\UserFormRecipientEmail;
use SilverStripe\Control\HTTP;
use SilverStripe\View\SSViewer;
use SilverStripe\Control\Session;
use SilverStripe\View\ArrayData;
/**
* Controller for the {@link UserDefinedForm} page type.
*
@ -96,7 +137,7 @@ class UserDefinedFormController extends PageController
public function Form()
{
$form = UserForm::create($this, 'Form_' . $this->ID);
$form->setFormAction(Controller::join_links($this->Link(), 'Form'));
$form->setFormAction(Controller::join_links($this->Link(), Form::class));
$this->generateConditionalJavascript();
return $form;
}
@ -150,7 +191,7 @@ JS
*/
public function process($data, $form)
{
$submittedForm = Object::create('SubmittedForm');
$submittedForm = Object::create(SubmittedForm::class);
$submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
$submittedForm->ParentID = $this->ID;
@ -182,7 +223,7 @@ JS
}
if (!empty($data[$field->Name])) {
if (in_array("EditableFileField", $field->getClassAncestry())) {
if (in_array(EditableFileField::class, $field->getClassAncestry())) {
if (!empty($_FILES[$field->Name]['name'])) {
$foldername = $field->getFormField()->getFolderName();

View File

@ -1,7 +1,15 @@
<?php
namespace SilverStripe\UserForms\Modifier;
use SilverStripe\Forms\SegmentFieldModifier\AbstractSegmentFieldModifier;
use EditableformField;
use SilverStripe\Forms\Form;
class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier
{
/**

View File

@ -1,7 +1,12 @@
<?php
namespace SilverStripe\UserForms\Modifier;
use SilverStripe\Forms\SegmentFieldModifier\SlugSegmentFieldModifier;
class UnderscoreSegmentFieldModifier extends SlugSegmentFieldModifier
{
/**

View File

@ -1,5 +1,15 @@
<?php
namespace SilverStripe\UserForms\Task;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\ORM\DB;
use SilverStripe\Dev\MigrationTask;
/**
* UserForms Column Clean Task
*
@ -15,7 +25,7 @@ class UserFormsColumnCleanTask extends MigrationTask
protected $description = "Removes unused columns from EditableFormField for MySQL databases;";
protected $tables = array('EditableFormField');
protected $tables = array(EditableFormField::class);
protected $keepColumns = array('ID');

View File

@ -1,5 +1,20 @@
<?php
namespace SilverStripe\UserForms\Task;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\Versioned\Versioned;
use SilverStripe\UserForms\Model\EditableCustomRule;
use SilverStripe\Control\Director;
use SilverStripe\ORM\DB;
/**
* Service to support upgrade of userforms module
*/
@ -16,7 +31,7 @@ class UserFormsUpgradeService
$this->log("Upgrading formfield rules and custom settings");
// List of rules that have been created in all stages
$fields = Versioned::get_including_deleted('EditableFormField');
$fields = Versioned::get_including_deleted(EditableFormField::class);
foreach ($fields as $field) {
$this->upgradeField($field);
}
@ -33,8 +48,8 @@ class UserFormsUpgradeService
// Check versions this field exists on
$filter = sprintf('"EditableFormField"."ID" = \'%d\' AND "Migrated" = 0', $field->ID);
$stageField = Versioned::get_one_by_stage('EditableFormField', 'Stage', $filter);
$liveField = Versioned::get_one_by_stage('EditableFormField', 'Live', $filter);
$stageField = Versioned::get_one_by_stage(EditableFormField::class, 'Stage', $filter);
$liveField = Versioned::get_one_by_stage(EditableFormField::class, 'Live', $filter);
if ($stageField) {
$this->upgradeFieldInStage($stageField, 'Stage');
@ -171,7 +186,7 @@ class UserFormsUpgradeService
// If live, search stage record for matching one
if ($stage === 'Live') {
$list = Versioned::get_by_stage('EditableCustomRule', 'Stage')
$list = Versioned::get_by_stage(EditableCustomRule::class, 'Stage')
->filter(array(
'ParentID' => $field->ID,
'ConditionFieldID' => $conditionField ? $conditionField->ID : 0,

View File

@ -1,5 +1,15 @@
<?php
namespace SilverStripe\UserForms\Task;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\UserForms\Task\UserFormsUpgradeService;
use SilverStripe\Dev\BuildTask;
/**
* Assists with upgrade of userforms to 3.0
*
@ -14,7 +24,7 @@ class UserFormsUpgradeTask extends BuildTask
public function run($request)
{
$service = Injector::inst()->create('UserFormsUpgradeService');
$service = Injector::inst()->create(UserFormsUpgradeService::class);
$service->log("Upgrading userforms module");
$service->setQuiet(false)
->run();

View File

@ -1,5 +1,15 @@
<?php
namespace SilverStripe\UserForms\Task;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Dev\MigrationTask;
/**
* UserForms Versioned Task
*
@ -23,7 +33,7 @@ class UserFormsVersionedTask extends MigrationTask
*/
public function run($request)
{
$forms = Versioned::get_by_stage('UserDefinedForm', 'Live');
$forms = Versioned::get_by_stage(UserDefinedForm::class, 'Live');
if ($forms) {
foreach ($forms as $form) {

View File

@ -1,5 +1,17 @@
<?php
namespace SilverStripe\UserForms\Test\Form;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\CMS\Controllers\ModelAsController;
use SilverStripe\UserForms\Form\UserForm;
use SilverStripe\Dev\SapphireTest;
class UserFormTest extends SapphireTest
{
@ -11,7 +23,7 @@ class UserFormTest extends SapphireTest
*/
public function testEmptyPages()
{
$page = $this->objFromFixture('UserDefinedForm', 'empty-page');
$page = $this->objFromFixture(UserDefinedForm::class, 'empty-page');
$this->assertEquals(5, $page->Fields()->count());
$controller = ModelAsController::controller_for($page);
$form = new UserForm($controller);

View File

@ -1,5 +1,16 @@
<?php
namespace SilverStripe\UserForms\Test\FormField;
use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Dev\SapphireTest;
class UserFormsCheckboxSetFieldTest extends SapphireTest
{
public function testValidate() {

View File

@ -1,5 +1,13 @@
<?php
namespace SilverStripe\UserForms\Test\Model;
use SilverStripe\UserForms\Model\EditableCustomRule;
use SilverStripe\Dev\SapphireTest;
/**
* Class EditableCustomRulesTest
*/
@ -10,7 +18,7 @@ class EditableCustomRuleTest extends SapphireTest
public function testBuildExpression()
{
/** @var EditableCustomRule $rule1 */
$rule1 = $this->objFromFixture('EditableCustomRule', 'rule1');
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
$result1 = $rule1->buildExpression();
//Dropdowns expect change event
@ -20,7 +28,7 @@ class EditableCustomRuleTest extends SapphireTest
$this->assertContains('==', $result1['operation']);
/** @var EditableCustomRule $rule2 */
$rule2 = $this->objFromFixture('EditableCustomRule', 'rule2');
$rule2 = $this->objFromFixture(EditableCustomRule::class, 'rule2');
$result2 = $rule2->buildExpression();
//TextField expect change event
$this->assertEquals('keyup', $result2['event']);
@ -35,7 +43,7 @@ class EditableCustomRuleTest extends SapphireTest
*/
public function testToggleDisplayText()
{
$rule1 = $this->objFromFixture('EditableCustomRule', 'rule1');
$rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1');
$this->assertSame('addClass("hide")', $rule1->toggleDisplayText('show'));
$this->assertSame('removeClass("hide")', $rule1->toggleDisplayText('hide'));
}

View File

@ -1,5 +1,14 @@
<?php
namespace SilverStripe\UserForms\Test\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
use SilverStripe\Dev\SapphireTest;
/**
* Tests the {@see EditableDropdown} class
*/
@ -19,7 +28,7 @@ class EditableDropdownTest extends SapphireTest
public function testFormField()
{
if (!$dropdown = EditableDropdown::get()->filter('UseEmptyString', true)->first()) {
$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
$dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
$dropdown->UseEmptyString = true;
$dropdown->EmptyString = 'My Default Empty String';
@ -29,7 +38,7 @@ class EditableDropdownTest extends SapphireTest
$field = $dropdown->getFormField();
$this->assertEquals($field->getEmptyString(), 'My Default Empty String');
$alternateDropdown = $this->objFromFixture('EditableDropdown', 'department-dropdown');
$alternateDropdown = $this->objFromFixture(EditableDropdown::class, 'department-dropdown');
$formField = $alternateDropdown->getFormField();
$this->assertFalse($formField->getHasEmptyDefault());

View File

@ -1,5 +1,14 @@
<?php
namespace SilverStripe\UserForms\Test\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Dev\SapphireTest;
/**
* @package userforms
*/
@ -23,7 +32,7 @@ class EditableFileFieldTest extends SapphireTest
{
parent::setUp();
$editableFileField = singleton('EditableFileField');
$editableFileField = singleton(EditableFileField::class);
$this->php_max_file_size = $editableFileField::get_php_max_file_size();
}
@ -33,7 +42,7 @@ class EditableFileFieldTest extends SapphireTest
*/
public function testDefaultMaxFileSize()
{
$fileField = $this->objFromFixture('EditableFileField', 'file-field');
$fileField = $this->objFromFixture(EditableFileField::class, 'file-field');
$formField = $fileField->getFormField();
$this->assertEquals($this->php_max_file_size, $formField->getValidator()->getAllowedMaxFileSize());
@ -45,8 +54,8 @@ class EditableFileFieldTest extends SapphireTest
public function testValidateFileSizeFieldValue()
{
$fileField = $this->objFromFixture('EditableFileField', 'file-field');
$this->setExpectedException('ValidationException');
$fileField = $this->objFromFixture(EditableFileField::class, 'file-field');
$this->setExpectedException(ValidationException::class);
$fileField->MaxFileSizeMB = $this->php_max_file_size * 2;
$fileField->write();
}
@ -56,7 +65,7 @@ class EditableFileFieldTest extends SapphireTest
*/
public function testUpdatedMaxFileSize()
{
$fileField = $this->objFromFixture('EditableFileField', 'file-field');
$fileField = $this->objFromFixture(EditableFileField::class, 'file-field');
$fileField->MaxFileSizeMB = .25;
$fileField->write();

View File

@ -1,5 +1,29 @@
<?php
namespace SilverStripe\UserForms\Test\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\Security\Member;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\Model\EditableFormField\EditableCheckbox;
use SilverStripe\UserForms\Model\EditableFormField\EditableOption;
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
use SilverStripe\Forms\DropdownField;
use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
use SilverStripe\Core\Config\Config;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\Dev\FunctionalTest;
/**
* @package userforms
*/
@ -11,7 +35,7 @@ class EditableFormFieldTest extends FunctionalTest
public function testFormFieldPermissions()
{
$text = $this->objFromFixture('EditableTextField', 'basic-text');
$text = $this->objFromFixture(EditableTextField::class, 'basic-text');
$this->logInWithPermission('ADMIN');
$this->assertTrue($text->canCreate());
@ -49,10 +73,10 @@ class EditableFormFieldTest extends FunctionalTest
public function testCustomRules()
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'custom-rules-form');
$form = $this->objFromFixture(UserDefinedForm::class, 'custom-rules-form');
$checkbox = $form->Fields()->find('ClassName', 'EditableCheckbox');
$field = $form->Fields()->find('ClassName', 'EditableTextField');
$checkbox = $form->Fields()->find('ClassName', EditableCheckbox::class);
$field = $form->Fields()->find('ClassName', EditableTextField::class);
$rules = $checkbox->DisplayRules();
@ -78,7 +102,7 @@ class EditableFormFieldTest extends FunctionalTest
*/
public function testEditableOptionEmptyValue()
{
$option = $this->objFromFixture('EditableOption', 'option-1');
$option = $this->objFromFixture(EditableOption::class, 'option-1');
$option->Value = '';
// Disallow empty values
@ -96,12 +120,12 @@ class EditableFormFieldTest extends FunctionalTest
public function testEditableDropdownField()
{
$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
$dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
$field = $dropdown->getFormField();
$this->assertThat($field, $this->isInstanceOf('DropdownField'));
$this->assertThat($field, $this->isInstanceOf(DropdownField::class));
$values = $field->getSource();
$this->assertEquals(array('Option 1' => 'Option 1', 'Option 2' => 'Option 2'), $values);
@ -109,11 +133,11 @@ class EditableFormFieldTest extends FunctionalTest
public function testEditableRadioField()
{
$radio = $this->objFromFixture('EditableRadioField', 'radio-field');
$radio = $this->objFromFixture(EditableRadioField::class, 'radio-field');
$field = $radio->getFormField();
$this->assertThat($field, $this->isInstanceOf('OptionsetField'));
$this->assertThat($field, $this->isInstanceOf(OptionsetField::class));
$values = $field->getSource();
$this->assertEquals(array('Option 5' => 'Option 5', 'Option 6' => 'Option 6'), $values);
@ -121,7 +145,7 @@ class EditableFormFieldTest extends FunctionalTest
public function testMultipleOptionDuplication()
{
$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
$dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
$clone = $dropdown->duplicate();
@ -136,7 +160,7 @@ class EditableFormFieldTest extends FunctionalTest
public function testFileField()
{
$fileField = $this->objFromFixture('EditableFileField', 'file-field');
$fileField = $this->objFromFixture(EditableFileField::class, 'file-field');
$formField = $fileField->getFormField();
$this->assertContains('jpg', $formField->getValidator()->getAllowedExtensions());
@ -145,8 +169,8 @@ class EditableFormFieldTest extends FunctionalTest
public function testFileFieldAllowedExtensionsBlacklist()
{
Config::inst()->update('EditableFileField', 'allowed_extensions_blacklist', array('jpg'));
$fileField = $this->objFromFixture('EditableFileField', 'file-field');
Config::inst()->update(EditableFileField::class, 'allowed_extensions_blacklist', array('jpg'));
$fileField = $this->objFromFixture(EditableFileField::class, 'file-field');
$formField = $fileField->getFormField();
$this->assertNotContains('jpg', $formField->getValidator()->getAllowedExtensions());
@ -177,7 +201,7 @@ class EditableFormFieldTest extends FunctionalTest
public function testLengthRange()
{
/** @var EditableTextField $textField */
$textField = $this->objFromFixture('EditableTextField', 'basic-text');
$textField = $this->objFromFixture(EditableTextField::class, 'basic-text');
// Empty range
/** @var TextField $formField */
@ -207,7 +231,7 @@ class EditableFormFieldTest extends FunctionalTest
public function testFormatDisplayRules()
{
$field = $this->objFromFixture('EditableFormField', 'irdNumberField');
$field = $this->objFromFixture(EditableFormField::class, 'irdNumberField');
$displayRules = $field->formatDisplayRules();
$this->assertNotNull($displayRules);
$this->assertCount(1, $displayRules['operations']);

View File

@ -1,5 +1,19 @@
<?php
namespace SilverStripe\UserForms\Test\Model\EditableFormField;
use HtmlEditorConfig;
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Dev\SapphireTest;
/**
* Tests the {@see EditableLiteralField} class
*/
@ -48,7 +62,7 @@ class EditableLiteralFieldTest extends SapphireTest
public function testLiteralFieldHasUpdateFormFieldMethodCalled()
{
$field = $this->getMockBuilder('EditableLiteralField')
$field = $this->getMockBuilder(EditableLiteralField::class)
->setMethods(array('doUpdateFormField'))
->getMock();
@ -66,9 +80,9 @@ class EditableLiteralFieldTest extends SapphireTest
$field = new EditableLiteralField;
$formField = $field->getFormField();
$this->assertInstanceOf('CompositeField', $formField, 'Literal field is contained within a composite field');
$this->assertInstanceOf(CompositeField::class, $formField, 'Literal field is contained within a composite field');
$this->assertInstanceOf(
'LiteralField',
LiteralField::class,
$formField->FieldList()->first(),
'Actual literal field exists in composite field children'
);

View File

@ -1,5 +1,20 @@
<?php
namespace SilverStripe\UserForms\Test\Model\EditableFormField;
use SilverStripe\Core\Config\Config;
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
use SilverStripe\Assets\Filesystem;
use SilverStripe\Assets\Folder;
use SilverStripe\Dev\SapphireTest;
/**
* Tests integration of EditableFileField with the securefiles module
*
@ -18,7 +33,7 @@ class SecureEditableFileFieldTest extends SapphireTest
$this->skipTest = true;
$this->markTestSkipped(get_class() . ' skipped unless running with securefiles');
}
Config::inst()->update('EditableFileField', 'secure_folder_name', 'SecureEditableFileFieldTest/SecureUploads');
Config::inst()->update(EditableFileField::class, 'secure_folder_name', 'SecureEditableFileFieldTest/SecureUploads');
$this->clearPath();
}
@ -54,7 +69,7 @@ class SecureEditableFileFieldTest extends SapphireTest
*/
public function testCreateInsecure()
{
Config::inst()->update('EditableFileField', 'disable_security', true);
Config::inst()->update(EditableFileField::class, 'disable_security', true);
// Esure folder is created without a folder
$field = new EditableFileField();
@ -73,8 +88,8 @@ class SecureEditableFileFieldTest extends SapphireTest
$this->assertEquals('Inherit', $field->Folder()->CanViewType);
// Enabling security and re-saving will force this field to be made secure (but not changed)
Config::inst()->update('EditableFileField', 'disable_security', false);
singleton('EditableFileField')->requireDefaultRecords();
Config::inst()->update(EditableFileField::class, 'disable_security', false);
singleton(EditableFileField::class)->requireDefaultRecords();
// Reload record from DB
$field = EditableFileField::get()->byID($field->ID);

View File

@ -1,5 +1,13 @@
<?php
namespace SilverStripe\UserForms\Test\Model\Recipient;
use SilverStripe\UserForms\Model\Recipient\UserDefinedForm_EmailRecipientCondition;
use SilverStripe\Dev\SapphireTest;
/**
* Class EditableCustomRulesTest
*/
@ -12,7 +20,7 @@ class UserDefinedForm_EmailRecipientConditionTest extends SapphireTest
*/
public function testMatches()
{
$fixtureClass = 'UserDefinedForm_EmailRecipientCondition';
$fixtureClass = UserDefinedForm_EmailRecipientCondition::class;
//Test Blank
/** @var UserDefinedForm_EmailRecipientCondition $blankObj */
$blankObj = $this->objFromFixture($fixtureClass, 'blankTest');

View File

@ -1,5 +1,33 @@
<?php
namespace SilverStripe\UserForms\Test\Model;
use ResetFormAction;
use UserDefinedForm_Controller;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
use SilverStripe\ORM\DataObject;
use SilverStripe\Dev\CSSContentParser;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\FieldList;
use SilverStripe\View\ArrayData;
use SilverStripe\UserForms\Test\Model\UserDefinedFormControllerTest;
use SilverStripe\Security\Member;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\TestOnly;
/**
* @package userforms
*/
@ -21,12 +49,12 @@ class UserDefinedFormControllerTest extends FunctionalTest
// load the form
$this->get($form->URLSegment);
$field = $this->objFromFixture('EditableTextField', 'basic-text');
$field = $this->objFromFixture(EditableTextField::class, 'basic-text');
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, array($field->Name => 'Basic Value'));
// should have a submitted form field now
$submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'");
$submitted = DataObject::get(SubmittedFormField::class, "\"Name\" = 'basic-text-name'");
$this->assertDOSAllMatch(array('Name' => 'basic-text-name', 'Value' => 'Basic Value', 'Title' => 'Basic Text Field'), $submitted);
// check emails
@ -124,7 +152,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
public function testForm()
{
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$controller = new UserDefinedFormControllerTest_Controller($form);
@ -134,7 +162,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$this->assertEquals($controller->Form()->Actions()->Count(), 1);
$this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 0);
$requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
$requiredForm = $this->objFromFixture(UserDefinedForm::class, 'validation-form');
$controller = new UserDefinedFormControllerTest_Controller($requiredForm);
$this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
@ -145,7 +173,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
public function testGetFormFields()
{
// generating the fieldset of fields
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$controller = new UserDefinedFormControllerTest_Controller($form);
@ -156,7 +184,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$this->assertEquals($firstStep->getChildren()->Count(), 1);
// custom error message on a form field
$requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
$requiredForm = $this->objFromFixture(UserDefinedForm::class, 'validation-form');
$controller = new UserDefinedFormControllerTest_Controller($requiredForm);
UserDefinedForm::config()->required_identifier = "*";
@ -180,7 +208,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$this->assertEquals($firstStep->getChildren()->First()->RightTitle(), "Right Title");
// test empty form
$emptyForm = $this->objFromFixture('UserDefinedForm', 'empty-form');
$emptyForm = $this->objFromFixture(UserDefinedForm::class, 'empty-form');
$controller = new UserDefinedFormControllerTest_Controller($emptyForm);
$this->assertFalse($controller->Form()->getFormFields()->exists());
@ -189,7 +217,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
public function testGetFormActions()
{
// generating the fieldset of actions
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$controller = new UserDefinedFormControllerTest_Controller($form);
$actions = $controller->Form()->getFormActions();
@ -201,7 +229,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
$this->assertEquals($actions, $expected);
// the custom popup should have a reset button and a custom text
$custom = $this->objFromFixture('UserDefinedForm', 'form-with-reset-and-custom-action');
$custom = $this->objFromFixture(UserDefinedForm::class, 'form-with-reset-and-custom-action');
$controller = new UserDefinedFormControllerTest_Controller($custom);
$actions = $controller->Form()->getFormActions();
@ -223,7 +251,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
// check to see if $Form is replaced to inside the content
$index = new ArrayData($controller->index());
$parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
$parser = new CSSContentParser($index->renderWith(array(UserDefinedFormControllerTest::class)));
$this->checkTemplateIsCorrect($parser, $form);
}
@ -236,7 +264,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
// check to see if $Form is replaced to inside the content
$index = new ArrayData($controller->index());
$parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
$parser = new CSSContentParser($index->renderWith(array(UserDefinedFormControllerTest::class)));
$this->checkTemplateIsCorrect($parser, $form);
}
@ -248,7 +276,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
*/
protected function setupFormFrontend($fixtureName = 'basic-form-page')
{
$form = $this->objFromFixture('UserDefinedForm', $fixtureName);
$form = $this->objFromFixture(UserDefinedForm::class, $fixtureName);
$this->logInWithPermission('ADMIN');
$form->doPublish();

View File

@ -1,5 +1,41 @@
<?php
namespace SilverStripe\UserForms\Test\Model;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\UserForms\Model\Recipient\UserDefinedForm_EmailRecipient;
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
use SilverStripe\Security\Member;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormField;
use SilverStripe\UserForms\Model\EditableCustomRule;
use SilverStripe\ORM\DB;
use SilverStripe\UserForms\Extension\UserFormValidator;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FieldList;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup;
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\FunctionalTest;
/**
* @package userforms
*/
@ -16,7 +52,7 @@ class UserDefinedFormTest extends FunctionalTest
// @todo
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$form->SubmitButtonText = 'Button Text';
$form->write();
@ -28,19 +64,19 @@ class UserDefinedFormTest extends FunctionalTest
$form->doPublish();
// check published site
$updated = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
$updated = Versioned::get_one_by_stage(UserDefinedForm::class, "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
$this->assertEquals($updated->SubmitButtonText, 'Updated Button Text');
$form->doRollbackTo($origVersion);
$orignal = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
$orignal = Versioned::get_one_by_stage(UserDefinedForm::class, "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
$this->assertEquals($orignal->SubmitButtonText, 'Button Text');
}
public function testGetCMSFields()
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$fields = $form->getCMSFields();
@ -54,14 +90,14 @@ class UserDefinedFormTest extends FunctionalTest
public function testGetCMSFieldsShowInSummary()
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'summary-rules-form');
$form = $this->objFromFixture(UserDefinedForm::class, 'summary-rules-form');
$fields = $form->getCMSFields();
$this->assertInstanceOf('GridField', $fields->dataFieldByName('Submissions'));
$this->assertInstanceOf(GridField::class, $fields->dataFieldByName('Submissions'));
$submissionsgrid = $fields->dataFieldByName('Submissions');
$gridFieldDataColumns = $submissionsgrid->getConfig()->getComponentByType('GridFieldDataColumns');
$gridFieldDataColumns = $submissionsgrid->getConfig()->getComponentByType(GridFieldDataColumns::class);
$summaryFields = $gridFieldDataColumns->getDisplayFields($submissionsgrid);
@ -74,7 +110,7 @@ class UserDefinedFormTest extends FunctionalTest
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$popup = new UserDefinedForm_EmailRecipient();
$popup->FormID = $form->ID;
@ -89,16 +125,16 @@ class UserDefinedFormTest extends FunctionalTest
$this->assertTrue($fields->dataFieldByName('EmailBody') !== null);
// add an email field, it should now add a or from X address picker
$email = $this->objFromFixture('EditableEmailField', 'email-field');
$email = $this->objFromFixture(EditableEmailField::class, 'email-field');
$form->Fields()->add($email);
$popup->write();
$fields = $popup->getCMSFields();
$this->assertThat($fields->dataFieldByName('SendEmailToFieldID'), $this->isInstanceOf('DropdownField'));
$this->assertThat($fields->dataFieldByName('SendEmailToFieldID'), $this->isInstanceOf(DropdownField::class));
// if the front end has checkboxs or dropdown they can select from that can also be used to send things
$dropdown = $this->objFromFixture('EditableDropdown', 'department-dropdown');
$dropdown = $this->objFromFixture(EditableDropdown::class, 'department-dropdown');
$form->Fields()->add($dropdown);
$fields = $popup->getCMSFields();
@ -157,7 +193,7 @@ class UserDefinedFormTest extends FunctionalTest
public function testCanEditAndDeleteRecipient()
{
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$this->logInWithPermission('ADMIN');
foreach ($form->EmailRecipients() as $recipient) {
@ -179,30 +215,30 @@ class UserDefinedFormTest extends FunctionalTest
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$form->write();
$form->doPublish();
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
$live = Versioned::get_one_by_stage(UserDefinedForm::class, "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
$this->assertNotNull($live);
$this->assertEquals(2, $live->Fields()->Count()); // one page and one field
$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
$dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
$form->Fields()->add($dropdown);
$stage = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
$stage = Versioned::get_one_by_stage(UserDefinedForm::class, "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
$this->assertEquals(3, $stage->Fields()->Count());
// should not have published the dropdown
$liveDropdown = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $dropdown->ID");
$liveDropdown = Versioned::get_one_by_stage(EditableFormField::class, "Live", "\"EditableFormField_Live\".\"ID\" = $dropdown->ID");
$this->assertNull($liveDropdown);
// when publishing it should have added it
$form->doPublish();
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
$live = Versioned::get_one_by_stage(UserDefinedForm::class, "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
$this->assertEquals(3, $live->Fields()->Count());
// edit the title
@ -210,12 +246,12 @@ class UserDefinedFormTest extends FunctionalTest
$text->Title = 'Edited title';
$text->write();
$liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
$liveText = Versioned::get_one_by_stage(EditableFormField::class, "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
$this->assertFalse($liveText->Title == $text->Title);
$form->doPublish();
$liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
$liveText = Versioned::get_one_by_stage(EditableFormField::class, "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
$this->assertTrue($liveText->Title == $text->Title);
// Add a display rule to the dropdown
@ -226,37 +262,37 @@ class UserDefinedFormTest extends FunctionalTest
$ruleID = $displayRule->ID;
// Not live
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$liveRule = Versioned::get_one_by_stage(EditableCustomRule::class, "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$this->assertEmpty($liveRule);
// Publish form, it's now live
$form->doPublish();
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$liveRule = Versioned::get_one_by_stage(EditableCustomRule::class, "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$this->assertNotEmpty($liveRule);
// Remove rule
$displayRule->delete();
// Live rule still exists
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$liveRule = Versioned::get_one_by_stage(EditableCustomRule::class, "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$this->assertNotEmpty($liveRule);
// Publish form, it should remove this rule
$form->doPublish();
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$liveRule = Versioned::get_one_by_stage(EditableCustomRule::class, "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$this->assertEmpty($liveRule);
}
public function testUnpublishing()
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$form->write();
$this->assertEquals(0, DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value());
$form->doPublish();
// assert that it exists and has a field
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
$live = Versioned::get_one_by_stage(UserDefinedForm::class, "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID");
$this->assertTrue(isset($live));
$this->assertEquals(2, DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value());
@ -264,14 +300,14 @@ class UserDefinedFormTest extends FunctionalTest
// unpublish
$form->doUnpublish();
$this->assertNull(Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"));
$this->assertNull(Versioned::get_one_by_stage(UserDefinedForm::class, "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"));
$this->assertEquals(0, DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value());
}
public function testDoRevertToLive()
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$field = $form->Fields()->First();
$field->Title = 'Title';
@ -283,14 +319,14 @@ class UserDefinedFormTest extends FunctionalTest
$field->write();
// check that the published version is not updated
$live = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $field->ID");
$live = Versioned::get_one_by_stage(EditableFormField::class, "Live", "\"EditableFormField_Live\".\"ID\" = $field->ID");
$this->assertEquals('Title', $live->Title);
// revert back to the live data
$form->doRevertToLive();
$form->flushCache();
$check = Versioned::get_one_by_stage("EditableFormField", "Stage", "\"EditableFormField\".\"ID\" = $field->ID");
$check = Versioned::get_one_by_stage(EditableFormField::class, "Stage", "\"EditableFormField\".\"ID\" = $field->ID");
$this->assertEquals('Title', $check->Title);
}
@ -298,7 +334,7 @@ class UserDefinedFormTest extends FunctionalTest
public function testDuplicatingForm()
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$duplicate = $form->duplicate();
@ -309,25 +345,25 @@ class UserDefinedFormTest extends FunctionalTest
$this->assertEquals($form->Fields()->First()->Title, $duplicate->Fields()->First()->Title);
// Test duplicate with group
$form2 = $this->objFromFixture('UserDefinedForm', 'page-with-group');
$form2 = $this->objFromFixture(UserDefinedForm::class, 'page-with-group');
$form2Validator = new UserFormValidator();
$form2Validator->setForm(new Form(new Controller(), 'Form', new FieldList(), new FieldList()));
$form2Validator->setForm(new Form(new Controller(), Form::class, new FieldList(), new FieldList()));
$this->assertTrue($form2Validator->php($form2->toMap()));
// Check field groups exist
$form2GroupStart = $form2->Fields()->filter('ClassName', 'EditableFieldGroup')->first();
$form2GroupEnd = $form2->Fields()->filter('ClassName', 'EditableFieldGroupEnd')->first();
$form2GroupStart = $form2->Fields()->filter('ClassName', EditableFieldGroup::class)->first();
$form2GroupEnd = $form2->Fields()->filter('ClassName', EditableFieldGroupEnd::class)->first();
$this->assertEquals($form2GroupEnd->ID, $form2GroupStart->EndID);
// Duplicate this
$form3 = $form2->duplicate();
$form3Validator = new UserFormValidator();
$form3Validator->setForm(new Form(new Controller(), 'Form', new FieldList(), new FieldList()));
$form3Validator->setForm(new Form(new Controller(), Form::class, new FieldList(), new FieldList()));
$this->assertTrue($form3Validator->php($form3->toMap()));
// Check field groups exist
$form3GroupStart = $form3->Fields()->filter('ClassName', 'EditableFieldGroup')->first();
$form3GroupEnd = $form3->Fields()->filter('ClassName', 'EditableFieldGroupEnd')->first();
$form3GroupStart = $form3->Fields()->filter('ClassName', EditableFieldGroup::class)->first();
$form3GroupEnd = $form3->Fields()->filter('ClassName', EditableFieldGroupEnd::class)->first();
$this->assertEquals($form3GroupEnd->ID, $form3GroupStart->EndID);
$this->assertNotEquals($form2GroupEnd->ID, $form3GroupStart->EndID);
}
@ -335,7 +371,7 @@ class UserDefinedFormTest extends FunctionalTest
public function testFormOptions()
{
$this->logInWithPermission('ADMIN');
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$fields = $form->getFormOptions();
$submit = $fields->fieldByName('SubmitButtonText');
@ -348,7 +384,7 @@ class UserDefinedFormTest extends FunctionalTest
public function testEmailRecipientFilters()
{
/** @var UserDefinedForm $form */
$form = $this->objFromFixture('UserDefinedForm', 'filtered-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'filtered-form-page');
// Check unfiltered recipients
$result0 = $form
@ -442,7 +478,7 @@ class UserDefinedFormTest extends FunctionalTest
public function testIndex()
{
// Test that the $UserDefinedForm is stripped out
$page = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$page->publish('Stage', 'Live');
$result = $this->get($page->Link());
@ -461,7 +497,7 @@ class UserDefinedFormTest extends FunctionalTest
$this->logInWithPermission('ADMIN');
// test invalid email addresses fail validation
$recipient = $this->objFromFixture('UserDefinedForm_EmailRecipient',
$recipient = $this->objFromFixture(UserDefinedForm_EmailRecipient::class,
'invalid-recipient-list');
$result = $recipient->validate();
$this->assertFalse($result->valid());
@ -469,7 +505,7 @@ class UserDefinedFormTest extends FunctionalTest
$this->assertNotContains('filtered2@example.com', $result->message());
// test valid email addresses pass validation
$recipient = $this->objFromFixture('UserDefinedForm_EmailRecipient',
$recipient = $this->objFromFixture(UserDefinedForm_EmailRecipient::class,
'valid-recipient-list');
$result = $recipient->validate();
$this->assertTrue($result->valid());

View File

@ -1,5 +1,26 @@
<?php
namespace SilverStripe\UserForms\Test\Task;
use SilverStripe\Core\Config\Config;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\UserForms\Model\EditableFormField\EditableNumericField;
use SilverStripe\Security\Group;
use SilverStripe\UserForms\Model\EditableFormField\EditableMemberListField;
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
use SilverStripe\UserForms\Model\EditableFormField\EditableFormHeading;
use SilverStripe\Assets\Folder;
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
use SilverStripe\UserForms\Model\EditableFormField\EditableDateField;
use SilverStripe\UserForms\Model\EditableFormField\EditableCheckbox;
use SilverStripe\UserForms\Task\UserFormsUpgradeService;
use SilverStripe\Dev\SapphireTest;
class UserFormsUpgradeServiceTest extends SapphireTest
{
@ -7,13 +28,13 @@ class UserFormsUpgradeServiceTest extends SapphireTest
public function setUp()
{
Config::inst()->update('UserDefinedForm', 'upgrade_on_build', false);
Config::inst()->update(UserDefinedForm::class, 'upgrade_on_build', false);
parent::setUp();
// Assign rules programatically
$field1 = $this->objFromFixture('EditableTextField', 'text1');
$field2 = $this->objFromFixture('EditableTextField', 'text2');
$field3 = $this->objFromFixture('EditableTextField', 'text3');
$field1 = $this->objFromFixture(EditableTextField::class, 'text1');
$field2 = $this->objFromFixture(EditableTextField::class, 'text2');
$field3 = $this->objFromFixture(EditableTextField::class, 'text3');
$field3->CustomRules = serialize(array(
array(
@ -32,7 +53,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest
$field3->write();
// Assign settings programatically
$field4 = $this->objFromFixture('EditableTextField', 'text4');
$field4 = $this->objFromFixture(EditableTextField::class, 'text4');
$field4->CustomSettings = serialize(array(
'MinLength' => 20,
'MaxLength' => 100,
@ -44,7 +65,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest
));
$field4->write();
$numeric1 = $this->objFromFixture('EditableNumericField', 'numeric1');
$numeric1 = $this->objFromFixture(EditableNumericField::class, 'numeric1');
$numeric1->CustomSettings = serialize(array(
'RightTitle' => 'Number of %',
'Default' => 1,
@ -54,8 +75,8 @@ class UserFormsUpgradeServiceTest extends SapphireTest
));
$numeric1->write();
$group1 = $this->objFromFixture('Group', 'group1');
$members1 = $this->objFromFixture('EditableMemberListField', 'members1');
$group1 = $this->objFromFixture(Group::class, 'group1');
$members1 = $this->objFromFixture(EditableMemberListField::class, 'members1');
$members1->CustomSettings = serialize(array(
'RightTitle' => 'Select group',
'GroupID' => $group1->ID,
@ -63,7 +84,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest
));
$members1->write();
$literal1 = $this->objFromFixture('EditableLiteralField', 'literal1');
$literal1 = $this->objFromFixture(EditableLiteralField::class, 'literal1');
$literal1->CustomSettings = serialize(array(
'HideFromReports' => 1,
'RightTitle' => 'Literal',
@ -72,7 +93,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest
));
$literal1->write();
$heading1 = $this->objFromFixture('EditableFormHeading', 'heading1');
$heading1 = $this->objFromFixture(EditableFormHeading::class, 'heading1');
$heading1->CustomSettings = serialize(array(
'RightTitle' => 'Right',
'Level' => 3,
@ -81,22 +102,22 @@ class UserFormsUpgradeServiceTest extends SapphireTest
));
$heading1->write();
$folder = $this->objFromFixture('Folder', 'folder1');
$file1 = $this->objFromFixture('EditableFileField', 'file1');
$folder = $this->objFromFixture(Folder::class, 'folder1');
$file1 = $this->objFromFixture(EditableFileField::class, 'file1');
$file1->CustomSettings = serialize(array(
'RightTitle' => 'File field',
'Folder' => $folder->ID
));
$file1->write();
$date1 = $this->objFromFixture('EditableDateField', 'date1');
$date1 = $this->objFromFixture(EditableDateField::class, 'date1');
$date1->CustomSettings = serialize(array(
'RightTitle' => 'Date field',
'DefaultToToday' => '1'
));
$date1->write();
$checkbox1 = $this->objFromFixture('EditableCheckbox', 'checkbox1');
$checkbox1 = $this->objFromFixture(EditableCheckbox::class, 'checkbox1');
$checkbox1->CustomSettings = serialize(array(
'Default' => true,
'RightTitle' => 'Check this'
@ -109,7 +130,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest
*/
protected function getService()
{
return singleton('UserFormsUpgradeService');
return singleton(UserFormsUpgradeService::class);
}
/**
@ -121,9 +142,9 @@ class UserFormsUpgradeServiceTest extends SapphireTest
$service->setQuiet(true);
$service->run();
$field1 = $this->objFromFixture('EditableTextField', 'text1');
$field2 = $this->objFromFixture('EditableTextField', 'text2');
$field3 = $this->objFromFixture('EditableTextField', 'text3');
$field1 = $this->objFromFixture(EditableTextField::class, 'text1');
$field2 = $this->objFromFixture(EditableTextField::class, 'text2');
$field3 = $this->objFromFixture(EditableTextField::class, 'text3');
$this->assertDOSEquals(array(
array(
@ -149,13 +170,13 @@ class UserFormsUpgradeServiceTest extends SapphireTest
$service->setQuiet(true);
$service->run();
$group1 = $this->objFromFixture('Group', 'group1');
$form = $this->objFromFixture('UserDefinedForm', 'form-with-settings');
$folder = $this->objFromFixture('Folder', 'folder1');
$group1 = $this->objFromFixture(Group::class, 'group1');
$form = $this->objFromFixture(UserDefinedForm::class, 'form-with-settings');
$folder = $this->objFromFixture(Folder::class, 'folder1');
$this->assertDOSEquals(array(
array(
'ClassName' => 'EditableTextField',
'ClassName' => EditableTextField::class,
'Title' => 'Text with rule',
'MinLength' => 20,
'MaxLength' => 100,
@ -166,7 +187,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest
'Default' => 'Enter your text here',
),
array(
'ClassName' => 'EditableNumericField',
'ClassName' => EditableNumericField::class,
'Title' => 'Numeric 1',
'RightTitle' => 'Number of %',
'Default' => 1,
@ -175,14 +196,14 @@ class UserFormsUpgradeServiceTest extends SapphireTest
'ShowOnLoad' => true,
),
array(
'ClassName' => 'EditableMemberListField',
'ClassName' => EditableMemberListField::class,
'Title' => 'Members 1',
'RightTitle' => 'Select group',
'GroupID' => $group1->ID,
'ShowOnLoad' => false,
),
array(
'ClassName' => 'EditableLiteralField',
'ClassName' => EditableLiteralField::class,
'Title' => 'Literal 1',
'HideFromReports' => true,
'RightTitle' => 'Literal',
@ -190,7 +211,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest
'ShowOnLoad' => true,
),
array(
'ClassName' => 'EditableFormHeading',
'ClassName' => EditableFormHeading::class,
'Title' => 'Heading 1',
'RightTitle' => 'Right',
'Level' => 3,
@ -198,19 +219,19 @@ class UserFormsUpgradeServiceTest extends SapphireTest
'ShowOnLoad' => false,
),
array(
'ClassName' => 'EditableFileField',
'ClassName' => EditableFileField::class,
'Title' => 'File 1',
'RightTitle' => 'File field',
'FolderID' => $folder->ID,
),
array(
'ClassName' => 'EditableDateField',
'ClassName' => EditableDateField::class,
'Title' => 'Date 1',
'RightTitle' => 'Date field',
'DefaultToToday' => true,
),
array(
'ClassName' => 'EditableCheckbox',
'ClassName' => EditableCheckbox::class,
'Title' => 'Checkbox 1',
'CheckedDefault' => true,
'RightTitle' => 'Check this',

View File

@ -1,5 +1,18 @@
<?php
namespace SilverStripe\UserForms\Test\Task;
use SilverStripe\Versioned\Versioned;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\Model\EditableFormField\EditableOption;
use SilverStripe\UserForms\Model\EditableFormField\EditableCheckboxGroupField;
use SilverStripe\Dev\SapphireTest;
class UserFormsVersionedTaskTest extends SapphireTest
{
@ -14,20 +27,20 @@ class UserFormsVersionedTaskTest extends SapphireTest
public function testPublishing()
{
/** @var UserDefinedForm $form */
$form = $this->objFromFixture('UserDefinedForm', 'filtered-form-page');
$form = $this->objFromFixture(UserDefinedForm::class, 'filtered-form-page');
// Get id of options
$optionID = $this->idFromFixture('EditableOption', 'option-3');
$this->assertEmpty(Versioned::get_one_by_stage('EditableOption', 'Live', array('"ID" = ?' => $optionID)));
$optionID = $this->idFromFixture(EditableOption::class, 'option-3');
$this->assertEmpty(Versioned::get_one_by_stage(EditableOption::class, 'Live', array('"ID" = ?' => $optionID)));
// Publishing writes this to live
$form->doPublish();
$liveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $optionID, false);
$liveVersion = Versioned::get_versionnumber_by_stage(EditableOption::class, 'Live', $optionID, false);
$this->assertNotEmpty($liveVersion);
// Add new option, and repeat publish process
/** @var EditableCheckboxGroupField $list */
$list = $this->objFromFixture('EditableCheckboxGroupField', 'checkbox-group');
$list = $this->objFromFixture(EditableCheckboxGroupField::class, 'checkbox-group');
$newOption = new EditableOption();
$newOption->Title = 'New option';
$newOption->Value = 'ok';
@ -38,12 +51,12 @@ class UserFormsVersionedTaskTest extends SapphireTest
$form->doPublish();
// Un-modified option should not create a new version
$newLiveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $optionID, false);
$newLiveVersion = Versioned::get_versionnumber_by_stage(EditableOption::class, 'Live', $optionID, false);
$this->assertNotEmpty($newLiveVersion);
$this->assertEquals($liveVersion, $newLiveVersion);
// New option is successfully published
$newOptionLiveVersion = Versioned::get_versionnumber_by_stage('EditableOption', 'Live', $newOptionID, false);
$newOptionLiveVersion = Versioned::get_versionnumber_by_stage(EditableOption::class, 'Live', $newOptionID, false);
$this->assertNotEmpty($newOptionLiveVersion);
}
}