Merge branch 'pull/6905'

This commit is contained in:
Daniel Hensby 2017-05-12 12:13:51 +01:00
commit e741af9127
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 45 additions and 19 deletions

View File

@ -333,7 +333,22 @@ class FormField extends RequestHandler
}
}
if ($content || $tag != 'input') {
if ($content || !in_array($tag, [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'link',
'meta',
'param',
'source',
'track',
'wbr',
])) {
return sprintf(
'<%s%s>%s</%s>',
$tag,

View File

@ -13,15 +13,16 @@ use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use ReflectionClass;
use SilverStripe\ORM\FieldType\DBField;
class FormFieldTest extends SapphireTest
{
protected static $required_extensions = array(
FormField::class => array(
TestExtension::class
)
);
protected static $required_extensions = [
FormField::class => [
TestExtension::class,
],
];
public function testDefaultClasses()
{
@ -29,9 +30,9 @@ class FormFieldTest extends SapphireTest
FormField::config()->update(
'default_classes',
array(
'class1',
)
[
'class1',
]
);
$field = new FormField('MyField');
@ -40,10 +41,10 @@ class FormFieldTest extends SapphireTest
FormField::config()->update(
'default_classes',
array(
'class1',
'class2',
)
[
'class1',
'class2',
]
);
$field = new FormField('MyField');
@ -52,9 +53,9 @@ class FormFieldTest extends SapphireTest
FormField::config()->update(
'default_classes',
array(
'class3',
)
[
'class3',
]
);
$field = new FormField('MyField');
@ -67,9 +68,9 @@ class FormFieldTest extends SapphireTest
TextField::config()->update(
'default_classes',
array(
'textfield-class',
)
[
'textfield-class',
]
);
$field = new TextField('MyField');
@ -370,4 +371,14 @@ class FormFieldTest extends SapphireTest
$schema['message']['value']
);
}
public function testCreateVoidTag()
{
$tag = FormField::create_tag('meta', [
'name' => 'description',
'content' => 'test tag',
]);
$this->assertNotContains('</meta>', $tag);
$this->assertRegexp('#/>$#', $tag);
}
}