public function WktGeneratorTest::testPolygon in Geofield 8
Tests the generation of WKT polygons and multipolygons.
File
- tests/
src/ Kernel/ WktGeneratorTest.php, line 122
Class
- WktGeneratorTest
- Tests WktGenerator.
Namespace
Drupal\Tests\geofield\KernelCode
public function testPolygon() {
$polygon = $this->wktGenerator
->wktGeneratePolygon();
$match = preg_match($this->polygonRegex, $polygon);
$this
->assertNotEmpty($match, 'Polygon generated properly');
$polygon = $this->wktGenerator
->wktGeneratePolygon([
7.34,
-45.66,
]);
$match = preg_match('/^POLYGON \\(\\(7.34 -45.66, ([-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\, )*7.34 -45.66\\)\\)$/', $polygon);
$this
->assertNotEmpty($match, 'Polygon generated properly');
$polygon = $this->wktGenerator
->wktGeneratePolygon(NULL, 9);
$match = preg_match('/^POLYGON \\(\\(([-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\, ){9}[-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\)\\)$/', $polygon);
$this
->assertNotEmpty($match, 'Polygon generated properly');
$polygon = $this->wktGenerator
->wktGeneratePolygon([
7,
45,
], 6);
$match = preg_match('/^POLYGON \\(\\(7 45, ([-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\, ){5}7 45\\)\\)$/', $polygon);
$this
->assertNotEmpty($match, 'Polygon generated properly');
$multipolygon = $this->wktGenerator
->wktGenerateMultipolygon();
$match = preg_match($this->multipolygonRegex, $multipolygon);
$this
->assertNotEmpty($match, 'Multipolygon generated properly');
}