You are here

public function WktGeneratorTest::testLinestring in Geofield 8

Tests the generation of WKT linestrings and multilinestrings.

File

tests/src/Kernel/WktGeneratorTest.php, line 97

Class

WktGeneratorTest
Tests WktGenerator.

Namespace

Drupal\Tests\geofield\Kernel

Code

public function testLinestring() {
  $linestring = $this->wktGenerator
    ->wktGenerateLinestring();
  $match = preg_match($this->linestringRegex, $linestring);
  $this
    ->assertNotEmpty($match, 'Linestring generated properly');
  $linestring = $this->wktGenerator
    ->wktGenerateLinestring([
    7.34,
    -45.66,
  ]);
  $match = preg_match('/^LINESTRING \\(7.34 -45.66, ([-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\, )*[-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\)$/', $linestring);
  $this
    ->assertNotEmpty($match, 'Linestring generated properly');
  $linestring = $this->wktGenerator
    ->wktGenerateLinestring(NULL, 9);
  $match = preg_match('/^LINESTRING \\(([-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\, ){8}[-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\)$/', $linestring);
  $this
    ->assertNotEmpty($match, 'Linestring generated properly');
  $linestring = $this->wktGenerator
    ->wktGenerateLinestring([
    7,
    45,
  ], 6);
  $match = preg_match('/^LINESTRING \\(7 45, ([-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\, ){4}[-]?[0-9]*\\.?[0-9]+ [-]?[0-9]*\\.?[0-9]+\\)$/', $linestring);
  $this
    ->assertNotEmpty($match, 'Linestring generated properly');
  $multilinestring = $this->wktGenerator
    ->wktGenerateMultilinestring();
  $match = preg_match($this->multilinestringRegex, $multilinestring);
  $this
    ->assertNotEmpty($match, 'Multilinestring generated properly');
}