Commit d1ae4a05 authored by catch's avatar catch

Issue #2012682 by fago: Fixed Constraints in getPropertyDefinitions generate...

Issue #2012682 by fago: Fixed Constraints in getPropertyDefinitions generate violations without a delta.
parent ecfbc27f
......@@ -28,7 +28,7 @@ public function accept(ValidationVisitorInterface $visitor, $typed_data, $group,
$typed_data = NULL;
}
$visitor->visit($this, $typed_data, $group, $propertyPath);
$pathPrefix = empty($propertyPath) ? '' : $propertyPath . '.';
$pathPrefix = isset($propertyPath) && $propertyPath !== '' ? $propertyPath . '.' : '';
if ($typed_data) {
foreach ($typed_data as $name => $data) {
......
......@@ -7,6 +7,7 @@
namespace Drupal\system\Tests\TypedData;
use Drupal\Component\Utility\String;
use Drupal\simpletest\DrupalUnitTestBase;
use Drupal\Core\Datetime\DrupalDateTime;
use DateInterval;
......@@ -548,5 +549,19 @@ public function testTypedDataValidation() {
$this->assertEqual($violations->count(), 1);
$violations = $this->typedData->create($definition, 0)->validate();
$this->assertEqual($violations->count(), 0);
// Test validating a list of a values and make sure property paths starting
// with "0" are created.
$definition = array(
'type' => 'integer_field',
'list' => TRUE,
);
$violations = $this->typedData->create($definition, array(array('value' => 10)))->validate();
$this->assertEqual($violations->count(), 0);
$violations = $this->typedData->create($definition, array(array('value' => 'string')))->validate();
$this->assertEqual($violations->count(), 1);
$this->assertEqual($violations[0]->getInvalidValue(), 'string');
$this->assertIdentical($violations[0]->getPropertyPath(), '0.value');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment