Fix FormSchemaTest.php linting issues

This commit is contained in:
Damian Mooyman 2017-05-04 12:52:40 +12:00
parent 8b9f41d4f4
commit 1f8de20ce7
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
4 changed files with 354 additions and 372 deletions

View File

@ -7,7 +7,6 @@ use SilverStripe\Forms\DateField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\Schema\FormSchema;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\TextField;
@ -22,47 +21,11 @@ class FormSchemaTest extends SapphireTest
{
$form = new Form(null, 'TestForm', new FieldList(), new FieldList());
$formSchema = new FormSchema();
$expected = [
'name' => 'TestForm',
'id' => 'Form_TestForm',
'action' => null,
'method' => 'POST',
'attributes' => [
'id' => 'Form_TestForm',
'action' => null,
'method' => 'POST',
'enctype' => 'application/x-www-form-urlencoded',
'target' => null,
'class' => ''
],
'data' => [],
'fields' => [
[
'id' => 'Form_TestForm_SecurityID',
'name' => 'SecurityID',
'type' => "Hidden",
'component' => null,
'holderId' => 'Form_TestForm_SecurityID_Holder',
'title' => 'Security ID',
'source' => null,
'extraClass' => 'hidden',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'attributes' => [],
'data' => [],
'validation' => [],
],
],
'actions' => []
];
$expected = json_decode(file_get_contents(__DIR__.'/FormSchemaTest/testGetSchema.json'), true);
$schema = $formSchema->getSchema($form);
$this->assertInternalType('array', $schema);
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($schema));
$this->assertEquals($expected, $schema);
}
public function testGetState()
@ -85,7 +48,7 @@ class FormSchemaTest extends SapphireTest
$state = $formSchema->getState($form);
$this->assertInternalType('array', $state);
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($state));
$this->assertEquals($expected, $state);
}
public function testGetStateWithFormMessages()
@ -183,192 +146,11 @@ class FormSchemaTest extends SapphireTest
)
);
$formSchema = new FormSchema();
$expected = [
'name' => 'TestForm',
'id' => 'Form_TestForm',
'action' => null,
'method' => 'POST',
'attributes' => [
'id' => 'Form_TestForm',
'action' => null,
'method' => 'POST',
'enctype' => 'application/x-www-form-urlencoded',
'target' => null,
'class' => ''
],
'data' => [],
'fields' => [
[
'id' => 'Form_TestForm_Name',
'name' => 'Name',
'type' => 'Text',
'component' => null,
'holderId' => 'Form_TestForm_Name_Holder',
'title' => 'Name',
'source' => null,
'extraClass' => 'text',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'attributes' => [],
'data' => [],
'validation' => [],
],
[
'id' => 'Form_TestForm_SecurityID',
'name' => 'SecurityID',
'type' => "Hidden",
'component' => null,
'holderId' => 'Form_TestForm_SecurityID_Holder',
'title' => 'Security ID',
'source' => null,
'extraClass' => 'hidden',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'attributes' => [],
'data' => [],
'validation' => [],
],
],
'actions' => [
[
'id' => 'Form_TestForm_action_save',
'title' => 'Save',
'name' => 'action_save',
'type' => null,
'component' => 'FormAction',
'holderId' => 'Form_TestForm_action_save_Holder',
'source' => null,
'extraClass' => 'action',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'attributes' => [
'type' => 'submit',
],
'data' => [
'icon' => 'save',
],
'validation' => [],
],
[
'id' => 'Form_TestForm_action_cancel',
'title' => 'Cancel',
'name' => 'action_cancel',
'type' => null,
'component' => 'FormAction',
'holderId' => 'Form_TestForm_action_cancel_Holder',
'source' => null,
'extraClass' => 'action',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'attributes' => [
'type' => 'button'
],
'data' => [
'icon' => null
],
'validation' => [],
],
[
'id' => 'Form_TestForm_Moreoptions',
'title' => 'More options',
'name' => 'Moreoptions',
'type' => 'Structural',
'component' => 'PopoverField',
'holderId' => 'Form_TestForm_Moreoptions_Holder',
'source' => null,
'extraClass' => 'field CompositeField popover',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => null,
'disabled' => false,
'customValidationMessage' => '',
'attributes' => [],
'data' => [
'popoverTitle' => null,
'placement' => 'bottom',
'tag' => 'div',
'legend' => null,
'buttonTooltip' => null,
'inherited' => [
'data' => [
'fieldholder' => 'small'
],
],
],
'validation' => [],
'children' => [
[
'id' => 'Form_TestForm_action_publish',
'title' => 'Publish record',
'name' => 'action_publish',
'type' => null,
'component' => 'FormAction',
'holderId' => 'Form_TestForm_action_publish_Holder',
'source' => null,
'extraClass' => 'action',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'attributes' => [
'type' => 'submit',
],
'data' => [
'icon' => null,
],
'validation' => [],
],
[
'id' => 'Form_TestForm_action_archive',
'title' => 'Archive',
'name' => 'action_archive',
'type' => null,
'component' => 'FormAction',
'holderId' => 'Form_TestForm_action_archive_Holder',
'source' => null,
'extraClass' => 'action',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'attributes' => [
'type' => 'submit',
],
'data' => [
'icon' => null,
],
'validation' => [],
],
]
]
]
];
$expected = json_decode(file_get_contents(__DIR__.'/FormSchemaTest/testGetNestedSchema.json'), true);
$schema = $formSchema->getSchema($form);
$this->assertInternalType('array', $schema);
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($schema));
$this->assertEquals($expected, $schema);
}
/**
@ -406,155 +188,8 @@ class FormSchemaTest extends SapphireTest
);
$formSchema = new FormSchema();
$schema = $formSchema->getSchema($form);
$expected = [
'name' => 'TestForm',
'id' => 'Form_TestForm',
'action' => null,
'method' => 'POST',
'attributes' =>
[
'id' => 'Form_TestForm',
'action' => null,
'method' => 'POST',
'enctype' => 'application/x-www-form-urlencoded',
'target' => null,
'class' => '',
],
'data' =>
[],
'fields' =>
[
[
'name' => 'Name',
'id' => 'Form_TestForm_Name',
'type' => 'Text',
'component' => null,
'holderId' => 'Form_TestForm_Name_Holder',
'title' => 'Name',
'source' => null,
'extraClass' => 'text',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'validation' =>
[
'required' => true,
'max' => [
'length' => 40,
],
],
'attributes' =>
[],
'data' =>
[],
],
[
'name' => 'Date',
'id' => 'Form_TestForm_Date',
'type' => 'Date',
'component' => null,
'holderId' => 'Form_TestForm_Date_Holder',
'title' => 'Date',
'source' => null,
'extraClass' => 'date text',
'description' => null,
'rightTitle' => null,
'lang' => 'en-US',
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'validation' =>
[
'date' => true,
],
'attributes' =>
[],
'data' => [
'html5' => true,
'min' => null,
'max' => null
],
],
[
'name' => 'Number',
'id' => 'Form_TestForm_Number',
'type' => 'Decimal',
'component' => null,
'holderId' => 'Form_TestForm_Number_Holder',
'title' => 'Number',
'source' => null,
'extraClass' => 'numeric text',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'validation' =>
[
'numeric' => true,
],
'attributes' =>
[],
'data' =>
[],
],
[
'name' => 'Money',
'id' => 'Form_TestForm_Money',
'type' => 'Text',
'component' => null,
'holderId' => 'Form_TestForm_Money_Holder',
'title' => 'Money',
'source' => null,
'extraClass' => 'currency text',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'validation' =>
[
'currency' => true,
],
'attributes' =>
[],
'data' =>
[],
],
[
'name' => 'SecurityID',
'id' => 'Form_TestForm_SecurityID',
'type' => 'Hidden',
'component' => null,
'holderId' => 'Form_TestForm_SecurityID_Holder',
'title' => 'Security ID',
'source' => null,
'extraClass' => 'hidden',
'description' => null,
'rightTitle' => null,
'leftTitle' => null,
'readOnly' => false,
'disabled' => false,
'customValidationMessage' => '',
'validation' =>
[],
'attributes' =>
[],
'data' =>
[],
],
],
'actions' =>
[],
];
$expected = json_decode(file_get_contents(__DIR__.'/FormSchemaTest/testSchemaValidation.json'), true);
$this->assertInternalType('array', $schema);
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($schema));
$this->assertEquals($expected, $schema);
}
}

View File

@ -0,0 +1,181 @@
{
"name": "TestForm",
"id": "Form_TestForm",
"action": null,
"method": "POST",
"attributes": {
"id": "Form_TestForm",
"action": null,
"method": "POST",
"enctype": "application\/x-www-form-urlencoded",
"target": null,
"class": ""
},
"data": [],
"fields": [
{
"id": "Form_TestForm_Name",
"name": "Name",
"type": "Text",
"component": null,
"holderId": "Form_TestForm_Name_Holder",
"title": "Name",
"source": null,
"extraClass": "text",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"attributes": [],
"data": [],
"validation": []
},
{
"id": "Form_TestForm_SecurityID",
"name": "SecurityID",
"type": "Hidden",
"component": null,
"holderId": "Form_TestForm_SecurityID_Holder",
"title": "Security ID",
"source": null,
"extraClass": "hidden",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"attributes": [],
"data": [],
"validation": []
}
],
"actions": [
{
"id": "Form_TestForm_action_save",
"title": "Save",
"name": "action_save",
"type": null,
"component": "FormAction",
"holderId": "Form_TestForm_action_save_Holder",
"source": null,
"extraClass": "action",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"attributes": {
"type": "submit"
},
"data": {
"icon": "save"
},
"validation": []
},
{
"id": "Form_TestForm_action_cancel",
"title": "Cancel",
"name": "action_cancel",
"type": null,
"component": "FormAction",
"holderId": "Form_TestForm_action_cancel_Holder",
"source": null,
"extraClass": "action",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"attributes": {
"type": "button"
},
"data": {
"icon": null
},
"validation": []
},
{
"id": "Form_TestForm_Moreoptions",
"title": "More options",
"name": "Moreoptions",
"type": "Structural",
"component": "PopoverField",
"holderId": "Form_TestForm_Moreoptions_Holder",
"source": null,
"extraClass": "field CompositeField popover",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": null,
"disabled": false,
"customValidationMessage": "",
"attributes": [],
"data": {
"popoverTitle": null,
"placement": "bottom",
"tag": "div",
"legend": null,
"buttonTooltip": null,
"inherited": {
"data": {
"fieldholder": "small"
}
}
},
"validation": [],
"children": [
{
"id": "Form_TestForm_action_publish",
"title": "Publish record",
"name": "action_publish",
"type": null,
"component": "FormAction",
"holderId": "Form_TestForm_action_publish_Holder",
"source": null,
"extraClass": "action",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"attributes": {
"type": "submit"
},
"data": {
"icon": null
},
"validation": []
},
{
"id": "Form_TestForm_action_archive",
"title": "Archive",
"name": "action_archive",
"type": null,
"component": "FormAction",
"holderId": "Form_TestForm_action_archive_Holder",
"source": null,
"extraClass": "action",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"attributes": {
"type": "submit"
},
"data": {
"icon": null
},
"validation": []
}
]
}
]
}

View File

@ -0,0 +1,37 @@
{
"name": "TestForm",
"id": "Form_TestForm",
"action": null,
"method": "POST",
"attributes": {
"id": "Form_TestForm",
"action": null,
"method": "POST",
"enctype": "application\/x-www-form-urlencoded",
"target": null,
"class": ""
},
"data": [],
"fields": [
{
"id": "Form_TestForm_SecurityID",
"name": "SecurityID",
"type": "Hidden",
"component": null,
"holderId": "Form_TestForm_SecurityID_Holder",
"title": "Security ID",
"source": null,
"extraClass": "hidden",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"attributes": [],
"data": [],
"validation": []
}
],
"actions": []
}

View File

@ -0,0 +1,129 @@
{
"name": "TestForm",
"id": "Form_TestForm",
"action": null,
"method": "POST",
"attributes": {
"id": "Form_TestForm",
"action": null,
"method": "POST",
"enctype": "application\/x-www-form-urlencoded",
"target": null,
"class": ""
},
"data": [],
"fields": [
{
"name": "Name",
"id": "Form_TestForm_Name",
"type": "Text",
"component": null,
"holderId": "Form_TestForm_Name_Holder",
"title": "Name",
"source": null,
"extraClass": "text",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"validation": {
"required": true,
"max": {
"length": 40
}
},
"attributes": [],
"data": []
},
{
"name": "Date",
"id": "Form_TestForm_Date",
"type": "Date",
"component": null,
"holderId": "Form_TestForm_Date_Holder",
"title": "Date",
"source": null,
"extraClass": "date text",
"description": null,
"rightTitle": null,
"lang": "en-US",
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"validation": {
"date": true
},
"attributes": [],
"data": {
"html5": true,
"min": null,
"max": null
}
},
{
"name": "Number",
"id": "Form_TestForm_Number",
"type": "Decimal",
"component": null,
"holderId": "Form_TestForm_Number_Holder",
"title": "Number",
"source": null,
"extraClass": "numeric text",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"validation": {
"numeric": true
},
"attributes": [],
"data": []
},
{
"name": "Money",
"id": "Form_TestForm_Money",
"type": "Text",
"component": null,
"holderId": "Form_TestForm_Money_Holder",
"title": "Money",
"source": null,
"extraClass": "currency text",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"validation": {
"currency": true
},
"attributes": [],
"data": []
},
{
"name": "SecurityID",
"id": "Form_TestForm_SecurityID",
"type": "Hidden",
"component": null,
"holderId": "Form_TestForm_SecurityID_Holder",
"title": "Security ID",
"source": null,
"extraClass": "hidden",
"description": null,
"rightTitle": null,
"leftTitle": null,
"readOnly": false,
"disabled": false,
"customValidationMessage": "",
"validation": [],
"attributes": [],
"data": []
}
],
"actions": []
}