Skip to content

Commit

Permalink
Fix EZP-25743: empty tagPreset error in fieldType validation
Browse files Browse the repository at this point in the history
- add test coverage for fieldType validation
  • Loading branch information
João Inácio authored and bdunogier committed May 17, 2016
1 parent 8785d62 commit 54dd496
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/FieldType/XmlText/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function validateFieldSettings($fieldSettings)
self::TAG_PRESET_DEFAULT,
self::TAG_PRESET_SIMPLE_FORMATTING,
);
if (!in_array($value, $definedTagPresets, true)) {
if (!empty($value) && !in_array($value, $definedTagPresets, true)) {
$validationErrors[] = new ValidationError(
"Setting '%setting%' is of unknown tag preset",
null,
Expand Down
92 changes: 92 additions & 0 deletions tests/lib/FieldType/XmlTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,56 @@ public function testSettingsSchema()
);
}

/**
* @covers \eZ\Publish\Core\FieldType\XmlText\Type::validateFieldSettings
* @dataProvider providerForTestValidateFieldSettingsValid
*/
public function testValidateFieldSettingsValid($settings)
{
$validationResult = $this->getFieldType()->validateFieldSettings($settings);

$this->assertInternalType(
'array',
$validationResult,
'The method validateFieldSettings() must return an array.'
);
$this->assertEquals(
array(),
$validationResult,
'validateFieldSettings() considered the input settings invalid, while they should be valid: '
);

}

/**
* @covers \eZ\Publish\Core\FieldType\XmlText\Type::validateFieldSettings
* @dataProvider providerForTestValidateFieldSettingsInvalid
*/
public function testValidateFieldSettingsInvalid($settings)
{
$validationResult = $this->getFieldType()->validateFieldSettings($settings);

$this->assertInternalType(
'array',
$validationResult,
'The method validateFieldSettings() must return an array.'
);

$this->assertNotEquals(
array(),
$validationResult,
'validateFieldSettings() considered the input settings valid, while they should be invalid.'
);

foreach ($validationResult as $actualResultElement) {
$this->assertInstanceOf(
'eZ\\Publish\\SPI\\FieldType\\ValidationError',
$actualResultElement,
'Validation result of incorrect type.'
);
}
}

/**
* @covers \eZ\Publish\Core\FieldType\XmlText\Type::acceptValue
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
Expand Down Expand Up @@ -150,6 +200,48 @@ public function testToPersistenceValue()
self::assertSame($xmlDoc->saveXML(), $fieldValue->data);
}

public static function providerForTestValidateFieldSettingsValid()
{
return array(
array(
array(
'numRows' => 10,
'tagPreset' => ''
)
),
array(
array(
'numRows' => 10,
'tagPreset' => 0,
)
),
);
}

public static function providerForTestValidateFieldSettingsInvalid()
{
return array(
array(
array(
'numRows' => '',
'tagPreset' => ''
),
),
array(
array(
'numRows' => 10,
'tagPreset' => 'a'
)
),
array(
array(
'numRows' => 'a',
'tagPreset' => 0
)
)
);
}

public static function providerForTestAcceptValueValidFormat()
{
return array(
Expand Down

0 comments on commit 54dd496

Please sign in to comment.