public function ConstraintsTest::testGeoConstraint in Geofield 8
Tests GeoType constraint.
@covers \Drupal\geofield\Plugin\Validation\Constraint\GeoConstraintValidator @covers \Drupal\geofield\Plugin\Validation\Constraint\GeoConstraint
@dataProvider geoProvider
File
- tests/
src/ Kernel/ ConstraintsTest.php, line 32
Class
- ConstraintsTest
- Tests geofield constraints.
Namespace
Drupal\Tests\geofield\KernelCode
public function testGeoConstraint($coordinates, $expected_violation_count) {
// Check message in constraint.
$constraint = new GeoConstraint();
$this
->assertEquals('"@value" is not a valid geospatial content.', $constraint->message, 'Correct constraint message found.');
$execution_context = $this
->getMockBuilder('\\Drupal\\Core\\TypedData\\Validation\\ExecutionContext')
->disableOriginalConstructor()
->getMock();
if ($expected_violation_count) {
$execution_context
->expects($this
->exactly($expected_violation_count))
->method('addViolation')
->with($constraint->message, [
'@value' => $coordinates,
]);
}
else {
$execution_context
->expects($this
->exactly($expected_violation_count))
->method('addViolation');
}
$geophp_wrapper = new GeoPHPWrapper();
$validator = new GeoConstraintValidator($geophp_wrapper);
$validator
->initialize($execution_context);
$validator
->validate($coordinates, $constraint);
}