Skip to content

Commit

Permalink
Fixed case when string length validator constraint value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Blazek committed Nov 28, 2016
1 parent 4c13c32 commit d341771
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Form/FieldTypeHandler/TextLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ protected function buildFieldForm(
$minStringLength = $fieldDefinition->validatorConfiguration['StringLengthValidator']['minStringLength'];
$maxStringLength = $fieldDefinition->validatorConfiguration['StringLengthValidator']['maxStringLength'];

if ($minStringLength !== false) {
if (!empty($minStringLength)) {
$lengthConstraints['min'] = $minStringLength;
}

if ($maxStringLength !== false) {
if (!empty($maxStringLength)) {
$lengthConstraints['max'] = $maxStringLength;
}

Expand Down
32 changes: 32 additions & 0 deletions Tests/Form/FieldTypeHandler/TextLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,36 @@ public function testBuildFieldCreateForm()
$text = new TextLine();
$text->buildFieldCreateForm($formBuilder, $fieldDefinition, $languageCode);
}

public function testBuildFieldCreateFormWithStringLengthsNull()
{
$formBuilder = $this->getMockBuilder(FormBuilder::class)
->disableOriginalConstructor()
->setMethods(array('add'))
->getMock();

$formBuilder->expects($this->once())
->method('add');

$fieldDefinition = new FieldDefinition(
array(
'id' => 'id',
'identifier' => 'identifier',
'isRequired' => true,
'descriptions' => array('fre-FR' => 'fre-FR'),
'names' => array('fre-FR' => 'fre-FR'),
'validatorConfiguration' => array(
'StringLengthValidator' => array(
'minStringLength' => null,
'maxStringLength' => null,
),
),
)
);

$languageCode = 'eng-GB';

$text = new TextLine();
$text->buildFieldCreateForm($formBuilder, $fieldDefinition, $languageCode);
}
}

0 comments on commit d341771

Please sign in to comment.