// Test the Null constraint with typed data containers.
$definition = BaseFieldDefinition::
create('float'
) ->
setConstraints(['Null' =>
[]]);
$field_item =
$this->typedDataManager->
create($definition,
['value' => 11.5
]);
$violations =
$field_item->
validate();
$this->
assertEquals(1,
$violations->
count());
$field_item =
$this->typedDataManager->
create($definition);
$violations =
$field_item->
validate();
$this->
assertEquals(0,
$violations->
count());
// Test getting constraint definitions by type.
$definitions =
$this->typedDataManager->
getValidationConstraintManager()->
getDefinitionsByType('entity'
);
$this->
assertTrue(isset($definitions['EntityType'
]), 'Constraint plugin found for type entity.'
);
$this->
assertTrue(isset($definitions['Null'
]), 'Constraint plugin found for type entity.'
);
$this->
assertTrue(isset($definitions['NotNull'
]), 'Constraint plugin found for type entity.'
);
$definitions =
$this->typedDataManager->
getValidationConstraintManager()->
getDefinitionsByType('string'
);
$this->
assertFalse(isset($definitions['EntityType'
]), 'Constraint plugin not found for type string.'
);
$this->
assertTrue(isset($definitions['Null'
]), 'Constraint plugin found for type string.'
);
$this->
assertTrue(isset($definitions['NotNull'
]), 'Constraint plugin found for type string.'
);
// Test automatic 'required' validation.
$definition = DataDefinition::
create('integer'
)