You are here

public function GeofieldFormatterTest::testLatLonFormatter in Geofield 8

Tests geofield field LatLon formatter.

@dataProvider latLonFormatterProvider

File

tests/src/Kernel/GeofieldFormatterTest.php, line 88

Class

GeofieldFormatterTest
Tests the geofield formatters functionality.

Namespace

Drupal\Tests\geofield\Kernel

Code

public function testLatLonFormatter($point, $format, $expected_value) {

  // Create the entity to be referenced.
  $entity = EntityTest::create([
    'name' => $this
      ->randomMachineName(),
  ]);
  $entity->geofield = [
    'value' => $point,
  ];
  $entity
    ->save();

  // Verify the geofield field formatter's render array.
  $build = $entity
    ->get('geofield')
    ->view([
    'type' => 'geofield_latlon',
    'settings' => [
      'output_format' => $format,
    ],
  ]);
  \Drupal::service('renderer')
    ->renderRoot($build[0]);
  $this
    ->assertEquals($expected_value, trim($build[0]['#markup']));
}